Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserGroup::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, 'owner_id' => $this->owner_id]);
     $query->andFilterWhere(['like', 'participants', $this->participants])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Example #2
0
 public function saveAll()
 {
     $__models = UserGroup::findAll(['userId' => $this->Id]);
     if (is_array($__models)) {
         $groups = $this->groupMap;
         foreach ($__models as $index => $model) {
             if (isset($groups[$index])) {
                 $model->groupId = $groups[$index];
                 $flag = $model->save();
                 unset($groups[$index]);
             } else {
                 $model->delete();
             }
             if (!$flag) {
                 break;
             }
         }
         foreach ($groups as $groupId) {
             //new insert
             $model = new UserGroup();
             $model->groupId = $groupId;
             $model->userId = $this->Id;
             $flag = $model->save();
             if (!$flag) {
                 break;
             }
         }
     } else {
         //new insertion
         foreach ($this->groupMap as $groupId) {
             $model = new UserGroup();
             $model->groupId = $groupId;
             $model->userId = $this->Id;
             $flag = $model->save();
             if (!$flag) {
                 break;
             }
         }
     }
     return $flag;
 }
Example #3
0
 public function getMapedUsers()
 {
     return $this->hasMany(UserGroup::className(), ['groupId' => 'Id']);
 }
Example #4
0
 /**
  * Finds the UserGroup model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserGroup the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserGroup::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function getUsersGroup()
 {
     return $this->usergroupsDP = new ActiveDataProvider(['query' => UserGroup::find()->where(['userId' => $this->Id])]);
 }