/**
  * check DB for unique link (exists or not)
  */
 public function validateExists()
 {
     $link = StatusesLinks::find()->where(['status_from' => $this->status_from, 'status_to' => $this->status_to, 'right_id' => $this->right_id])->one();
     if (!is_null($link)) {
         $this->addError('status_from', Yii::t('statuses', 'Statuses Links is exists.'));
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($statusesId, $params)
 {
     $query = StatusesLinks::find()->with('statusFrom')->where(['status_from' => $statusesId]);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     // надо здесь создать условия для фильтрации элементов единиц StatusLink
     // по именам связанных статусов и прав
     $query->joinWith(['statusTo' => function ($query) {
         $query->where(['or', '"statuses"."name" LIKE ' . "'%" . $this->statusName . "%'", '"statuses"."symbolic_id" LIKE ' . "'%" . $this->statusName . "%'"]);
     }])->joinWith(['right' => function ($query) {
         $query->where('"ref_rights"."name" LIKE ' . "'%" . $this->rightName . "%'");
     }]);
     $dataProvider->setSort(['attributes' => ['statusName' => ['asc' => ['statuses.name' => SORT_ASC], 'desc' => ['statuses.name' => SORT_DESC], 'default' => SORT_ASC], 'rightName' => ['asc' => ['ref_rights.name' => SORT_ASC], 'desc' => ['ref_rights.name' => SORT_DESC], 'default' => SORT_ASC]]]);
     return $dataProvider;
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getStatusesLinksTo()
 {
     return $this->hasMany(StatusesLinks::className(), ['status_to' => 'id'])->from(['statusesLinksTo' => StatusesLinks::tableName()]);
 }
 /**
  * Finds the StatusesLinks model based on keys 'status_from', 'status_to' and 'right_id'.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return StatusesLinks the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelLink($status_from, $status_to, $right_id)
 {
     $model = StatusesLinks::find()->where(['status_from' => $status_from, 'status_to' => $status_to, 'right_id' => $right_id])->one();
     if ($model !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('statuses', 'The requested page does not exist.'));
     }
 }