Example #1
0
 /**
  * Create a new ticket
  */
 public function actionCreate()
 {
     // Initiate Model
     $model = new Tickets();
     $model->assignedtoid = '';
     if (isset($_POST['Tickets'])) {
         $model->setScenario('ticketupdate');
         $model->setAttributes($_POST['Tickets']);
         // Was the form submitted?
         if (isset($_POST['submit'])) {
             // Bug: assigntoid cannot be null
             if (!$model->assignedtoid) {
                 $model->assignedtoid = 0;
             }
             if ($model->save()) {
                 $comment = new TicketComments();
                 $comment->content = $model->content;
                 $comment->ticketid = $model->id;
                 $comment->firstcomment = 1;
                 $comment->save();
                 // Update ticket id
                 $model->lastcommentid = $comment->id;
                 $model->update();
                 // Mark flash and redirect
                 Functions::setFlash(Yii::t('tickets', 'Tickets: Ticket Created.'));
                 $this->redirect(array('/tickets'));
             }
         }
     }
     // make sure we display the name of the
     if (isset($_POST['Tickets']['assignedtoid'])) {
         $model->assignedtoid = $_POST['Tickets']['assignedtoid'];
     }
     // Add title
     $title = Yii::t('tickets', 'Creating A Ticket');
     $this->pageTitle[] = $title;
     $this->render('create', array('model' => $model, 'title' => $title));
 }
 public function comments()
 {
     return $this->hasMany(TicketComments::getClass());
 }
Example #3
0
 public function postReply($id = false)
 {
     $ticket = $id !== false ? Ticket::where('user_id', Auth::id())->findOrFail($id) : null;
     try {
         if (empty($ticket)) {
             return Redirect::to('ticket')->with('error', 'You need a ticket to comment');
         }
         $ticketComment = new TicketComments();
         $ticketComment->user_id = Auth::id();
         // logged in user id
         $ticketComment->ticket_id = $id;
         $ticketComment->comments = Input::get('comments');
         $success = $ticketComment->save();
         if ($success) {
             print json_encode(array('status' => 'OK', 'message' => Lang::get('ticket/ticket.ticket_comments_updated')));
             // return Redirect::intended('ticket')->with('success', Lang::get('ticket/ticket.ticket_comments_updated'));
         } else {
             print json_encode(array('status' => 'error', 'message' => Lang::get('ticket/ticket.ticket_comment_update_failed')));
             // return Redirect::to('ticket')->with('error', Lang::get('ticket/ticket.ticket_comment_update_failed'));
         }
     } catch (Exception $e) {
         Log::error($e);
         return Redirect::to('ticket')->with('error', $e->getMessage());
     }
 }