Example #1
0
 public static function getData($code, $other = [], $fromCache = true)
 {
     $cacheKey = self::CachePrefix . $code;
     $values = $fromCache ? LuLu::getCache($cacheKey) : false;
     if ($values === false) {
         $fragment = self::findOne(['code' => $code]);
         if ($fragment == null) {
             return [];
         }
         $query = $fragment->type === 1 ? Fragment1Data::find() : Fragment2Data::find();
         $query->where(['fragment_id' => $fragment->id, 'status' => 1]);
         $query->orderBy('sort_num asc');
         $values = $query->all();
         LuLu::setCache($cacheKey, $values);
     }
     $offset = isset($other['offset']) ? $other['offset'] : 0;
     $limit = isset($other['limit']) ? $other['limit'] : count($values) - $offset;
     return array_slice($values, $offset, $limit, true);
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Fragment2Data::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->fragment_id = LuLu::getGetValue('fid');
     $query->andFilterWhere(['fragment_id' => $this->fragment_id]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     //         $query->andFilterWhere([
     //             'id' => $this->id,
     //             'fragment_id' => $this->fragment_id,
     //             'created_at' => $this->created_at,
     //             'sort_num' => $this->sort_num,
     //             'status' => $this->status,
     //         ]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'title_format', $this->title_format])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'sub_title', $this->sub_title])->andFilterWhere(['like', 'summary', $this->summary])->andFilterWhere(['like', 'created_by', $this->created_by]);
     return $dataProvider;
 }
 /**
  * Finds the Fragment2Data model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Fragment2Data the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Fragment2Data::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }