コード例 #1
0
 /**
  * Creates a new Note model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Note();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
ファイル: NoteController.php プロジェクト: jslight/helpdesk
 /**
  * Creates a new Note model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Note();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['ticket/view', 'id' => $model->ticket_id]);
     } elseif (!Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->get());
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $model]);
     }
     return $this->render('create', ['model' => $model]);
 }
コード例 #3
0
 public function actionLogWork($remote = false)
 {
     $model = new Schedule(['scenario' => Schedule::SCENARIO_REMOTE]);
     $model->loadDefaultValues();
     $model->duration = null;
     $model->tech_id = Yii::$app->user->id;
     $note = new Note(['scenario' => Note::SCENARIO_REMOTE]);
     $ticket = new Ticket(['scenario' => Ticket::SCENARIO_REMOTE]);
     if ($model->load(Yii::$app->request->post()) && $model->validate() && $note->load(Yii::$app->request->post()) && $note->validate()) {
         if (empty($note->ticket_id)) {
             // new ticket
             if (!($ticket->load(Yii::$app->request->post()) && !empty(trim($ticket->title)) && $ticket->validate())) {
                 $ticket->addError('title', 'Select a ticket or enter a title to create a new one');
             } else {
                 $ticket->invoice_id = $model->invoice_id;
                 $ticket->status_id = $ticket::STATUS_IN_PROGRESS;
                 if ($ticket->save(false) && $model->save(false)) {
                     $note->link('ticket', $ticket);
                     $note->link('schedule', $model, ['hours' => $model->duration / 60]);
                     return $this->redirect(['ticket/view', 'id' => $note->ticket_id]);
                 }
             }
         } elseif ($model->save(false) && $note->save(false)) {
             $note->link('schedule', $model, ['hours' => $model->duration / 60]);
             if ($note->ticket->status_id == $ticket::STATUS_SUBMITTED) {
                 $note->ticket->status_id = $ticket::STATUS_IN_PROGRESS;
                 $note->ticket->save(false);
             }
             return $this->redirect(['ticket/view', 'id' => $note->ticket_id]);
         }
     } elseif (!Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->get());
         $note->load(Yii::$app->request->get());
         $ticket->load(Yii::$app->request->get());
     }
     if (empty($model->start_time)) {
         $minutes = time() / 60;
         $minutes = $minutes - $minutes % 5;
         // round down to 5 min increment
         $model->start_time = date('Y-m-d H:i:00', $minutes * 60);
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('log-work', ['model' => $model, 'note' => $note, 'ticket' => $ticket, 'remote' => $remote]);
     }
     return $this->render('log-work', ['model' => $model, 'note' => $note, 'ticket' => $ticket, 'remote' => $remote]);
 }
コード例 #4
0
ファイル: TicketController.php プロジェクト: jslight/helpdesk
 public function actionDuplicate($id)
 {
     $model = $this->findModel($id);
     $model->status_id = $model::STATUS_DUPLICATE;
     $model->scenario = $model::SCENARIO_DUPLICATE;
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $noteAppend = "\r\n\r\n---Moved from duplicate " . $model->fullName . ' ( ' . Url::base(true) . Url::to(['/ticket/view', 'id' => $model->id]) . ' )';
         foreach ($model->notes as $note) {
             //duplicate the original note and attach to original ticket
             $oldNote = new Note($note->attributes);
             $oldNote->id = null;
             $oldNote->save(false);
             //move the original note to the new ticket
             $note->scenario = $note::SCENARIO_DUPLICATE;
             $note->ticket_id = $model->dup_id;
             if (!empty($note->body)) {
                 $note->body .= $noteAppend;
             }
             $note->save(false);
         }
         $newNote = new Note();
         $newNote->ticket_id = $model->id;
         $newNote->body = '---Marked as duplicate of TT#' . $model->dup_id . ' ( ' . Url::base(true) . Url::to(['/ticket/view', 'id' => $model->dup_id]) . ' )';
         $newNote->save(false);
         if ($model->save(false)) {
             return $this->redirect(['/ticket/view', 'id' => $model->dup_id]);
         }
     }
     if (Yii::$app->request->isAjax) {
         return $this->renderAjax('duplicate', ['model' => $model]);
     }
     return $this->render('duplicate', ['model' => $model]);
 }
コード例 #5
0
ファイル: Schedule.php プロジェクト: jslight/helpdesk
 /**
  * @inheritdoc
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     // if onSite was changed in the form
     if ($this->onSite == empty($this->travel)) {
         if ($this->onSite) {
             $this->link('travel', new Travel());
         } else {
             $this->unlink('travel', $this->travel, true);
         }
     }
     // compile an array with [note_id => ticket_id] for each ticket currently attached
     $note_to_ticket = ArrayHelper::map($this->notes, 'id', 'ticket_id');
     // are we updating an existing event?
     if (!$insert) {
         // get a list of all tickets that need to be removed from event
         $removeNotes = array_keys(array_diff($note_to_ticket, $this->ticketIds));
         Note::deleteAll(['id' => $removeNotes, 'author_id' => null]);
         Labor::deleteAll(['schedule_id' => $this->id, 'note_id' => $removeNotes, 'hours' => null]);
     }
     // get a list of all the tickets to add and attach them to the event
     foreach (array_diff($this->ticketIds, $note_to_ticket) as $ticket_id) {
         $note = new Note(['scenario' => Note::SCENARIO_SCHEDULE, 'ticket_id' => $ticket_id]);
         $note->save(false);
         $this->link('notes', $note);
         // update the ticket status if still submitted
         if ($note->ticket->status_id == Ticket::STATUS_SUBMITTED) {
             $note->ticket->status_id = Ticket::STATUS_IN_PROGRESS;
             $note->ticket->save(false);
         }
     }
 }