public function index()
 {
     $perPage = 999999;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $where = [];
     $where[] = 1;
     $queryParam = [];
     if (!empty($_GET['geo_id'])) {
         $where[] = "geo_id = ?";
         $queryParam[] = $_GET['geo_id'];
     }
     $where = implode(" AND ", $where);
     $queryParam[] = $start;
     $queryParam[] = $perPage;
     $items = R::getAll('SELECT * FROM contactdealer WHERE ' . $where . ' LIMIT ?,?', $queryParam);
     //$items = R::find('contactdealer', 'LIMIT ?,?', [$start, $perPage]);
     $count = R::count('contactdealer', $where, array_slice($queryParam, 0, -2));
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     // $itemsExport = R::exportAll($items);
     $this->builds($items);
     header('Content-Type: application/json');
     echo json_encode(['items' => $items, 'page' => $page, 'maxPage' => $maxPage, 'total' => $count], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     exit;
 }
示例#2
0
 public function index()
 {
     $perPage = 999999;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $where = [];
     $where[] = 1;
     $queryParam = [];
     if (!empty($_GET['type'])) {
         $where[] = "type = ?";
         $queryParam[] = $_GET['type'];
     }
     if (!empty($_GET['porcelain_type'])) {
         $where[] = "porcelain_type = ?";
         $queryParam[] = $_GET['porcelain_type'];
     }
     if (!empty($_GET['size'])) {
         $where[] = "size = ?";
         $queryParam[] = $_GET['size'];
     }
     if (!empty($_GET['size_unit'])) {
         $where[] = "size_unit = ?";
         $queryParam[] = $_GET['size_unit'];
     }
     if (!empty($_GET['style'])) {
         $where[] = "style = ?";
         $queryParam[] = $_GET['style'];
     }
     if (!empty($_GET['company'])) {
         $where[] = "company = ?";
         $queryParam[] = $_GET['company'];
     }
     if (!empty($_GET['is_group'])) {
         $where[] = "company = ?";
         $queryParam[] = $_GET['company'];
     }
     if (!empty($_GET['pattern_id'])) {
         $pattern = R::findOne("room_pattern", "id=?", [$_GET['pattern_id']]);
         if (isset($pattern["product_use"])) {
             $ids = trim($pattern["product_use"], ",");
             $ids = explode(",", $ids);
         } else {
             $ids = [0];
         }
         $where[] = "id IN (" . R::genSlots($ids) . ")";
         $queryParam = array_merge($queryParam, $ids);
     }
     $where = implode(" AND ", $where);
     $queryParam[] = $start;
     $queryParam[] = $perPage;
     $items = R::getAll('SELECT product.* FROM product WHERE ' . $where . ' ORDER BY is_hot DESC, is_new DESC, created_at DESC LIMIT ?,?', $queryParam);
     $count = R::count('product', $where, array_slice($queryParam, 0, -2));
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     // $itemsExport = R::exportAll($items);
     $this->builds($items);
     header('Content-Type: application/json');
     echo json_encode(['items' => $items, 'page' => $page, 'maxPage' => $maxPage, 'total' => $count], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     exit;
 }
示例#3
0
 public function index()
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $items = R::find('user', 'level=2 LIMIT ?,?', [$start, $perPage]);
     $count = R::count('user');
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $this->slim->render("user/list.php", ['items' => $items, 'page' => $page, 'maxPage' => $maxPage]);
 }
示例#4
0
 public function index()
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $items = R::find('account', 'email IS NOT NULL LIMIT ?,?', [$start, $perPage]);
     $count = R::count('account', 'email IS NOT NULL');
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $itemsExport = R::exportAll($items);
     $this->builds($itemsExport);
     $this->slim->render("user/list.php", ['items' => $itemsExport, 'page' => $page, 'maxPage' => $maxPage]);
 }
示例#5
0
 public function index()
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $items = R::find('news', ' ORDER BY sort_order LIMIT ?,?', [$start, $perPage]);
     $itemsAll = R::find('news', 'ORDER BY sort_order');
     $itemsAll = R::exportAll($items);
     $count = R::count('news');
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $this->slim->render("news/list.php", ['items' => $items, 'itemsAll' => $itemsAll, 'page' => $page, 'maxPage' => $maxPage]);
 }
