diff --git a/common/models/Job.php b/common/models/Job.php index f15732c..d82d374 100755 --- a/common/models/Job.php +++ b/common/models/Job.php @@ -84,22 +84,43 @@ 'string', 'max' => 255, ], + [ + [ + 'link', + ], + 'match', + 'pattern' => '/^(?:https?:\/\/)?(?:w{3}\.)?'.preg_quote($_SERVER['HTTP_HOST']).'\/company\/\w+\/\d+$/i', + ], ]; } public function getExpTime() { - if($this->date_end && $this->date_start) { - $date = new \DateTime(date('Y-m-d H:i:s', $this->date_start)); - return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime(date('Y-m-d H:i:s', $this->date_end)))); - } elseif($this->date_start) { - $now = new \DateTime(); - $date = new \DateTime(date('Y-m-d H:i:s', strtotime($this->date_start))); - return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime())); + if(!empty($this->date_start) && !empty($this->date_end)) { + $result = ''; + $start = new \DateTime($this->date_start); + $end = new \DateTime($this->date_end); + $interval = $end->diff($start); + if(!empty($interval->y)) { + if($interval->y) { + $result + } + } + } elseif(!empty($this->date_start)) { + } else { - return 'неизвестна дата начала'; + return false; } - +// if($this->date_end && $this->date_start) { +// $date = new \DateTime(date('Y-m-d H:i:s', $this->date_start)); +// return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime(date('Y-m-d H:i:s', $this->date_end)))); +// } elseif($this->date_start) { +// $now = new \DateTime(); +// $date = new \DateTime(date('Y-m-d H:i:s', strtotime($this->date_start))); +// return \Yii::$app->formatter->asRelativeTime($date->diff(new \DateTime())); +// } else { +// return 'неизвестна дата начала'; +// } } /** diff --git a/common/models/User.php b/common/models/User.php index 7649808..4c0a3f5 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -523,7 +523,7 @@ public function getJobs() { return $this->hasMany(Job::className(), [ 'user_id' => 'id' ]) - ->orderBy([ 'current' => SORT_DESC ]); + ->orderBy([ 'current' => SORT_DESC, 'date_start' => SORT_DESC]); } /** diff --git a/frontend/controllers/PerformerController.php b/frontend/controllers/PerformerController.php index ee1c271..7019972 100755 --- a/frontend/controllers/PerformerController.php +++ b/frontend/controllers/PerformerController.php @@ -250,7 +250,7 @@ public function actionWorkplace($performer_id) { - $user = User::findOne($performer_id); + $user = User::find()->where(['id' => $performer_id])->with('jobs')->one(); if(!$user instanceof User) { throw new BadRequestHttpException('Пользователь не найден'); } diff --git a/frontend/views/accounts/_job_form.php b/frontend/views/accounts/_job_form.php index 785a4b4..b17364d 100755 --- a/frontend/views/accounts/_job_form.php +++ b/frontend/views/accounts/_job_form.php @@ -1,75 +1,98 @@ \Yii::$app->user->getId (), 'current' => 0]); -$form = ActiveForm::begin (); + $model = new Job([ + 'user_id' => \Yii::$app->user->getId(), + 'current' => 0, + ]); + $form = ActiveForm::begin(); ?> -