Example #1
0
 public function getAttachments()
 {
     return $this->hasMany(IssueAttachment::className(), ['_id' => 'attachmentIds']);
 }
 private function _createIssue()
 {
     $params = $this->getParams();
     $issue = new Issue();
     $issue->attributes = $params;
     $issue->origin = $params['origin'];
     $issue->status = Issue::STATUS_OPEN;
     $accountId = '';
     if (isset($params['accountId'])) {
         $accountId = new \MongoId($params['accountId']);
     } else {
         $accountId = $this->getAccountId();
     }
     $issue->accountId = $accountId;
     if ($params['origin'] !== IssueUser::HELPDESK) {
         $issue->creator = $this->_createIssueUser($params);
     } else {
         $issue->creator = $this->_getCurrentUser();
     }
     if (isset($params['attachments'])) {
         $attachments = $params['attachments'];
         if (IssueAttachment::batchInsert($attachments)) {
             $issue->attachmentIds = $this->_getIdArray($attachments);
         }
     }
     if ($issue->save()) {
         $this->_createActivity($issue);
         $issue->creator = $issue->creatorDetail;
         $data = $issue->toArray();
         $this->_sendTuisongbaoEvent($params, Issue::EVENT_NEW_ISSUE, $data, $accountId);
         return $data;
     }
     return ['errors' => $issue->errors];
 }