示例#6
0
 public function index($roomId)
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $room = R::findOne('room', 'id = ?', [$roomId]);
     $items = R::find('room_pattern', 'room_id = ? LIMIT ?,?', [$roomId, $start, $perPage]);
     $count = R::count('room_pattern', 'room_id = ?', [$roomId]);
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $itemsExport = R::exportAll($items);
     $this->builds($itemsExport);
     $this->slim->render("room/pattern/list.php", ['room' => $room, 'items' => $itemsExport, 'page' => $page, 'maxPage' => $maxPage]);
 }
示例#7
0
 public function validate()
 {
     $this->errors = [];
     $this->error = false;
     $this->isValid = true;
     if (empty($this->attr['name'])) {
         $this->pushError("name empty");
     }
     $id = @$this->attr["id"] ? $this->attr["id"] : 0;
     if (R::count("room", "name = ? AND id != ?", [$this->attr["name"], $id]) > 0) {
         $this->pushError("Duplicate name " . $this->attr["name"]);
     }
     return !$this->error;
 }
示例#8
0
 public function index()
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $items = R::find('room', 'LIMIT ?,?', [$start, $perPage]);
     $count = R::count('room');
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $itemsExport = R::exportAll($items);
     $this->builds($itemsExport);
     header('Content-Type: application/json');
     echo json_encode(['items' => $itemsExport, 'page' => $page, 'maxPage' => $maxPage, 'total' => $count], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     exit;
 }
示例#9
0
 public function index()
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $items = R::find('contactdealer', 'LIMIT ?,?', [$start, $perPage]);
     $count = R::count('contactdealer');
     foreach ($items as &$item) {
         $item->ownProvince = R::getRow('SELECT * FROM provinces WHERE province_id=?', [$item->province_id]);
         $item->ownGeography = R::getRow('SELECT * FROM geography WHERE geo_id=?', [$item->geo_id]);
         // var_dump($item); exit();
     }
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $this->slim->render("contactdealer/list.php", ['items' => $items, 'page' => $page, 'maxPage' => $maxPage]);
 }
示例#10
0
文件: Auth.php 项目: kiswa/SMPLog
 public static function CreateInitialAdmin($container)
 {
     if (!R::count('user')) {
         $admin = R::dispense('user');
         $admin->username = '******';
         $admin->is_admin = true;
         $admin->is_active = true;
         $admin->name = 'Anonymous';
         $admin->image = '';
         $admin->logins = 0;
         $admin->last_login = null;
         $admin->password_hash = password_hash('admin', PASSWORD_BCRYPT);
         $admin->active_token = null;
         R::store($admin);
     }
 }
