public function getStatusHistory() { return $this->hasMany(StatusHistory::className(), ['record_id' => 'id'])->orderBy(['stage_id' => SORT_ASC, 'created_at' => SORT_ASC]); }
public static function setStatusCompleted(UploadEvent $event) { $transaction = Yii::$app->getDb()->beginTransaction(); try { $record = self::getRecord($event->record->id); if ($record->status_id == Status::COMPLETE) { throw new \Exception('Record has same status'); } $record->setAttributes(['status_id' => Status::COMPLETE]); if (!$record->save(true, ['status_id'])) { throw new \Exception('Record status do not updated'); } $history = new StatusHistory(); $history->setAttributes(['record_id' => $record->id, 'author_id' => $event->user_id, 'status_code' => Status::COMPLETE, 'created_at' => time()]); if (!$history->save()) { throw new \Exception('StatusHistory do not created'); } $transaction->commit(); return true; } catch (\Exception $e) { $transaction->rollBack(); return false; } }
/** * @return \yii\db\ActiveQuery */ public function getStatusHistory() { return $this->hasOne(StatusHistory::className(), ['id' => 'status_history_id']); }
/** * @param $record_id * @return array|null|StatusHistory */ private static function getHistoryStatus($record_id) { if (is_null(self::$history)) { $condition = ['record_id' => $record_id, 'status_code' => CaseStatus::AWAITING_DEACTIVATION]; self::$history = StatusHistory::find()->where($condition)->orderBy(['id' => SORT_DESC])->one(); } return self::$history; }