示例#1
0
 public function actionList()
 {
     $limit = 10;
     $page = is_null(Yii::$app->request->get('page')) ? 1 : Yii::$app->request->get('page');
     $offset = ((int) $page - 1) * $limit;
     $order = ['service.order' => SORT_ASC, 'id' => SORT_DESC];
     if (is_null(Yii::$app->request->get('section'))) {
         $service = Service::find()->select(['service.id', 'service.sid', 'service.header'])->innerJoinWith('secs')->orderBy($order)->offset($offset)->limit($limit)->all();
         $pagination = new Pagination(['totalCount' => Service::find()->count(), 'pageSize' => $limit]);
     } else {
         $service = Service::find()->select(['service.id', 'service.sid', 'service.header'])->innerJoinWith('secs')->where(['sec_service.sid' => Yii::$app->request->get('section')])->orderBy($order)->offset($offset)->limit($limit)->all();
         $pagination = new Pagination(['totalCount' => Service::find()->innerJoinWith('secs')->where(['sec_service.sid' => Yii::$app->request->get('section')])->count(), 'pageSize' => $limit]);
     }
     $sections = SecService::find()->asArray()->all();
     $pagination->pageSizeParam = false;
     $page = Page::find()->where(['sid' => Yii::$app->controller->id])->select(['id', 'pid', 'sid', 'header'])->one();
     $pages = Page::find()->select(['id', 'pid', 'sid', 'header'])->asArray()->indexBy('id')->all();
     $mode = $pages[$page->id];
     $branch[] = $mode;
     while (!is_null($mode['pid'])) {
         $mode = $pages[$mode['pid']];
         $branch[] = $mode;
     }
     krsort($branch);
     $sectionsBySid = ArrayHelper::index($sections, 'sid');
     if (!is_null(Yii::$app->request->get('section'))) {
         $branch[] = ['header' => $sectionsBySid[Yii::$app->request->get('section')]['header']];
     }
     return $this->render('list', ['service' => $service, 'sections' => $sections, 'pagination' => $pagination, 'branch' => $branch]);
 }
示例#2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SecService::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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, 'order' => $this->order]);
     $query->andFilterWhere(['like', 'sid', $this->sid])->andFilterWhere(['like', 'header', $this->header]);
     return $dataProvider;
 }
示例#3
0
 /**
  * Updates an existing Service model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     //$model->getSectionsId();
     $secServiceList = SecService::find()->select(['id', 'header'])->all();
     $secServiceList = ArrayHelper::map($secServiceList, 'id', 'header');
     // или
     // $secServiceList = SecService::find()->select(['header', 'id'])->indexBy('id')->column();
     if ($model->load(Yii::$app->request->post())) {
         $transaction = Service::getDb()->beginTransaction();
         if ($model->save()) {
             $transaction->commit();
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             $transaction->rollBack();
             return $this->render('update', ['model' => $model, 'secServiceList' => $secServiceList]);
         }
     } else {
         return $this->render('update', ['model' => $model, 'secServiceList' => $secServiceList]);
     }
 }
示例#4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSecs()
 {
     return $this->hasMany(SecService::className(), ['id' => 'sec'])->viaTable('sec_ser', ['ser' => 'id']);
 }
示例#5
0
 /**
  * Finds the SecService model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SecService the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SecService::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSec0()
 {
     return $this->hasOne(SecService::className(), ['id' => 'sec']);
 }