示例#11
0
 public function index()
 {
     $perPage = 999999;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $where = [];
     $whereParam = [];
     if (!empty($_GET['room_id'])) {
         $where[] = "room_id = ?";
         $whereParam[] = $_GET['room_id'];
     }
     $whereString = implode("AND", $where);
     $items = R::find('room_pattern', $whereString . ' LIMIT ?,?', array_merge($whereParam, [$start, $perPage]));
     $count = R::count('room_pattern', $whereString, $whereParam);
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $itemsExport = R::exportAll($items);
     $this->builds($itemsExport);
     header('Content-Type: application/json');
     echo json_encode(['items' => $itemsExport, 'page' => $page, 'maxPage' => $maxPage, 'total' => $count], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     exit;
 }
示例#12
0
 /**
  * @RequestMapping(url="account/comic/{comic_id}/{vol}",type="template",auth=true)
  * @RequestParams(true)
  * @Role(USER)
  * @Role(ADMIN)
  */
 function comicDetails($model, $comic_id = null, $action = null, $title = null, $vol = 1)
 {
     Service::DBSetup();
     $comic = R::load("comic", $comic_id);
     if ($action == "add_chapter" && $title !== null) {
         $chapter = R::dispense("chapter");
         $chapter->title = $title;
         $chapter->uid = $this->user->uid;
         $chapter->vol = $vol;
         $chapter->comic = $comic;
         $chapter->inorder = R::count("chapter", "comic_id = :comic_id AND vol = :vol", array("comic_id" => $comic_id, "vol" => $vol));
         $chapter->time = microtime(true);
         R::store($chapter);
     }
     $chapters = R::find("chapter", "comic_id = :comic_id AND vol = :vol", array("comic_id" => $comic_id, "vol" => $vol));
     //print_r($comic);
     $model->assign("comic", $comic);
     $model->assign("chapters", $chapters);
     $model->assign("user", $this->user);
     return "member/comic";
 }
示例#13
0
 public static function checkOut($number, Publisher $publisher)
 {
     if (R::count('record', ' number = :number AND isnull(`in`) ', ['number' => $number]) > 0) {
         return null;
     }
     $territoryBean = R::findOne('territory', ' number = :number ', ['number' => $number]);
     if ($territoryBean === null) {
         return null;
     }
     $bean = R::dispense('record');
     $bean->number = $number;
     $bean->out = time();
     $bean->in = null;
     $bean->checkOutBy = App::user()->id;
     $record = new Record($number, $bean);
     $territoryBean->sharedRecordList[] = $bean;
     $publisherBean = $publisher->bean();
     $publisherBean->ownRecordList[] = $bean;
     R::storeAll([$bean, $territoryBean, $publisherBean]);
     $publisher->records[] = $record;
     return $record;
 }
示例#14
0
 public function search()
 {
     $page = $this->getAttr("page");
     $perPage = $this->getAttr("perPage");
     $start = ($page - 1) * $perPage;
     $query = "";
     $bindParam = [];
     $keyword = $this->getAttr("keyword");
     $keyword = trim($keyword);
     if (!empty($keyword)) {
         $query .= "first_name LIKE :keyword OR last_name LIKE :keyword";
         $bindParam["keyword"] = '%' . $keyword . '%';
     }
     $this->count = R::count('employee', $query, $bindParam);
     $page = floor($this->count / $perPage);
     $this->maxPage = $page + ($this->count % $perPage == 0 ? 0 : 1);
     $query .= " LIMIT :start,:perPage";
     $bindParam["start"] = $start;
     $bindParam["perPage"] = $perPage;
     $this->items = R::find('employee', $query, $bindParam);
     $this->injectsUser($this->items);
 }
示例#15
0
 public function index()
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $where = [];
     $where[] = 1;
     $queryParam = [];
     if (!empty($_GET['type'])) {
         $where[] = "type = ?";
         $queryParam[] = $_GET['type'];
     }
     if (!empty($_GET['size'])) {
         $where[] = "size = ?";
         $queryParam[] = $_GET['size'];
     }
     if (!empty($_GET['style'])) {
         $where[] = "style = ?";
         $queryParam[] = $_GET['style'];
     }
     if (!empty($_GET['company'])) {
         $where[] = "company = ?";
         $queryParam[] = $_GET['company'];
     }
     $where = implode(" AND ", $where);
     $queryParam[] = $start;
     $queryParam[] = $perPage;
     $items = R::getAll('SELECT * FROM product WHERE ' . $where . ' ORDER BY is_hot DESC, is_new DESC, created_at DESC LIMIT ?,?', $queryParam);
     $count = R::count('product', $where, array_slice($queryParam, 0, -2));
     $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
     $form = [];
     $form["type"] = @$_GET["type"] ?: "";
     $form["size"] = @$_GET["size"] ?: "";
     $form["style"] = @$_GET["style"] ?: "";
     $form["company"] = @$_GET["company"] ?: "";
     $this->slim->render("product/list.php", ['items' => $items, 'page' => $page, 'maxPage' => $maxPage, 'form' => $form]);
 }
示例#16
0
文件: Base.php 项目: skema/skema
 public static function exists($name)
 {
     return R::count('skemafield', ' name = ? ', [$name]) > 0;
 }
示例#17
0
文件: Perm.php 项目: Koohiisan/Enpowi
 public static function isUnique($module, $component, $groupName)
 {
     $result = R::count('perm', ' groupName = ? AND module = ? AND component = ?', [$groupName, $module, $component]);
     return $result === 0;
 }
