Example #1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     $this->articleIds = explode(',', $this->articleIdsStr);
     $deleteArticleIds = array_diff($this->_oldArticleIds, $this->articleIds);
     $addArticleIds = array_diff($this->articleIds, $this->_oldArticleIds);
     foreach ($this->articleMultArticles as $articleMultArticle) {
         if (in_array($articleMultArticle->article_id, $deleteArticleIds)) {
             $articleMultArticle->delete();
         }
     }
     foreach ($addArticleIds as $articleId) {
         $model = new MArticleMultArticle();
         $model->article_mult_id = $this->article_mult_id;
         $model->article_id = $articleId;
         $model->save(false);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MArticleMultArticle::find()->where(['gh_id' => Yii::$app->user->getGhid()])->orderBy(['sort_order' => SORT_DESC, 'article_mult_article_id' => SORT_DESC]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->andFilterWhere(['article_mult_id' => $this->article_mult_id]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['article_mult_article_id' => $this->article_mult_article_id, 'article_mult_id' => $this->article_mult_id, 'article_id' => $this->article_id, 'sort_order' => $this->sort_order]);
     $query->andFilterWhere(['like', 'gh_id', $this->gh_id]);
     return $dataProvider;
 }
Example #3
0
 public function getArticleMultArticles()
 {
     return $this->hasMany(MArticleMultArticle::className(), ['article_id' => 'article_id']);
 }
 /**
  * Finds the MArticleMultArticle model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return MArticleMultArticle the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MArticleMultArticle::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }