Example #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getReason()
 {
     return $this->hasOne(Reason::className(), ['status_history_id' => 'id']);
 }
Example #2
0
 /**
  * @param int $id record id
  * @param int $user_id user id
  * @param int $code reason code
  * @param string $description reason description
  * @return bool
  */
 public function rejectDeactivation($id, $user_id, $code, $description)
 {
     $transaction = Yii::$app->getDb()->beginTransaction();
     try {
         $record = self::getRecord($id);
         if ($record->status_id == Status::FULL_COMPLETE) {
             throw new \Exception('Record has same status');
         }
         $record->setAttributes(['status_id' => Status::FULL_COMPLETE]);
         if (!$record->save(true, ['status_id'])) {
             throw new \Exception('Record status do not updated');
         }
         $history = new StatusHistory();
         $history->setAttributes(['record_id' => $id, 'author_id' => $user_id, 'status_code' => Status::FULL_COMPLETE, 'created_at' => time()]);
         if (!$history->save()) {
             throw new \Exception('StatusHistory do not created');
         }
         $reason = new Reason();
         $reason->setAttributes(['status_history_id' => $history->id, 'code' => $code, 'description' => $description]);
         if (!$reason->save()) {
             //                var_dump($reason->getErrors()); die;
             throw new \Exception('Reason do not saved');
         }
         $transaction->commit();
         return true;
     } catch (\Exception $e) {
         //            var_dump($e); die;
         $transaction->rollBack();
         return false;
     }
 }