示例#18
0
 public static function count()
 {
     return R::count('territory');
 }
示例#19
0
 public function search()
 {
     $page = $this->getAttr("page");
     $perPage = $this->getAttr("perPage");
     $start = ($page - 1) * $perPage;
     $query = "";
     $bindParam = [];
     if (!empty($this->attr['passport_expiry_start']) || !empty($this->attr['passport_expiry_end'])) {
         $queryPassportExpire = "";
         if (!empty($this->attr['passport_expiry_start'])) {
             $queryPassportExpire .= "passport_expiry >= :passport_expiry_start";
             $bindParam['passport_expiry_start'] = $this->attr['passport_expiry_start'];
         }
         if (!empty($this->attr['passport_expiry_end'])) {
             if (!empty($queryPassportExpire)) {
                 $queryPassportExpire .= " AND ";
             }
             $queryPassportExpire .= "passport_expiry <= :passport_expiry_end";
             $bindParam['passport_expiry_end'] = $this->attr['passport_expiry_end'];
         }
         if (!empty($query)) {
             $query .= " OR ";
         }
         $query .= "({$queryPassportExpire})";
     }
     if (!empty($this->attr['visa_expiry_start']) || !empty($this->attr['visa_expiry_end'])) {
         $queryVisaExpire = "";
         if (!empty($this->attr['visa_expiry_start'])) {
             $queryVisaExpire .= "visa_expiry >= :visa_expiry_start";
             $bindParam['visa_expiry_start'] = $this->attr['visa_expiry_start'];
         }
         if (!empty($this->attr['visa_expiry_end'])) {
             if (!empty($queryVisaExpire)) {
                 $queryVisaExpire .= " AND ";
             }
             $queryVisaExpire .= "visa_expiry <= :visa_expiry_end";
             $bindParam['visa_expiry_end'] = $this->attr['visa_expiry_end'];
         }
         if (!empty($query)) {
             $query .= " OR ";
         }
         $query .= "({$queryVisaExpire})";
     }
     if (!empty($this->attr['report_expiry_start']) || !empty($this->attr['report_expiry_end'])) {
         $queryReportExpire = "";
         if (!empty($this->attr['report_expiry_start'])) {
             $queryReportExpire .= "report_expiry >= :report_expiry_start";
             $bindParam['report_expiry_start'] = $this->attr['report_expiry_start'];
         }
         if (!empty($this->attr['report_expiry_end'])) {
             if (!empty($queryReportExpire)) {
                 $queryReportExpire .= " AND ";
             }
             $queryReportExpire .= "report_expiry <= :report_expiry_end";
             $bindParam['report_expiry_end'] = $this->attr['report_expiry_end'];
         }
         if (!empty($query)) {
             $query .= " OR ";
         }
         $query .= "({$queryReportExpire})";
     }
     $this->count = R::count('employee', $query, $bindParam);
     $page = floor($this->count / $perPage);
     $this->maxPage = $page + ($this->count % $perPage == 0 ? 0 : 1);
     $query .= " LIMIT :start,:perPage";
     $bindParam["start"] = $start;
     $bindParam["perPage"] = $perPage;
     $this->items = R::find('employee', $query, $bindParam);
     // $this->injectsUser($this->items);
 }
示例#20
0
文件: AuthTest.php 项目: kiswa/SMPLog
 public function testCreateJwtKey()
 {
     $this->assertEquals(0, R::count('jwt'));
     Auth::CreateJwtKey();
     $this->assertEquals(1, R::count('jwt'));
 }
