/** * Creates a new Ticket model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Ticket(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Ticket model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Ticket(); $model->setToCurrentActiveBoard(); //A new ticket belongs to the current active board $model->moveToBacklog(); //A new ticket always starts in the backlog if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Ticket model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($close = false) { $model = new Ticket(); $model->loadDefaultValues(); if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($close) { return "<script>window.close();</script>"; } return $this->redirect(['view', 'id' => $model->id]); } elseif (!Yii::$app->request->isPost) { $model->load(Yii::$app->request->get()); } if (!empty($model->invoice_id)) { $model->bill_type_id = $model->invoice->location->proactive; } if (Yii::$app->request->isAjax) { return $this->renderAjax('_form', ['model' => $model]); } return $this->render('create', ['model' => $model]); }
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]); }
/** * 创建工单 * @return string|\yii\web\Response */ public function actionAdd_ticket() { $ticketModel = new Ticket(); $ticketCdataModel = new TicketCdata(); if (Yii::$app->request->post()) { $ticketForm = Yii::$app->request->post('Ticket'); $ticketCdataForm = Yii::$app->request->post('TicketCdata'); $fileForm = Yii::$app->request->post('File'); $ticketTopicRelationForm = Yii::$app->request->post('TicketTopicRelation'); $ticketModel->number = $ticketModel->newTicketNumber(); $ticketModel->user_id = Yii::$app->user->identity->id; $ticketModel->status_id = TicketStatus::CREATED; $ticketModel->type_id = Ticket::FEEDBACK_TICKET_TYPE; $ticketModel->source_id = 1; $ticketModel->ip_address = Yii::$app->request->getUserIP(); $ticketModel->created = date("Y-m-d H:i:s"); $ticketModel->updated = date("Y-m-d H:i:s"); $ticketCdataModel->subject = $ticketCdataForm['subject']; $ticketCdataModel->detail = $ticketCdataForm['detail']; $ticketCdataModel->priority = 1; //事务 $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { if (!$ticketModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1001)"); } $ticketCdataModel->ticket_id = $ticketModel->ticket_id; if (!$ticketCdataModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1002)"); } if (!empty($fileForm['file_index']) && is_array($fileForm['file_index'])) { foreach ($fileForm['file_index'] as $k => $v) { $fileModel = new File(); $fileModel->attribute = Ticket::tableName(); $fileModel->attribute_id = $ticketModel->ticket_id; $fileModel->file_name = $v['name']; $fileModel->file_index = $v['path']; $fileModel->size = $v['size']; $fileModel->type = $v['type']; if (!$fileModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1003)"); } } } if (!empty($ticketTopicRelationForm['topic_id']) && is_array($ticketTopicRelationForm['topic_id'])) { foreach ($ticketTopicRelationForm['topic_id'] as $v) { $ticketTopicRelationModel = new TicketTopicRelation(); $ticketTopicRelationModel->ticket_id = $ticketModel->ticket_id; $ticketTopicRelationModel->topic_id = $v; if (!$ticketTopicRelationModel->save()) { throw new Exception("数据存储失败,请检查数据库配置(error:1004)"); } } } $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); return $this->redirect(array('add_ticket')); } return $this->redirect(array('detail', 'number' => $ticketModel->number)); } else { $topicModel = new TicketTopic(); $topic_list = $topicModel->find()->select(array('topic_name', 'topic_id'))->indexBy('topic_id')->column(); $fileModel = new File(); $ticketTopicRelationModel = new TicketTopicRelation(); return $this->render('add_ticket', array('ticketModel' => $ticketModel, 'ticketCdataModel' => $ticketCdataModel, 'fileModel' => $fileModel, 'ticketTopicRelationModel' => $ticketTopicRelationModel, 'topic_list' => $topic_list)); } }