Exemple #1
0
 public function validateAttribute($model, $attribute)
 {
     $value = $model->{$attribute};
     if (isset($model->id) || isset($model->item_id)) {
         /** @noinspection PhpUndefinedFieldInspection */
         $modelId = isset($model->id) ? $model->id : $model->item_id;
         if (Subject::find()->where(['!=', 'id', $modelId])->andWhere(['name' => $value])->exists()) {
             $model->addError($attribute, $this->message);
         }
     } else {
         if (Subject::find()->where(['name' => $value])->exists()) {
             $model->addError($attribute, $this->message);
         }
     }
 }
Exemple #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = parent::find();
     if (!isset($params['sort'])) {
         $query->orderBy(['name' => SORT_ASC]);
     }
     $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(['like', 'name', $this->name]);
     $query->andFilterWhere(['like', 'email', $this->email]);
     $query->andFilterWhere(['like', 'phone', $this->phone]);
     return $dataProvider;
 }
Exemple #3
0
 public function __construct($config)
 {
     $this->modelClass = Subject::className();
     parent::__construct($config);
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSubject()
 {
     return $this->hasOne(Subject::className(), ['id' => 'subject_id']);
 }
Exemple #5
0
 /**
  * Saves new subject
  */
 private function saveSubject()
 {
     $subjectModel = new Subject();
     $subjectModel->attributes = $this->toArray(['name', 'email', 'phone']);
     if ($subjectModel->save()) {
         $this->subject_id = $subjectModel->id;
     }
 }
Exemple #6
0
/* @var $form yii\bootstrap\ActiveForm */
use backend\modules\reservation\models\UsageForm;
use backend\modules\reservation\models\Subject;
use backend\modules\reservation\Module;
use kartik\datecontrol\DateControl;
use yii\bootstrap\ActiveField;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;
use yii\web\View;
/** @noinspection PhpUndefinedFieldInspection */
$actionId = $this->context->action->id;
$dayTimes = $model->getDayTimes();
$subjectsList = ArrayHelper::merge(['0' => '== ' . Module::t('res', 'new') . ' =='], Subject::getSubjects());
$subject = $model->subject_id > 0 ? Subject::findOne($model->subject_id) : null;
$timeFromTimes = array_slice($dayTimes, 0, -1, true);
$timeToTimes = array_slice($dayTimes, 1, null, true);
?>

<div class="row">

	<div class="col-sm-12">

		<?php 
$form = ActiveForm::begin(['fieldClass' => ActiveField::className()]);
?>

		<div class="row">
			<div class="col-xs-12 col-md-6">
 /**
  * Finds the model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Subject the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Subject::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }