Example #1
0
 public function checkRole($user, $role)
 {
     $rows = Assignment::findAll(['user' => $user, 'role' => $role]);
     if ($rows === null) {
         return false;
     }
     if (is_string($permission)) {
         return true;
     } else {
         if (count($rows) === count($role)) {
             return true;
         }
         $ret = [];
         foreach ($role as $t) {
             $found = false;
             foreach ($rows as $row) {
                 if ($t === $row['role']) {
                     $found = true;
                     break;
                 }
             }
             if (!$found) {
                 $ret[] = $t;
             }
         }
         return $ret;
     }
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Assignment::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'role', $this->role])->andFilterWhere(['like', 'note', $this->note]);
     return $dataProvider;
 }
 /**
  * Finds the Assignment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $user_id
  * @param string $role
  * @return Assignment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($user, $role)
 {
     if (($model = Assignment::findOne(['user' => $user, 'role' => $role])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }