Exemplo n.º 1
0
 public static function getSortDataByField($field)
 {
     $fieldSelect = '';
     $sorts = PrakruangUtility::getSortData();
     foreach ($sorts as $index => $sort) {
         if ($sort['field'] == $field) {
             $fieldSelect = $sort['label'];
         }
     }
     return $fieldSelect;
 }
Exemplo n.º 2
0
 public function actionIndex()
 {
     $where_condition = ' obj_status = ' . $this->publicStatus . ' ';
     $pagin_page_size = $this->displayDefault;
     $pagin_page_current = empty($_GET['page']) ? '1' : $_GET['page'];
     $mem_id = empty($_GET['user']) ? '' : $_GET['user'];
     $title = 'พระเครื่องยอดนิยม';
     $typeId = empty($_GET['typeId']) ? '' : $_GET['typeId'];
     $criteria = new CDbCriteria();
     $criteria->select = 'o.*';
     $criteria->alias = 'o';
     $criteria->join = 'LEFT JOIN province p ON p.pro_id = o.pro_id';
     /* if (!empty($typeId)) {
        $where_condition .= 'AND type_id = ' . $typeId;
        $criteria->compare('o.type_id', $typeId);
        $title = SacredType::model()->findByPk($typeId)->type_name;
        } */
     $criteria->compare('obj_status', $this->publicStatus);
     if (!empty($mem_id)) {
         $where_condition .= 'AND mem_id = ' . $mem_id;
         $criteria->compare('o.mem_id', $mem_id, true);
     }
     if (!empty(Yii::app()->session['criteria'])) {
         $criterias = Yii::app()->session['criteria'];
         $criteriaType = $criterias['types'];
         $criteriaRegion = $criterias['region'];
         $criteriaForm = $criterias['form'];
         if (!empty($criteriaForm['price_begin']) && !empty($criteriaForm['price_end'])) {
             $criteria->addBetweenCondition('o.obj_price', $criteriaForm['price_begin'], $criteriaForm['price_end']);
             $where_condition .= ' AND (obj_price between ' . $criteriaForm['price_begin'] . ' AND ' . $criteriaForm['price_end'] . ') ';
         }
         if (!empty($criteriaForm['born_begin']) && !empty($criteriaForm['born_end'])) {
             $criteria->addBetweenCondition('o.obj_born', $criteriaForm['born_begin'], $criteriaForm['born_end']);
             $where_condition .= ' AND (obj_born between ' . $criteriaForm['born_begin'] . ' AND ' . $criteriaForm['born_end'] . ') ';
         }
         if (!empty($criteriaForm['freedom'])) {
             $criteria->compare('o.obj_name', $criteriaForm['freedom'], true);
             $where_condition .= " AND o.obj_name like '%" . $criteriaForm['freedom'] . "%' ";
         }
         if (count($criteriaType) > 0) {
             $arrayCriteria = array();
             foreach ($criteriaType as $key => $value) {
                 $arrayCriteria[] = $value;
             }
             $arrayString = implode(',', $arrayCriteria);
             $criteria->addInCondition('o.type_id', $arrayCriteria);
             $where_condition .= ' AND type_id in (' . $arrayString . ') ';
         }
         if (count($criteriaRegion) > 0) {
             $arrayCriteria = array();
             foreach ($criteriaRegion as $key => $value) {
                 $arrayCriteria[] = $value;
             }
             $arrayString = implode(',', $arrayCriteria);
             $criteria->addInCondition('o.pro_id', $arrayCriteria);
             $where_condition .= ' AND o.pro_id in (' . $arrayString . ') ';
         }
     }
     if (!empty($_GET['field']) && !empty($_GET['by'])) {
         $criteria->order = 'o.obj_' . trim($_GET['field']) . ' ' . trim($_GET['by']);
     } else {
         $criteria->order = 'o.obj_updatedate desc';
     }
     $criteria->limit = $pagin_page_size;
     $criteria->offset = ($pagin_page_current - 1) * $pagin_page_size;
     //var_dump($criteria);
     //exit();
     $listSacredObject = SacredObject::model()->findAll($criteria);
     $this->data['listSacredObject'] = $listSacredObject;
     /*
      * pagination logic 
      */
     $count_object = Yii::app()->db->createCommand()->select('count(*)')->from('sacred_object o')->join('province p', 'p.pro_id = o.pro_id')->where($where_condition)->queryScalar();
     $pagin_page_count = $count_object;
     $pagin_page_all = ceil($pagin_page_count / $pagin_page_size);
     $paramsBegin = array('user' => $mem_id);
     if (1 == $pagin_page_current) {
         $paramsBegin['page'] = 1;
     } else {
         $paramsBegin['page'] = $pagin_page_current - 1;
     }
     $paramsEnd = array();
     if ($pagin_page_all == $pagin_page_current) {
         $paramsEnd['page'] = $pagin_page_all;
     } else {
         $paramsEnd['page'] = $pagin_page_current + 1;
     }
     if (!empty($mem_id)) {
         $paramsEnd['user'] = $mem_id;
         $paramsBegin['user'] = $mem_id;
     }
     $pagin_url_begin = $pagin_page_count > 0 ? Yii::app()->createUrl('site/index', $paramsBegin) : 'javascript:void(0)';
     $pagin_url_end = $pagin_page_count > 0 ? Yii::app()->createUrl('site/index', $paramsEnd) : 'javascript:void(0)';
     /*
      * DateSorting
      */
     $sortDatas = PrakruangUtility::getSortData();
     $this->data['sortDatas'] = $sortDatas;
     $this->data['total_length'] = $count_object;
     $this->data['title'] = $title;
     $this->data['display_length'] = $this->displayDefault;
     $fieldSelect = empty($_GET['field']) ? 'updatedate' : $_GET['field'];
     $this->data['sort_select'] = PrakruangUtility::getSortDataByField($fieldSelect);
     /*
      * DateSorting
      */
     $this->data['pagination'] = array('page_size' => $pagin_page_size, 'page_count' => $pagin_page_count, 'page_current' => $pagin_page_current, 'page_all' => $pagin_page_all, 'page_type_id' => $typeId, 'page_user_id' => $mem_id, 'page_url_begin' => $pagin_url_begin, 'page_url_end' => $pagin_url_end);
     /*
      * pagiation logic
      */
     $listSacredNews = SacredNews::model()->findAll(array('order' => 'news_updatedate desc', 'limit' => 10));
     $this->data['listSacredNews'] = $listSacredNews;
     /*
      * Meta SEO Tag
      */
     $metaDescription = 'พระเครื่อง';
     $sacredObjectType = SacredType::model()->findAll();
     foreach ($sacredObjectType as $index => $type) {
         $metaDescription .= ',' . $type['type_name'];
     }
     foreach ($listSacredObject as $key => $object) {
         $metaDescription .= ',' . $object->obj_name;
     }
     $this->metaDescription = $metaDescription;
     $this->metaKeywords = $metaDescription;
     /*
      * Meta SEO tag
      */
     $this->render('index', $this->data);
 }