Example #1
0
 public function actionCountRecord()
 {
     try {
         $request = Yii::app()->request;
         $data = count(Clinics::model()->findAll());
         ResponseHelper::JsonReturnSuccess($data, 'Success');
     } catch (Exception $ex) {
         var_dump($ex->getMessage());
     }
 }
Example #2
0
 public function searchByAddressAndKeywords($province, $district, $ward, $limit, $offset, $keywords)
 {
     $criteria = new CDbCriteria();
     if (!empty($province)) {
         $criteria->addCondition("province={$province}");
     }
     if (!empty($ward)) {
         $criteria->addCondition("ward={$ward}");
     }
     if (!empty($district)) {
         $criteria->addCondition("district={$district}");
     }
     if (!empty($keywords)) {
         $criteria->addSearchCondition('name', $keywords, TRUE, 'OR', 'LIKE');
         $criteria->addSearchCondition('address', $keywords, TRUE, 'OR', 'LIKE');
     }
     $criteria->limit = $limit;
     $criteria->offset = $offset;
     $criteria->order = 'clinic_id DESC';
     $data = Clinics::model()->findAll($criteria);
     $cnt = count($data);
     return array('cnt' => $cnt, 'data' => $data);
 }
Example #3
0
 public function actionGetTreePages()
 {
     $result = array();
     if (isset($_REQUEST['model']) && isset($_REQUEST['page'])) {
         $limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : 30;
         $model = $_REQUEST['model'];
         $id = $_REQUEST['id'];
         $bid = $_REQUEST['bid'];
         $p = isset($_REQUEST['page']) ? $_REQUEST['page'] - 1 : 0;
         $items = array();
         $isParent = false;
         $count = 0;
         $criteria = new CDbCriteria();
         switch ($model) {
             case 'news':
                 $criteria->addCondition("is_active = 1");
                 $criteria->limit = $limit;
                 $criteria->offset = $p * $limit;
                 $items = News::model()->findAll($criteria);
                 if (is_array($items) && count($items)) {
                     foreach ($items as $item) {
                         $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false;
                         $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked);
                     }
                 }
                 break;
             case 'articles_categories':
                 $criteria->addCondition("is_active = 1");
                 $criteria->limit = $limit;
                 $criteria->offset = $p * $limit;
                 $items = ArticlesCategories::model()->findAll($criteria);
                 if ($id == 0) {
                     $isParent = true;
                     $model = 'articles';
                 }
                 if (is_array($items) && count($items)) {
                     foreach ($items as $item) {
                         $criteria = new CDbCriteria();
                         $criteria->addCondition("category_id = :cid AND is_active = 1");
                         $criteria->params = array(":cid" => $item->id);
                         $count = Articles::model()->count($criteria);
                         $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false;
                         $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'count' => $count, 'page' => $p, 'pageSize' => 30, 'isParent' => $isParent, "checked" => $checked);
                     }
                 }
                 break;
             case 'articles':
                 $criteria->addCondition("category_id = :cid AND is_active = 1");
                 $criteria->limit = $limit;
                 $criteria->offset = $p * $limit;
                 $criteria->params = array(":cid" => $id);
                 $items = Articles::model()->findAll($criteria);
                 if (is_array($items) && count($items)) {
                     foreach ($items as $item) {
                         $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false;
                         $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked);
                     }
                 }
                 break;
             case 'clinics':
                 $criteria->addCondition("is_active = 1");
                 $criteria->limit = $limit;
                 $criteria->offset = $p * $limit;
                 $items = Clinics::model()->findAll($criteria);
                 if (is_array($items) && count($items)) {
                     foreach ($items as $item) {
                         $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false;
                         $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked);
                     }
                 }
                 break;
             case 'experts':
                 $criteria->addCondition("is_active = 1");
                 $criteria->limit = $limit;
                 $criteria->offset = $p * $limit;
                 $items = Experts::model()->findAll($criteria);
                 if (is_array($items) && count($items)) {
                     foreach ($items as $item) {
                         $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false;
                         $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked);
                     }
                 }
                 break;
             case 'book_categories':
                 $criteria->addCondition("is_active = 1");
                 $criteria->limit = $limit;
                 $criteria->offset = $p * $limit;
                 $items = BookCategories::model()->findAll($criteria);
                 if ($id == 0) {
                     $isParent = true;
                     $model = 'book';
                 }
                 if (is_array($items) && count($items)) {
                     foreach ($items as $item) {
                         $criteria = new CDbCriteria();
                         $criteria->addCondition("category_id = :cid AND is_active = 1");
                         $criteria->params = array(":cid" => $item->id);
                         $count = BookPages::model()->count($criteria);
                         $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false;
                         $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'count' => $count, 'page' => $p, 'pageSize' => 30, 'isParent' => $isParent, "checked" => $checked);
                     }
                 }
                 break;
             case 'book':
                 $criteria->addCondition("category_id = :cid AND is_active = 1");
                 $criteria->limit = $limit;
                 $criteria->offset = $p * $limit;
                 $criteria->params = array(":cid" => $id);
                 $items = BookPages::model()->findAll($criteria);
                 if (is_array($items) && count($items)) {
                     foreach ($items as $item) {
                         $checked = BannersPagesRelation::model()->findByAttributes(array("banner_id" => $bid, "object_id" => $item->id, "model" => $model)) ? true : false;
                         $result[] = array('name' => $item->name, 'model' => $model, 'id' => $item->id, 'oid' => $item->id, 'isParent' => $isParent, "checked" => $checked);
                     }
                 }
                 break;
         }
     }
     echo json_encode($result);
 }