Esempio n. 1
0
 protected function findModel($id)
 {
     if (($model = Fragment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 2
0
 public function search($params)
 {
     $query = Fragment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'type' => $this->type, 'sort_num' => $this->sort_num]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
 public function actionUpdate($id, $fraid = null)
 {
     $model = $this->findModel($id);
     $fraid = $model->fragment_id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'fraid' => $fraid]);
     } else {
         $locals = [];
         $locals['model'] = $model;
         $locals['currentFragment'] = Fragment::findOne($fraid);
         return $this->render('update', $locals);
     }
 }
Esempio n. 4
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. 5
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;
     }
 }
Esempio n. 6
0
 public function getFragment()
 {
     return $this->hasOne(Fragment::className(), ['id' => 'fragment_id']);
 }