protected function findModel($id)
 {
     if (($model = Fragment2Data::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function search($params)
 {
     $query = Fragment2Data::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'fragment_id' => $this->fragment_id, 'publish_time' => $this->publish_time, 'sort_num' => $this->sort_num]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'title_format', $this->title_format])->andFilterWhere(['like', 'title_pic', $this->title_pic])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'sub_title', $this->sub_title])->andFilterWhere(['like', 'summary', $this->summary]);
     return $dataProvider;
 }
Esempio n. 3
0
 public static function deleteData($id, $type)
 {
     Fragment::deleteAll(['id' => $id]);
     if ($type === 1) {
         Fragment1Data::deleteAll(['fragment_id' => $id]);
     } else {
         if ($type === 2) {
             Fragment2Data::deleteAll(['fragment_id' => $id]);
         } else {
             if ($type === 3) {
                 Fragment3Data::deleteAll(['fragment_id' => $id]);
             }
         }
     }
     return true;
 }
Esempio n. 4
0
 public static function getFragmentData($fraid, $other = [], $withFragment = false)
 {
     $query = null;
     // $query=Fragment1Data::find();
     $fragment = Fragment::findOne($fraid);
     if ($fragment == null) {
         return [];
     }
     $type = $fragment->type;
     if ($type == 1) {
         $query = Fragment1Data::find();
     } else {
         if ($type == 2) {
             $query = Fragment2Data::find();
         } else {
             if ($type == 3) {
                 $query = Fragment3Data::find();
             }
         }
     }
     if ($query == null) {
         return [];
     }
     $query->where(['fragment_id' => $fraid]);
     if (isset($other['where'])) {
         $query->andWhere($other['where']);
     }
     if (isset($other['order'])) {
         $query->orderBy($other['where']);
     } else {
         $query->orderBy('sort_num desc');
     }
     if (isset($other['offset']) && is_integer($other['offset'])) {
         $query->offset($other['offset']);
     }
     if (isset($other['limit']) && $other['limit']) {
         $query->limit($other['limit']);
     }
     $ret = $query->all();
     if ($type === 3) {
         $temp = [];
         foreach ($ret as $row) {
             $item = self::getContentByChannel($row['channel_id'], ['where' => 'id=' . $row['content_id']]);
             if (empty($item)) {
                 continue;
             }
             $temp[] = $item[0];
         }
         $ret = $temp;
     }
     if ($withFragment) {
         return [$fragment, $ret];
     } else {
         return $ret;
     }
 }