Example #1
0
 public function actionItems($mid, $type = 'all', $stype = null, $sword = null)
 {
     if (\Yii::$app->request->isPost) {
         $scenario = \Yii::$app->request->post('scenario');
         $items = \Yii::$app->request->post('items');
         if ($scenario && $items) {
             foreach ($items as $id => $attributes) {
                 if (($item = SiteModuleItem::findOne($id)) && $attributes) {
                     $item->scenario = $scenario;
                     foreach ($attributes as $attribute => $value) {
                         $item->{$attribute} = $value;
                     }
                     $item->commonHandler();
                 }
             }
         }
         return $this->refresh();
     }
     $superior = SiteModule::findOne(['id' => $mid, 'site_id' => $this->module->siteId, 'type' => SiteModule::TYPE_MENU]);
     if (!$superior) {
         throw new NotFoundHttpException(\Yii::t($this->module->messageCategory, 'no matched data'));
     }
     if ($type !== 'all') {
         $query->andWhere(['type' => $type]);
     }
     $query = SiteModuleItem::find()->where(['site_id' => $this->module->siteId, 'module_id' => $mid])->orderby('list_order desc, created_at');
     if ($sword !== null) {
         $query->andWhere(['like', "{$stype}", $sword]);
     }
     $pagination = new Pagination(['totalCount' => $query->count()]);
     $items = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     $typeItems = ArrayHelper::merge(['all' => \Yii::t($this->module->messageCategory, '{attribute} {action}', ['attribute' => \Yii::t($this->module->messageCategory, 'type'), 'action' => \Yii::t($this->module->messageCategory, 'filtering')])], SiteModuleItem::defaultAttributeItems('type'));
     return $this->render($this->action->id, ['type' => $type, 'stype' => $stype, 'sword' => $sword, 'superior' => $superior, 'items' => $items, 'pagination' => $pagination, 'typeItems' => $typeItems]);
 }