Ejemplo n.º 1
0
 /**
  * Deletes an existing InfoCategory model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $infoModel = Info::find()->andWhere(['category_id' => $id])->one();
     if (null === $infoModel) {
         $this->findModel($id)->delete();
     } else {
         Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete category #' . $id . '. It used in other table. Change category for info #' . $infoModel->id . ' before delete.'), 'options' => ['class' => 'alert-error']]);
     }
     return $this->redirect(['index']);
 }
Ejemplo n.º 2
0
 public function actionSearch()
 {
     $request = Yii::$app->request;
     $type = $request->get("type");
     $query = Yii::$app->session->getFlash('query');
     if (!$type) {
         $type = $request->post("type");
         $content = $request->post("content");
     } else {
         $content = $request->get("content");
     }
     if ($type || !$query) {
         switch ($type) {
             case 'userId':
                 $query = Info::find()->where(['userId' => $content]);
                 break;
             case 'date':
                 $query = Info::find()->where(['between', 'createDate', date('Y-m-d H:i:s', strtotime($content)), date('Y-m-d H:i:s')]);
                 break;
             case 'state':
                 if ($content == 'record') {
                     $query = Info::find()->where(['state' => Info::STATE_RECORD]);
                 } elseif ($content == 'pass') {
                     $query = Info::find()->where(['state' => Info::STATE_PASS]);
                 } elseif ($content == 'refuse') {
                     $query = Info::find()->where(['state' => Info::STATE_REFUSE]);
                 } else {
                     $query = Info::find();
                 }
                 break;
             case 'IDCard':
             case 'cellphone':
             case 'realName':
                 $query = Info::find()->where(['like', $type, $content]);
                 break;
             default:
                 $query = Info::find();
                 break;
         }
     }
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $models = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['createDate' => SORT_DESC])->all();
     return $this->render('index', ['models' => $models, 'pages' => $pagination]);
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Info::find();
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!empty($params['mid'])) {
         $query->andFilterWhere(['model_id' => intval($params['mid'])]);
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['{{info}}.id' => $this->id, '{{info}}.slug' => $this->slug, '{{info}}.author_id' => $this->author_id, '{{info}}.category_id' => $this->category_id, '{{info}}.model_id' => $this->model_id, '{{info}}.updater_id' => $this->updater_id, '{{info}}.status' => $this->status, '{{info}}.published_at' => $this->published_at, '{{info}}.created_at' => $this->created_at, '{{info}}.updated_at' => $this->updated_at, '{{info}}.domain_id' => $this->domain_id]);
     $query->andFilterWhere(['like', '{{info}}.slug', $this->slug])->andFilterWhere(['like', '{{info}}.title', $this->title])->andFilterWhere(['like', '{{info}}.description', $this->description])->andFilterWhere(['like', '{{info}}.weight', $this->weight])->andFilterWhere(['like', '{{info}}.body', $this->body])->andFilterWhere(['like', '{{info}}.before_body', $this->before_body])->andFilterWhere(['like', '{{info}}.after_body', $this->after_body])->andFilterWhere(['like', '{{info}}.on_scenario', $this->on_scenario]);
     if (!empty($params['InfoSearch']['cid'])) {
         $query->onlyModelCategory($params['InfoSearch']['cid']);
     }
     return $dataProvider;
 }
Ejemplo n.º 4
0
 /**
  * Creates a new Info model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     foreach (Yii::$app->params['availableLocales'] as $key => $value) {
         $currentModel = Info::getLocaleInstance($key);
         $currentModel->locale = $key;
         if (Yii::$app->request->get('scenario')) {
             $currentModel->on_scenario = Yii::$app->request->get('scenario');
         }
         $models[$key] = $currentModel;
     }
     //set data from default model
     if (Yii::$app->request->get('locale_group_id')) {
         $defaultDomainModels = Info::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale_group_id' => Yii::$app->request->get('locale_group_id')])->all();
         foreach ($defaultDomainModels as $key => $value) {
             if (!in_array($value->locale, array_keys(Yii::$app->params['availableLocales']))) {
                 continue;
             }
             $models[$value->locale]->slug = $value->slug;
             $models[$value->locale]->title = $value->title;
             $models[$value->locale]->head = $value->head;
             $models[$value->locale]->body = $value->body;
             $models[$value->locale]->description = $value->description;
             $models[$value->locale]->before_body = $value->before_body;
             $models[$value->locale]->after_body = $value->after_body;
         }
     }
     $model = new MultiModel(['models' => $models]);
     if ($model->load(Yii::$app->request->post()) && Info::multiSave($model)) {
         return $this->redirect(['index', 'mid' => $model->getModel(Yii::$app->language)->model_id]);
     } else {
         switch (Yii::$app->request->get('scenario')) {
             case 'extend':
                 $viewName = 'extend';
                 break;
             default:
                 $viewName = 'create';
         }
         return $this->render($viewName, ['model' => $model, 'categories' => InfoCategory::find()->active()->all(), 'domains' => array_combine(explode(',', Yii::getAlias('@frontendUrls')), explode(',', Yii::getAlias('@frontendUrls')))]);
     }
 }
Ejemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Info::find();
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!empty($params['mid'])) {
         $query->andFilterWhere(['model_id' => intval($params['mid'])]);
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['info.id' => $this->id, 'info.author_id' => $this->author_id, 'info.category_id' => $this->category_id, 'info.model_id' => $this->model_id, 'info.updater_id' => $this->updater_id, 'info.status' => $this->status, 'info.domain_id' => $this->domain_id]);
     if ($this->search_date_published != '') {
         $this->data_begin_published = strtotime($this->search_date_published);
         $this->data_end_published = strtotime($this->search_date_published) + 24 * 60 * 60;
     }
     $query->andFilterWhere(['like', 'info.slug', $this->slug])->andFilterWhere(['like', 'info.title', $this->title])->andFilterWhere(['like', 'info.description', $this->description])->andFilterWhere(['like', 'info.weight', $this->weight])->andFilterWhere(['like', 'info.body', $this->body])->andFilterWhere(['like', 'info.before_body', $this->before_body])->andFilterWhere(['like', 'info.after_body', $this->after_body])->andFilterWhere(['between', 'info.published_at', $this->data_begin_published, $this->data_end_published])->andFilterWhere(['like', 'info.on_scenario', $this->on_scenario]);
     if (!empty($params['InfoSearch']['cid'])) {
         $query->onlyModelCategory($params['InfoSearch']['cid']);
     }
     return $dataProvider;
 }
Ejemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFirstInfo()
 {
     return Info::find()->firstInfo($this->id, $this->domain_id);
     //return $this->hasOne(ModelCategory::className(), ['id' => 'category_id']);
 }
Ejemplo n.º 7
0
 /**
  * Deletes an existing Model model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     //$this->findModel($id)->delete();
     $infoModel = Info::find()->andWhere(['model_id' => $id])->one();
     if (null === $infoModel) {
         $this->findModel($id)->delete();
     } else {
         Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete model #' . $id . '. It used in other table. Delete info page #' . $infoModel->id . ' first.'), 'options' => ['class' => 'alert-error']]);
     }
     return $this->redirect(['index']);
 }
Ejemplo n.º 8
0
 public function afterDelete()
 {
     $model = Info::find()->andWhere(['locale_group_id' => $this->locale_group_id, 'domain_id' => Yii::$app->user->identity->domain_id])->one();
     if ($model) {
         $model->delete();
     }
     return parent::afterDelete();
 }
Ejemplo n.º 9
0
 /**
  * 查询被拒绝的用户信息
  * @param $userId
  * @return array|null|\common\models\Info
  */
 public static function findRefusedByUserId($userId)
 {
     return Info::find()->where(['userId' => $userId, 'state' => Info::STATE_REFUSE])->one();
 }