];
}
- public function validateTimetableIntersection($attribute, $params) {
+ public function validateTimetableIntersection($attribute, $params)
+ {
\Yii::debug($this->datetime_start);
\Yii::debug($this->datetime_end);
])
->one();
if ($sameDate && ($this->isNewRecord || $this->id != $sameDate->id)) {
- $this->addError('datetime_start', 'Сотрудник ' .$this->admin->name_full.' уже добавлялся на эту дату в ' . $sameDate->store->name);
- $this->addError('time_start', 'Сотрудник ' .$this->admin->name_full.' уже добавлялся на эту дату в ' . $sameDate->store->name);
+ $this->addError('datetime_start', 'Сотрудник ' . $this->admin->name_full . ' уже добавлялся на эту дату в ' . $sameDate->store->name);
+ $this->addError('time_start', 'Сотрудник ' . $this->admin->name_full . ' уже добавлялся на эту дату в ' . $sameDate->store->name);
}
/** @var Timetable $endOverlap */
$endOverlap = self::find()
return $this->hasOne(CityStore::class, ['id' => 'store_id']);
}
- public function getCheckIns() {
- return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id']);
+ public function getCheckIns()
+ {
+ if (!empty($this->plan_id)) {
+ return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id']);
+ } else {
+ return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id'])
+ ->andWhere(['BETWEEN', 'datetime_start', date('Y-m-d H:i:s'), date('Y-m-d H:i:s', strtotime('+6 hour'))])
+ ->andWhere(['BETWEEN', 'datetime_end', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s')]);
+
+// return $this->hasOne(AdminCheckin::class, ['admin_id' => 'id'])
+// ->andWhere(['>=', 'date', date('Y-m-d 00:00:00')])
+// ->andWhere(['<=', 'date', date('Y-m-d 23:59:59')]);
+ }
}
- public function getCheckInCount() {
- return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id'])->count();
+ public function getCheckInCount()
+ {
+ if (!empty($this->plan_id)) {
+ return $this->hasMany(AdminCheckin::class, ['plan_id' => 'id'])->count();
+ } else {
+ return $this->hasMany(AdminCheckin::class, ['admin_id' => 'admin_id'])
+ ->andWhere(['BETWEEN', 'datetime_start', date('Y-m-d H:i:s'), date('Y-m-d H:i:s', strtotime('+6 hour'))])
+ ->andWhere(['BETWEEN', 'datetime_end', date('Y-m-d H:i:s', strtotime('-6 hour')), date('Y-m-d H:i:s')])->count();
+ }
}
}
\ No newline at end of file