示例#21
0
文件: Post.php 项目: Koohiisan/Enpowi
    public static function pages($showAll = false)
    {
        $count = R::count('blog', '
			where
				true = :show_all
				or date(published_on) >= now()
			order by created', ['show_all' => $showAll]);
        $result = [];
        $max = $count / App::$pagingSize;
        $i = 0;
        for (; $i < $max; $i++) {
            $result[] = $i;
        }
        return $result;
    }
示例#22
0
    public function index()
    {
        $perPage = 10;
        $page = @$_GET['page'] ? $_GET['page'] : 1;
        $start = ($page - 1) * $perPage;
        $form = [];
        $where = [];
        $where[] = 1;
        $queryParam = [];
        if (!empty($_GET['type'])) {
            $where[] = "type = '{$_GET['type']}'";
            //	$where[] = "type = ?";
            //	$queryParam[] = $_GET['type'];
        }
        if (!empty($_GET['size'])) {
            $where[] = "size = '{$_GET['size']}'";
            // $where[] = "size = ?";
            // $queryParam[] = $_GET['size'];
        }
        if (!empty($_GET['style'])) {
            $where[] = "style = '{$_GET['style']}'";
            // $where[] = "style = ?";
            // $queryParam[] = $_GET['style'];
        }
        if (!empty($_GET['company'])) {
            $where[] = "company = '{$_GET['company']}'";
            // $where[] = "company = ?";
            // $queryParam[] = $_GET['company'];
        }
        $where = implode(" AND ", $where);
        $queryParam[] = $start;
        $queryParam[] = $perPage;
        $ids = "";
        $form["room"] = "";
        $form["type"] = @$_GET["type"] ?: "";
        $form["size"] = @$_GET["size"] ?: "";
        $form["style"] = @$_GET["style"] ?: "";
        $form["company"] = @$_GET["company"] ?: "";
        // if(!empty($_GET["room"])){
        //
        // 		$form["room"] = $_GET["room"];
        //
        // 		$ids = R::getCol('SELECT product_id FROM product_room WHERE room_name = :room_name',
        //     [':room_name' => $_GET["room"]]);
        //
        // 		if(!empty($ids)){
        // 		$ids = 	array_unique($ids);
        //
        // 		$where = [];
        // 		$where =  ' id IN ('.R::genSlots($ids).')';
        //
        // 		$queryParam = array_merge($ids,$queryParam);
        //
        // 	}
        //
        // }
        $sub = 'SELECT SUM(product_view.view_count) FROM product_view WHERE product_view.product_id = product.id';
        $sub2 = 'SELECT SUM(product_add.add_count) FROM product_add WHERE product_add.product_id = product.id';
        $sub3 = 'SELECT SUM(product_room.view_count) FROM product_room WHERE product_room.product_id = product.id';
        $form["month"] = '';
        $form["year"] = '';
        if (!empty($_GET["year"])) {
            $sub .= " AND YEAR(product_view.view_date) = " . (int) $_GET["year"];
            $sub2 .= " AND YEAR(product_add.add_date) = " . (int) $_GET["year"];
            $sub3 .= " AND YEAR(product_room.view_date) = " . (int) $_GET["year"];
            $form["year"] = $_GET["year"];
            if (!empty($_GET["month"])) {
                $sub .= " AND MONTH(product_view.view_date) = " . (int) $_GET["month"];
                $sub2 .= " AND MONTH(product_add.add_date) = " . (int) $_GET["month"];
                $sub3 .= " AND MONTH(product_room.view_date) = " . (int) $_GET["month"];
                $form["month"] = $_GET["month"];
            }
        }
        if (empty($_GET["order"])) {
            $form["order"] = 'total_view';
        } else {
            $form["order"] = $_GET["order"];
        }
        $sql = 'SELECT *, (' . $sub3 . ') as total_room, (' . $sub . ') as total_view, (' . $sub2 . ') as total_add
			FROM product WHERE ' . $where . '  ORDER BY ' . $form["order"] . ' DESC LIMIT ?,?';
        $items = R::getAll($sql, $queryParam);
        $count = R::count('product', $where, array_slice($queryParam, 0, -2));
        $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
        $items = array_map(function ($item) {
            if (is_null($item["total_view"])) {
                $item["total_view"] = 0;
            }
            if (is_null($item["total_add"])) {
                $item["total_add"] = 0;
            }
            if (is_null($item["total_room"])) {
                $item["total_room"] = 0;
            }
            return $item;
        }, $items);
        $this->slim->render("stat/list.php", ['items' => $items, 'page' => $page, 'maxPage' => $maxPage, 'form' => $form]);
    }
示例#23
0
文件: Gallery.php 项目: enpowi/enpowi
 public static function pages()
 {
     return R::count('gallery') / App::$pagingSize;
 }
示例#24
0
 public function testRemoveAuthorValid()
 {
     $jwt = DataMock::getJwt();
     $this->setAdminToken($jwt);
     $post = R::dispense('post');
     $post->is_published = true;
     $post->title = 'test';
     $user = R::dispense('user');
     $user->is_admin = false;
     $user->username = '******';
     $user->ownPostList[] = $post;
     R::store($user);
     $request = new RequestMock();
     $request->header = [$jwt];
     $args = [];
     $args['id'] = 2;
     // The new user above
     $response = $this->admin->removeAuthor($request, new ResponseMock(), $args);
     $this->assertEquals('success', $response->status);
     $this->assertEquals(2, R::count('user'));
 }
示例#25
0
文件: Post.php 项目: enpowi/enpowi
    /**
     * @param User $user
     * @param bool|false $showAll
     * @return float
     */
    public static function userPages(User $user, $showAll = false)
    {
        return R::count('blog', '
			where
				user_id = :user_id
				and (
					true = :show_all
					or date(published_on) >= now()
				)
			order by created', ['user_id' => $user->bean()->getID(), 'show_all' => $showAll]) / App::$pagingSize;
    }
示例#26
0
function createInitialUser()
{
    if (!R::count('user')) {
        $admin = R::dispense('user');
        $admin->username = '******';
        $admin->isAdmin = true;
        $admin->logins = 0;
        $admin->lastLogin = time();
        //date('Y-m-d H:i:s');
        $admin->defaultBoard = null;
        $admin->salt = password_hash($admin->username . time(), PASSWORD_BCRYPT);
        $admin->password = password_hash('admin', PASSWORD_BCRYPT, array('salt' => $admin->salt));
        $admin->email = '';
        $options = R::dispense('option');
        $options->tasksOrder = 0;
        $options->showAnimations = true;
        $options->showAssignee = true;
        $admin->ownOptions[] = $options;
        R::store($admin);
    }
}
示例#27
0
 public function count()
 {
     if (is_null($this->sql)) {
         return R::count($this->table);
     }
     $this->sql = 'SELECT COUNT(*) FROM ' . $this->table . ' ' . $this->alias . $this->sql;
     $result = R::getCell($this->sql, $this->params);
     $this->sql = null;
     return $result;
 }
示例#28
0
 public function stat()
 {
     $perPage = 10;
     $page = @$_GET['page'] ? $_GET['page'] : 1;
     $start = ($page - 1) * $perPage;
     $where = [];
     $where[] = 1;
     $where = implode(" AND ", $where);
     $queryParam[] = $start;
     $queryParam[] = $perPage;
     $form = [];
     $form['room'] = '';
     $sub = 'SELECT SUM(product_room.view_count) FROM product_room WHERE product_room.product_id = product.id';
     $items = [];
     $count = 0;
     $maxPage = 0;
     if (!empty($_GET["room"])) {
         $form["room"] = $_GET["room"];
         $ids = R::getCol('SELECT product_id FROM product_room WHERE room_name = :room_name', [':room_name' => $_GET["room"]]);
         if (!empty($ids)) {
             $ids = array_unique($ids);
             $room = $_GET["room"];
             $sub .= " AND product_room.room_name = '{$room}' ";
             $where = ' id IN (' . R::genSlots($ids) . ')';
             $queryParam = array_merge($ids, $queryParam);
             $sql = 'SELECT *,(' . $sub . ') as total_room FROM product WHERE ' . $where . ' LIMIT ?,?';
             $items = R::getAll($sql, $queryParam);
             $count = R::count('product', $where, array_slice($queryParam, 0, -2));
             $maxPage = floor($count / $perPage) + ($count % $perPage == 0 ? 0 : 1);
         } else {
         }
     }
     $items = array_map(function ($item) {
         if (is_null($item["total_room"])) {
             $item["total_room"] = 0;
         }
         return $item;
     }, $items);
     $this->slim->render("room/stat_view.php", ['items' => $items, 'page' => $page, 'maxPage' => $maxPage, 'form' => $form]);
 }