/** * After validate event * @return object */ public function afterValidate() { if (count($this->ids)) { $save = array(); // The values we would like to check if they were changed // key = value from this model // value = value from the tickets model $valuesChanged = array('status' => 'ticketstatus', 'type' => 'tickettype', 'category' => 'ticketcategory', 'priority' => 'priority', 'version' => 'ticketversion', 'fixedin' => 'fixedin', 'assignedtoid' => 'assignedtoid'); // Loop the values foreach ($valuesChanged as $key => $value) { if ($this->{$key}) { $save[$value] = $this->{$key}; } } // Only update if we have any if (count($save)) { // Update all the ticket ids Tickets::model()->updateByPk($this->ids, $save); // Load one ticket model $model = Tickets::model()->findByPk(reset($this->ids)); $this->activity['projectid'] = $model->projectid; $this->activity['type'] = Activity::TYPE_TICKET; $this->activity['title'] = 'Used multi-Moderation to update <strong>{n}</strong> {title}.'; // Append project params $this->activity['params'] = array_merge($this->activity['params'], array('{n}' => count($this->ids), '{title}' => CHtml::link(Yii::t('tickets', 'Tickets'), array('/tickets')))); // Activity: New Project Activity::log($this->activity); } } return parent::afterValidate(); }
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)); }
/** * Index action * ----------------- */ public function actionSuggestion($term) { // Find tickets that match that term $criteria = new CDbCriteria(); $criteria->addSearchCondition('t.title', $term); $criteria->limit = 10; $criteria->order = 't.title ASC'; $tickets = Tickets::model()->with(array('status', 'commentsCount'))->findAll($criteria); echo $this->renderPartial('_results', array('tickets' => $tickets), true); exit; }
/** * Search issues * */ public function actionSearch() { $search = new SearchTickets(); $doSearch = false; $tickets = array(); $pages = array(); $count = null; // If we wanted to reset the form then just reset and redirect back if (isset($_POST['reset']) && $_POST['SearchTickets']) { if (isset(Yii::app()->session['searchTerms'])) { unset(Yii::app()->session['searchTerms']); } if (Yii::app()->session['didSearch']) { unset(Yii::app()->session['didSearch']); } $this->redirect(array('search')); } if (isset($_POST['SearchTickets'])) { $search->setAttributes($_POST['SearchTickets']); if ($search->validate()) { $doSearch = true; // Store it in the session so pagging will work Yii::app()->session['searchTerms'] = $_POST['SearchTickets']; Yii::app()->session['didSearch'] = true; } } elseif (isset(Yii::app()->session['didSearch']) && Yii::app()->session['didSearch'] && isset(Yii::app()->session['searchTerms']) && count(Yii::app()->session['searchTerms'])) { $search->setAttributes(Yii::app()->session['searchTerms']); if ($search->validate()) { $doSearch = true; // Store it in the session so pagging will work Yii::app()->session['searchTerms'] = Yii::app()->session['searchTerms']; Yii::app()->session['didSearch'] = true; } } // If we passed validation then search if ($doSearch) { // Initiate Criteria $criteria = new CDbCriteria(); // Build criteria if ($search->title) { $criteria->addSearchCondition('t.title', $search->title); } if ($search->keywords) { $criteria->addSearchCondition('t.keywords', $search->keywords); } // Start with the properties $props = array('status' => 'ticketstatus', 'type' => 'tickettype', 'category' => 'ticketcategory', 'priority' => 'priority', 'version' => 'ticketversion', 'fixedin' => 'fixedin'); // Loop the props and add conditions if they were submitted foreach ($props as $key => $value) { if ($search->{$key}) { $criteria->addInCondition('t.' . $value, $search->{$key}); } } // Add the reported by and assigned to condition if ($search->reportedby) { $criteria->addInCondition('t.reportedbyid', array($search->reportedby)); } if ($search->assignedtoid) { $criteria->addInCondition('t.assignedtoid', array($search->assignedtoid)); } // Initiate Pager $count = Tickets::model()->count($criteria); $pages = new CPagination($count); $pages->route = '/tickets/search'; $pages->pageSize = Yii::app()->params['ticketsPerPage']; $pages->applyLimit($criteria); // Load them $tickets = Tickets::model()->with(array('reporter', 'assigned', 'status', 'type', 'category', 'ticketpriority', 'version', 'fixed', 'ticketmilestone'))->findAll($criteria); } // Make sure we display the name and not id of the assigned to if ($search->assignedtoid && ($user = Users::model()->findByPk($search->assignedtoid))) { $search->assignedtoid = $user->username; } // Make sure we display the name and not id of the assigned to if ($search->reportedby && ($user = Users::model()->findByPk($search->reportedby))) { $search->reportedby = $user->username; } // Load the quick moderation form $moderation = new TicketsQuickModeration(); // Title $title = Yii::t('tickets', 'Search Tickets'); $this->pageTitle[] = $title; // Render $this->render('search', array('count' => $count, 'moderation' => $moderation, 'pages' => $pages, 'tickets' => $tickets, 'title' => $title, 'search' => $search, 'doSearch' => $doSearch)); }
</head> <body> <nav class="navbar navbar-default navbar-fixed-top" role="navigation"> <div class="navbar-header"> <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> </div> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <div class="container"> <?php $this->widget('zii.widgets.CMenu', array('encodeLabel' => FALSE, 'htmlOptions' => array('class' => 'nav navbar-nav'), 'items' => array(array('label' => Yii::t('backend', 'Главная'), 'url' => array('/backend/default/index')), array('label' => Yii::t('backend', 'Страницы'), 'url' => array('/backend/pages/index')), array('label' => Yii::t('backend', 'Новости'), 'url' => array('/backend/news/index')), array('label' => Yii::t('backend', 'Юзеры'), 'url' => array('/backend/users/index')), array('label' => Yii::t('backend', 'Настройки'), 'url' => array('/backend/config/index')), array('label' => 'Lineage <b class="caret"></b>', 'url' => '#', 'submenuOptions' => array('class' => 'dropdown-menu'), 'itemOptions' => array('class' => 'dropdown'), 'linkOptions' => array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown'), 'items' => array(array('label' => Yii::t('main', 'Игровые сервера'), 'url' => array('/backend/gameServers/index')), array('label' => Yii::t('main', 'Логин сервера'), 'url' => array('/backend/loginServers/index')))), array('label' => Yii::t('backend', 'Пополнения баланса'), 'url' => array('/backend/transactions/index')), array('label' => Yii::t('backend', 'Галерея'), 'url' => array('/backend/gallery/index')), array('label' => Yii::t('main', 'Бонусы') . ' <b class="caret"></b>', 'url' => '#', 'submenuOptions' => array('class' => 'dropdown-menu'), 'itemOptions' => array('class' => 'dropdown'), 'linkOptions' => array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown'), 'items' => array(array('label' => Yii::t('main', 'Просмотр'), 'url' => array('/backend/bonuses/index')), array('label' => Yii::t('main', 'Коды'), 'url' => array('/backend/bonuses/codes')))), array('label' => '<span class="count-tickets label label-primary" rel="tooltip" title="' . Yii::t('backend', 'Новые тикеты') . '">' . Tickets::model()->count('updated_at IS NULL') . '</span>' . Yii::t('main', 'Тикеты') . ' <b class="caret"></b>', 'url' => '#', 'submenuOptions' => array('class' => 'dropdown-menu'), 'itemOptions' => array('class' => 'dropdown'), 'linkOptions' => array('class' => 'dropdown-toggle', 'data-toggle' => 'dropdown'), 'items' => array(array('label' => Yii::t('main', 'Просмотр'), 'url' => array('/backend/tickets/index')), array('label' => Yii::t('main', 'Категории'), 'url' => array('/backend/tickets/categories'))))))); ?> </div> </div> </nav> <div class="wrapper"> <section class="site-container container"> <div class="page-header"> <?php $this->widget('zii.widgets.CBreadcrumbs', array('links' => $this->breadcrumbs, 'homeLink' => '<li>' . CHtml::link(Yii::t('main', 'Главная'), array('/backend/default/index')) . '</li>')); ?> </div> <?php echo $content;
public function actionClose($ticket_id) { $ticket = Tickets::model()->findByPk($ticket_id); if ($ticket === NULL) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Тикет не найден.')); } elseif ($ticket->user_id != user()->getId()) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Можно закрыть только свой тикет.')); } elseif ($ticket->isStatusOff()) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Тикет уже закрыт.')); } else { $ticket->status = ActiveRecord::STATUS_OFF; if ($ticket->save(FALSE)) { user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('main', 'Тикет :ticket_name закрыт.', array(':ticket_name' => '<b>' . e($ticket->title) . '</b>'))); } else { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('main', 'Произошла ошибка! Попробуйте повторить позже.')); Yii::log("Неудалось закрыть тикет\nID: " . $ticket_id . "\n", CLogger::LEVEL_ERROR, 'tickets'); } } $this->redirectBack(); }