/** * @param CHelpdeskUser $oHelpdeskUser Helpdesk user object * @param CHelpdeskThread $oThread Helpdesk thread object * @param CHelpdeskPost $oPost Helpdesk post object * @param bool $bIsNew Default value is **false**. * @param bool $bSendNotify Default value is **true**. * @param string $sCc Default value is empty string. * @param string $sBcc Default value is empty string. * * @return bool */ public function createPost(CHelpdeskUser $oHelpdeskUser, $oThread, CHelpdeskPost $oPost, $bIsNew = false, $bSendNotify = true, $sCc = '', $sBcc = '') { $bResult = false; try { if ($oPost->validate()) { if ($oPost->Type === EHelpdeskPostType::Internal && !$oHelpdeskUser->IsAgent) { $oPost->Type = EHelpdeskPostType::Normal; } if ($oHelpdeskUser->IsAgent && !$bIsNew && $oHelpdeskUser->IdHelpdeskUser !== $oThread->IdOwner) { if ($oPost->Type !== EHelpdeskPostType::Internal) { $oThread->Type = EHelpdeskThreadType::Answered; } } else { $oThread->Type = EHelpdeskThreadType::Pending; } $bResult = $this->oStorage->createPost($oHelpdeskUser, $oPost); if (!$bResult) { $this->moveStorageExceptionToManager(); throw new CApiManagerException(Errs::HelpdeskManager_PostCreateFailed); } else { if (is_array($oPost->Attachments) && 0 < count($oPost->Attachments)) { $this->oStorage->addAttachments($oHelpdeskUser, $oThread, $oPost, $oPost->Attachments); } $oThread->Updated = time(); $oThread->PostCount = $this->getPostsCount($oHelpdeskUser, $oThread); $oThread->LastPostId = $oPost->IdHelpdeskPost; $oThread->LastPostOwnerId = $oPost->IdOwner; $oThread->Notificated = false; if (!$oThread->HasAttachments) { $oThread->HasAttachments = is_array($oPost->Attachments) && 0 < count($oPost->Attachments); } $bResult = $this->updateThread($oHelpdeskUser, $oThread); $this->setThreadSeen($oHelpdeskUser, $oThread); if ($bSendNotify) { $this->sendPostNotify($oThread, $oPost, $bIsNew, $sCc, $sBcc); } if (!empty($sCc) || !empty($sBcc)) { //$this->sendPostCopy($oThread, $oPost, $bIsNew, $sCc, $sBcc); } } } } catch (CApiBaseException $oException) { if ($oException->getCode() !== \Errs::Mail_MailboxUnavailable) { $bResult = false; $this->setLastException($oException); } else { $bResult = true; } } return $bResult; }
/** * @param CHelpdeskUser $oHelpdeskUser * @param CHelpdeskThread $oThread * @param CHelpdeskPost $oPost * @param bool $bIsNew = false * @param bool $bSendNotify = true * * @return bool */ public function CreatePost(CHelpdeskUser $oHelpdeskUser, $oThread, CHelpdeskPost $oPost, $bIsNew = false, $bSendNotify = true) { $bResult = false; try { if ($oPost->Validate()) { if ($oPost->Type === EHelpdeskPostType::Internal && !$oHelpdeskUser->IsAgent) { $oPost->Type = EHelpdeskPostType::Normal; } if ($oHelpdeskUser->IsAgent && !$bIsNew && $oHelpdeskUser->IdHelpdeskUser !== $oThread->IdOwner) { if ($oPost->Type !== EHelpdeskPostType::Internal) { $oThread->Type = EHelpdeskThreadType::Answered; } } else { $oThread->Type = EHelpdeskThreadType::Pending; } $bResult = $this->oStorage->CreatePost($oHelpdeskUser, $oPost); if (!$bResult) { $this->moveStorageExceptionToManager(); throw new CApiManagerException(Errs::HelpdeskManager_PostCreateFailed); } else { if (is_array($oPost->Attachments) && 0 < count($oPost->Attachments)) { $this->oStorage->AddAttachments($oHelpdeskUser, $oThread, $oPost, $oPost->Attachments); } $oThread->Updated = time(); $oThread->PostCount = $this->GetPostsCount($oHelpdeskUser, $oThread); $oThread->LastPostId = $oPost->IdHelpdeskPost; $oThread->LastPostOwnerId = $oPost->IdOwner; $oThread->Notificated = false; if (!$oThread->HasAttachments) { $oThread->HasAttachments = is_array($oPost->Attachments) && 0 < count($oPost->Attachments); } $bResult = $this->UpdateThread($oHelpdeskUser, $oThread); $this->SetThreadSeen($oHelpdeskUser, $oThread); if ($bSendNotify) { $this->NotifyPost($oThread, $oPost, $bIsNew); } } } } catch (CApiBaseException $oException) { $bResult = false; $this->setLastException($oException); } return $bResult; }
/** * @param CHelpdeskUser $oHelpdeskUser * @param CHelpdeskThread $oThread * @param int $iStartFromId = 0 * @param int $iLimit = 20 * * @return array|bool */ public function GetPosts(CHelpdeskUser $oHelpdeskUser, $oThread, $iStartFromId = 0, $iLimit = 20) { $mResult = false; if ($this->oConnection->Execute($this->oCommandCreator->GetPosts($oHelpdeskUser, $oThread, $iStartFromId, $iLimit))) { $oRow = null; $mResult = array(); while (false !== ($oRow = $this->oConnection->GetNextRecord())) { $oHelpdeskPost = new CHelpdeskPost(); $oHelpdeskPost->InitByDbRow($oRow); $mResult[] = $oHelpdeskPost; } } $this->throwDbExceptionIfExist(); return $mResult; }
/** * @param CHelpdeskUser $oHelpdeskUser * @param CHelpdeskThread $oThread * @param int $iStartFromId = 0 * @param int $iLimit = 20 * * @return string */ public function GetPosts(CHelpdeskUser $oHelpdeskUser, $oThread, $iStartFromId = 0, $iLimit = 20) { $aMap = api_AContainer::DbReadKeys(CHelpdeskPost::GetStaticMap()); $aMap = array_map(array($this, 'escapeColumn'), $aMap); $sSql = 'SELECT %s FROM %sahd_posts WHERE deleted = 0'; $sSql = sprintf($sSql, implode(', ', $aMap), $this->Prefix()); $aWhere = $this->buildPostsWhere($oHelpdeskUser, $oThread); if (0 < $iStartFromId) { $aWhere[] = $this->escapeColumn('id_helpdesk_post') . ' < ' . $iStartFromId; } if (0 < count($aWhere)) { $sSql .= ' AND ' . implode(' AND ', $aWhere); } $sSql .= ' ORDER BY id_helpdesk_post desc LIMIT ' . $iLimit; return $sSql; }