Пример #1
0
 public function actionEdit($id)
 {
     $ticket = Tickets::model()->with(array('category', 'user'))->findByPk($id);
     if ($ticket === NULL) {
         user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('backend', 'Тикет не найден.'));
         $this->redirect(array('/backend/tickets/index'));
     }
     if (!$ticket->user) {
         user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('backend', 'Связь с таблицей "Users" была нарушена.'));
         $this->redirect(array('/backend/tickets/index'));
     }
     // Убираю статус нового сообщения
     if ($ticket->new_message_for_admin == Tickets::STATUS_NEW_MESSAGE_ON) {
         $ticket->new_message_for_admin = 0;
         $ticket->save(FALSE, array('new_message_for_admin', 'updated_at'));
     }
     // Ответы
     $answersDataProvider = new CActiveDataProvider('TicketsAnswers', array('criteria' => array('condition' => 'ticket_id = :ticket_id', 'params' => array('ticket_id' => $ticket->id), 'order' => 't.created_at DESC', 'with' => 'userInfo'), 'pagination' => array('pageSize' => 10, 'pageVar' => 'page')));
     $model = new TicketsAnswers();
     if (isset($_POST['TicketsAnswers'])) {
         $model->setAttributes($_POST['TicketsAnswers']);
         $model->ticket_id = $id;
         if ($model->save()) {
             // change new message status
             $ticket->new_message_for_user = 1;
             $ticket->save(FALSE, array('new_message_for_user', 'updated_at'));
             notify()->userNoticeTicketAnswer($ticket->user->email, array('ticket' => $ticket, 'user' => $ticket->user));
             user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('backend', 'Ответ добавлен.'));
             $this->refresh();
         }
     }
     $this->render('//tickets/edit', array('ticket' => $ticket, 'model' => $model, 'answersDataProvider' => $answersDataProvider));
 }
Пример #2
0
 public function actionView($ticket_id)
 {
     $ticket = Tickets::model()->find('t.id = :id AND t.user_id = :user_id', array(':id' => $ticket_id, ':user_id' => user()->getId()));
     if ($ticket === NULL) {
         user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Тикет не найден.'));
         $this->redirect(array('/cabinet/tickets/index'));
     }
     // Ответы
     $dependency = new CDbCacheDependency('SELECT MAX(UNIX_TIMESTAMP(created_at)) FROM {{tickets_answers}} WHERE ticket_id = :ticket_id');
     $dependency->params = array('ticket_id' => $ticket_id);
     $model = TicketsAnswers::model()->cache(3600 * 24, $dependency, 2);
     $dataProvider = new CActiveDataProvider($model, array('criteria' => array('condition' => 'ticket_id = :ticket_id', 'params' => array(':ticket_id' => $ticket->id), 'order' => 't.created_at DESC'), 'pagination' => array('pageSize' => config('cabinet.tickets.answers.limit'), 'pageVar' => 'page')));
     $model = new TicketsAnswers();
     // При просмотре удаляю статус нового сообщения
     if ($ticket->new_message_for_user) {
         $ticket->new_message_for_user = 0;
         $ticket->save(FALSE);
     }
     if (isset($_POST['TicketsAnswers']) && $ticket->isStatusOn()) {
         $model->setAttributes($_POST['TicketsAnswers']);
         $model->setAttribute('ticket_id', $ticket_id);
         $model->setAttribute('gs_id', user()->getGsId());
         if ($model->validate()) {
             $model->save(FALSE);
             $ticket->new_message_for_admin = 1;
             $ticket->save(FALSE);
             user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Ваше сообщение успешно добавлено!'));
             $this->refresh();
         }
     }
     $this->render('//cabinet/tickets/view', array('ticket' => $ticket, 'model' => $model, 'answersDataProvider' => $dataProvider));
 }