2015-11-09 11:01:11 -04:00
|
|
|
<?php
|
|
|
|
|
|
2017-08-11 11:10:27 -04:00
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
class labelsGmail
|
|
|
|
|
{
|
|
|
|
|
function listLabels($service)
|
|
|
|
|
{
|
|
|
|
|
$labels = array();
|
|
|
|
|
try {
|
|
|
|
|
$labelsResponse = $service->users_labels->listUsersLabels('me');
|
|
|
|
|
if ($labelsResponse->getLabels()) {
|
|
|
|
|
$labels = array_merge($labels, $labelsResponse->getLabels());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
2016-04-25 10:59:21 -04:00
|
|
|
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . G::getErrorMessage($e);
|
2015-12-19 14:38:45 -04:00
|
|
|
throw ($e);
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
return $labels;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Modify the Labels a Message is associated with.
|
|
|
|
|
*
|
2016-01-06 11:07:56 -04:00
|
|
|
* @param Google_Service_Gmail $service Authorized Gmail API instance.
|
|
|
|
|
* @param string $userId User's email address. The special value 'me'
|
|
|
|
|
* can be used to indicate the authenticated user.
|
|
|
|
|
* @param string $messageId ID of Message to modify.
|
|
|
|
|
* @param array $labelsToAdd Array of Labels to add.
|
|
|
|
|
* @param array $labelsToRemove Array of Labels to remove.
|
2015-11-09 11:01:11 -04:00
|
|
|
*/
|
2016-01-06 11:07:56 -04:00
|
|
|
function modifyMessage($service, $userId, $messageId, $labelsToAdd, $labelsToRemove)
|
|
|
|
|
{
|
2015-11-09 11:01:11 -04:00
|
|
|
$mods = new Google_Service_Gmail_ModifyMessageRequest();
|
|
|
|
|
$mods->setAddLabelIds($labelsToAdd);
|
|
|
|
|
$mods->setRemoveLabelIds($labelsToRemove);
|
|
|
|
|
try {
|
|
|
|
|
$message = $service->users_messages->modify($userId, $messageId, $mods);
|
|
|
|
|
} catch (Exception $e) {
|
2016-04-25 10:59:21 -04:00
|
|
|
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . G::getErrorMessage($e);
|
2015-12-19 14:38:45 -04:00
|
|
|
throw ($e);
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get list of Messages in user's mailbox.
|
|
|
|
|
*
|
|
|
|
|
* @param Google_Service_Gmail $service Authorized Gmail API instance.
|
2016-01-06 11:07:56 -04:00
|
|
|
* @param string $userId User's email address. The special value 'me'
|
|
|
|
|
* can be used to indicate the authenticated user.
|
|
|
|
|
*
|
2015-11-09 11:01:11 -04:00
|
|
|
* @return array Array of Messages.
|
|
|
|
|
*/
|
2016-01-06 11:07:56 -04:00
|
|
|
function listMessages($service, $userId, $query, $labels)
|
|
|
|
|
{
|
|
|
|
|
$pageToken = null;
|
2015-11-09 11:01:11 -04:00
|
|
|
$messages = array();
|
|
|
|
|
$opt_param = array();
|
|
|
|
|
do {
|
|
|
|
|
try {
|
|
|
|
|
if ($pageToken) {
|
|
|
|
|
$opt_param['pageToken'] = $pageToken;
|
|
|
|
|
}
|
|
|
|
|
$opt_param['labelIds'] = $labels;
|
|
|
|
|
$opt_param['q'] = $query;
|
|
|
|
|
$opt_param['maxResults'] = 3;
|
|
|
|
|
$messagesResponse = $service->users_messages->listUsersMessages($userId, $opt_param);
|
|
|
|
|
if ($messagesResponse->getMessages()) {
|
|
|
|
|
$messages = array_merge($messages, $messagesResponse->getMessages());
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
2016-04-25 10:59:21 -04:00
|
|
|
print G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . G::getErrorMessage($e);
|
2015-12-19 14:38:45 -04:00
|
|
|
throw ($e);
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
} while ($pageToken);
|
|
|
|
|
|
|
|
|
|
return $messages;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
public function setLabelsToPauseCase($caseId, $index)
|
|
|
|
|
{
|
2015-12-20 18:56:46 -04:00
|
|
|
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
|
|
|
|
$appData = $Pmgmail->getDraftApp($caseId, $index);
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
foreach ($appData as $application) {
|
2015-12-20 18:56:46 -04:00
|
|
|
$appNumber = $application['APP_NUMBER'];
|
|
|
|
|
$index = $application['DEL_INDEX'];
|
|
|
|
|
$threadUsr = $application['USR_UID'];
|
|
|
|
|
$proName = $application['APP_PRO_TITLE'];
|
|
|
|
|
$threadStatus = $application['DEL_THREAD_STATUS'];
|
|
|
|
|
$appStatus = $application['APP_STATUS'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Getting the privious User email
|
|
|
|
|
$oUsers = new \Users();
|
|
|
|
|
$usrData = $oUsers->loadDetails($threadUsr);
|
|
|
|
|
$mail = $usrData['USR_EMAIL'];
|
|
|
|
|
|
|
|
|
|
//The Subject to search the email
|
2016-09-26 16:44:58 -04:00
|
|
|
$subject = "[PM] " . $proName . " (" . $index . ") Case: " . $appNumber;
|
2015-12-20 18:56:46 -04:00
|
|
|
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle = new PmGoogleApi();
|
2015-12-20 18:56:46 -04:00
|
|
|
$pmGoogle->setUser($mail);
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle->setScope(PmGoogleApi::GMAIL_MODIFY);
|
2015-12-20 18:56:46 -04:00
|
|
|
$client = $pmGoogle->serviceClient();
|
|
|
|
|
$service = new Google_Service_Gmail($client);
|
|
|
|
|
$labelsIds = $this->getLabelsIds($service);
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
if ($appStatus == 'DRAFT') {
|
2015-12-20 18:56:46 -04:00
|
|
|
$labelsToRemove = $labelsIds['Draft'];
|
|
|
|
|
$labelsToSearch = "*-draft";
|
|
|
|
|
$labelsToAdd = $labelsIds['Paused'];
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
if ($appStatus == 'TO_DO') {
|
2015-12-20 18:56:46 -04:00
|
|
|
$labelsToRemove = $labelsIds['Inbox'];
|
|
|
|
|
$labelsToSearch = "*-inbox";
|
|
|
|
|
$labelsToAdd = $labelsIds['Paused'];
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
$q = "subject:('" . preg_quote($subject, '-') . "') label:('" . $labelsToSearch . "')";
|
2015-12-20 18:56:46 -04:00
|
|
|
$messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
|
|
|
|
|
foreach ($messageList as $message) {
|
|
|
|
|
$messageId = $message->getId();
|
2016-01-06 11:07:56 -04:00
|
|
|
$modifyResult = $this->modifyMessage($service, $mail, $messageId, array($labelsToAdd),
|
|
|
|
|
array($labelsToRemove));
|
2015-12-20 18:56:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-07 11:55:46 -04:00
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
function setLabelsTounpauseCase($caseId, $index)
|
|
|
|
|
{
|
2015-12-07 11:55:46 -04:00
|
|
|
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
|
|
|
|
$appData = $Pmgmail->getDraftApp($caseId, $index);
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
foreach ($appData as $application) {
|
2015-12-07 11:55:46 -04:00
|
|
|
$appNumber = $application['APP_NUMBER'];
|
|
|
|
|
$index = $application['DEL_INDEX'];
|
|
|
|
|
$threadUsr = $application['USR_UID'];
|
|
|
|
|
$proName = $application['APP_PRO_TITLE'];
|
|
|
|
|
$threadStatus = $application['DEL_THREAD_STATUS'];
|
|
|
|
|
$appStatus = $application['APP_STATUS'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Getting the privious User email
|
|
|
|
|
$oUsers = new \Users();
|
|
|
|
|
$usrData = $oUsers->loadDetails($threadUsr);
|
|
|
|
|
$mail = $usrData['USR_EMAIL'];
|
|
|
|
|
|
|
|
|
|
//The Subject to search the email
|
2016-09-26 16:44:58 -04:00
|
|
|
$subject = "[PM] " . $proName . " (" . $index . ") Case: " . $appNumber;
|
2015-12-07 11:55:46 -04:00
|
|
|
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle = new PmGoogleApi();
|
2015-12-07 11:55:46 -04:00
|
|
|
$pmGoogle->setUser($mail);
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle->setScope(PmGoogleApi::GMAIL_MODIFY);
|
2015-12-07 11:55:46 -04:00
|
|
|
$client = $pmGoogle->serviceClient();
|
|
|
|
|
$service = new Google_Service_Gmail($client);
|
|
|
|
|
$labelsIds = $this->getLabelsIds($service);
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
if ($appStatus == 'DRAFT') {
|
2015-12-07 11:55:46 -04:00
|
|
|
$labelsToRemove = $labelsIds['Paused'];
|
|
|
|
|
$labelsToSearch = "*-paused";
|
|
|
|
|
$labelsToAdd = $labelsIds['Draft'];
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
if ($appStatus == 'TO_DO') {
|
2015-12-07 11:55:46 -04:00
|
|
|
$labelsToRemove = $labelsIds['Paused'];
|
|
|
|
|
$labelsToSearch = "*-paused";
|
|
|
|
|
$labelsToAdd = $labelsIds['Inbox'];
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
$q = "subject:('" . preg_quote($subject, '-') . "') label:('" . $labelsToSearch . "')";
|
2015-12-07 11:55:46 -04:00
|
|
|
$messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
|
|
|
|
|
foreach ($messageList as $message) {
|
|
|
|
|
$messageId = $message->getId();
|
2016-01-06 11:07:56 -04:00
|
|
|
$modifyResult = $this->modifyMessage($service, $mail, $messageId, array($labelsToAdd),
|
|
|
|
|
array($labelsToRemove));
|
2015-12-07 11:55:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
public function setLabels($caseId, $index, $actualLastIndex, $unassigned = false)
|
|
|
|
|
{
|
2015-11-09 11:01:11 -04:00
|
|
|
//First getting the actual thread data
|
|
|
|
|
$Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
|
2015-12-07 09:34:42 -04:00
|
|
|
$appData = $Pmgmail->getDraftApp($caseId, $index);
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
foreach ($appData as $application) {
|
2015-11-09 11:01:11 -04:00
|
|
|
$appNumber = $application['APP_NUMBER'];
|
|
|
|
|
$index = $application['DEL_INDEX'];
|
|
|
|
|
$threadUsr = $application['USR_UID'];
|
|
|
|
|
$proName = $application['APP_PRO_TITLE'];
|
|
|
|
|
$threadStatus = $application['DEL_THREAD_STATUS'];
|
2015-12-07 11:55:46 -04:00
|
|
|
$appStatus = $application['APP_STATUS'];
|
2015-12-20 18:56:46 -04:00
|
|
|
$tasUid = $application['TAS_UID'];
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
if ($threadStatus == 'CLOSED' || $unassigned == true) {
|
2015-11-09 11:01:11 -04:00
|
|
|
//Getting the privious User email
|
|
|
|
|
$oUsers = new \Users();
|
|
|
|
|
|
|
|
|
|
$usrData = $oUsers->loadDetails($threadUsr);
|
|
|
|
|
$mail = $usrData['USR_EMAIL'];
|
|
|
|
|
|
|
|
|
|
//The Subject to search the email
|
2016-09-26 16:44:58 -04:00
|
|
|
$subject = "[PM] " . $proName . " (" . $index . ") Case: " . $appNumber;
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle = new PmGoogleApi();
|
2015-11-09 11:01:11 -04:00
|
|
|
|
|
|
|
|
$pmGoogle->setUser($mail);
|
|
|
|
|
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle->setScope(PmGoogleApi::GMAIL_MODIFY);
|
2015-11-09 11:01:11 -04:00
|
|
|
$client = $pmGoogle->serviceClient();
|
|
|
|
|
|
|
|
|
|
$service = new Google_Service_Gmail($client);
|
2015-12-07 11:55:46 -04:00
|
|
|
$labelsIds = $this->getLabelsIds($service);
|
2015-11-09 11:01:11 -04:00
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
if ($actualLastIndex == 0) {
|
2015-12-07 11:55:46 -04:00
|
|
|
$labelsToRemove = $labelsIds['Draft'];
|
2015-11-09 11:01:11 -04:00
|
|
|
$labelsToSearch = "*-draft";
|
2015-12-07 11:55:46 -04:00
|
|
|
$labelsToAdd = $labelsIds['Participated'];
|
2016-01-06 11:07:56 -04:00
|
|
|
} else {
|
|
|
|
|
if (($actualLastIndex == -1) && ($unassigned == true)) { //Unassigned
|
|
|
|
|
$labelsToRemove = $labelsIds['Unassigned'];
|
|
|
|
|
$labelsToSearch = "*-unassigned";
|
|
|
|
|
$labelsToAdd = $labelsIds['Inbox'];
|
|
|
|
|
} else {
|
|
|
|
|
if ($actualLastIndex >= 1) {
|
|
|
|
|
$labelsToRemove = $labelsIds['Inbox'];
|
|
|
|
|
$labelsToSearch = "*-inbox";
|
|
|
|
|
$labelsToAdd = $labelsIds['Participated'];
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Searching the email in the user's mail
|
2016-01-06 11:07:56 -04:00
|
|
|
$q = "subject:('" . preg_quote($subject, '-') . "') label:('" . $labelsToSearch . "')";
|
2015-11-09 11:01:11 -04:00
|
|
|
$messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
|
|
|
|
|
|
2016-03-28 11:53:07 -04:00
|
|
|
//if there isn't any message at draft, and lasindex is zero, is a subprocess
|
|
|
|
|
//and we must search in inbox:
|
|
|
|
|
if ($actualLastIndex === 0 && count($messageList) ===0) {
|
|
|
|
|
$labelsToRemove = $labelsIds['Inbox'];
|
|
|
|
|
$labelsToSearch = "*-inbox";
|
|
|
|
|
$labelsToAdd = $labelsIds['Participated'];
|
|
|
|
|
$q = "subject:('" . preg_quote($subject, '-') . "') label:('" . $labelsToSearch . "')";
|
|
|
|
|
$messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
foreach ($messageList as $message) {
|
|
|
|
|
$messageId = $message->getId();
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
$modifyResult = $this->modifyMessage($service, $mail, $messageId, array($labelsToAdd),
|
|
|
|
|
array($labelsToRemove));
|
2015-11-09 11:01:11 -04:00
|
|
|
|
|
|
|
|
}
|
2015-12-20 18:56:46 -04:00
|
|
|
|
|
|
|
|
//in is unassigned we must remove the label to the orher users
|
|
|
|
|
if ($labelsToRemove === $labelsIds['Unassigned']) {
|
2016-01-06 11:07:56 -04:00
|
|
|
require_once(PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "model" . PATH_SEP . "TaskUser.php");
|
2015-12-20 18:56:46 -04:00
|
|
|
$oTaskUsers = new \TaskUser();
|
|
|
|
|
$taskUsers = $oTaskUsers->getAllUsersTask($tasUid);
|
2016-01-06 11:07:56 -04:00
|
|
|
foreach ($taskUsers as $user) {
|
2015-12-20 18:56:46 -04:00
|
|
|
$usrData = $oUsers->loadDetails($user['USR_UID']);
|
|
|
|
|
$nextMail = $usrData['USR_EMAIL'];
|
|
|
|
|
//this operation is just for the users that didn't make the case claim
|
|
|
|
|
if ($nextMail !== $mail) {
|
|
|
|
|
$this->changeLabelsOfUnassigned($appData[0], $nextMail);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
}
|
2015-12-20 18:56:46 -04:00
|
|
|
|
|
|
|
|
function changeLabelsOfUnassigned($application, $mail)
|
|
|
|
|
{
|
|
|
|
|
$appNumber = $application['APP_NUMBER'];
|
|
|
|
|
$index = $application['DEL_INDEX'];
|
|
|
|
|
$threadUsr = $application['USR_UID'];
|
|
|
|
|
$proName = $application['APP_PRO_TITLE'];
|
|
|
|
|
$threadStatus = $application['DEL_THREAD_STATUS'];
|
|
|
|
|
$appStatus = $application['APP_STATUS'];
|
|
|
|
|
$tasUid = $application['TAS_UID'];
|
|
|
|
|
|
|
|
|
|
//The Subject to search the email
|
2016-09-26 16:44:58 -04:00
|
|
|
$subject = "[PM] " . $proName . " (" . $index . ") Case: " . $appNumber;
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle = new PmGoogleApi();
|
2015-12-20 18:56:46 -04:00
|
|
|
$pmGoogle->setUser($mail);
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle->setScope(PmGoogleApi::GMAIL_MODIFY);
|
2015-12-20 18:56:46 -04:00
|
|
|
$client = $pmGoogle->serviceClient();
|
|
|
|
|
$service = new Google_Service_Gmail($client);
|
|
|
|
|
$labelsIds = $this->getLabelsIds($service);
|
|
|
|
|
$labelsToRemove = $labelsIds['Unassigned'];
|
|
|
|
|
$labelsToSearch = "*-unassigned";
|
|
|
|
|
$labelsToAdd = $labelsIds['Participated'];
|
|
|
|
|
|
|
|
|
|
//Searching the email in the user's mail
|
2016-01-06 11:07:56 -04:00
|
|
|
$q = "subject:('" . preg_quote($subject, '-') . "') label:('" . $labelsToSearch . "')";
|
2015-12-20 18:56:46 -04:00
|
|
|
$messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
|
|
|
|
|
|
|
|
|
|
foreach ($messageList as $message) {
|
|
|
|
|
$messageId = $message->getId();
|
2016-01-06 11:07:56 -04:00
|
|
|
$modifyResult = $this->modifyMessage($service, $mail, $messageId, array($labelsToAdd),
|
|
|
|
|
array($labelsToRemove));
|
2015-12-20 18:56:46 -04:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
/**
|
|
|
|
|
* Delete Label with given ID.
|
|
|
|
|
*
|
|
|
|
|
* @param Google_Service_Gmail $service Authorized Gmail API instance.
|
2016-01-06 11:07:56 -04:00
|
|
|
* @param string $userId User's email address. The special value 'me'
|
|
|
|
|
* can be used to indicate the authenticated user.
|
|
|
|
|
* @param string $labelId Id of Label to be updated.
|
2015-11-09 11:01:11 -04:00
|
|
|
*/
|
|
|
|
|
public function deleteLabel($service, $user, $labelId)
|
|
|
|
|
{
|
2015-12-20 18:56:46 -04:00
|
|
|
try {
|
|
|
|
|
$service->users_labels->delete($user, $labelId);
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
error_log(G::LoadTranslation("ID_PMGMAIL_GENERAL_ERROR") . $e->getMessage());
|
|
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
2015-12-20 18:56:46 -04:00
|
|
|
|
2015-11-09 11:01:11 -04:00
|
|
|
/**
|
|
|
|
|
* Delete PMGmail integration labels getting the list of labels in an email account.
|
2016-01-06 11:07:56 -04:00
|
|
|
*
|
2015-11-09 11:01:11 -04:00
|
|
|
* @param string $mail User mail adress.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function deletePMGmailLabels($mail)
|
|
|
|
|
{
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle = new PmGoogleApi();
|
2015-12-20 18:56:46 -04:00
|
|
|
|
|
|
|
|
$pmGoogle->setUser($mail);
|
|
|
|
|
|
2017-08-11 13:43:39 -04:00
|
|
|
$pmGoogle->setScope(PmGoogleApi::GMAIL_MODIFY);
|
2015-12-20 18:56:46 -04:00
|
|
|
$client = $pmGoogle->serviceClient();
|
|
|
|
|
|
|
|
|
|
$service = new Google_Service_Gmail($client);
|
|
|
|
|
$count = 0;
|
|
|
|
|
$listlabels = $this->listLabels($service);
|
|
|
|
|
foreach ($listlabels as $label) {
|
|
|
|
|
if ($label->getName() == '* Inbox' ||
|
|
|
|
|
$label->getName() == '* Participated' ||
|
|
|
|
|
$label->getName() == '* Unassigned' ||
|
|
|
|
|
$label->getName() == '* Draft' ||
|
|
|
|
|
$label->getName() == '* Inbox' ||
|
2016-01-04 16:38:52 -04:00
|
|
|
$label->getName() == '* --- ProcessMaker ---' ||
|
2015-12-20 18:56:46 -04:00
|
|
|
$label->getName() == '* Paused'
|
|
|
|
|
) {
|
|
|
|
|
$oresp = $this->deleteLabel($service, 'me', $label->getId());
|
|
|
|
|
$count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $count . ' labels successfully deleted.';
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|
|
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
public function addRelabelingToQueue($caseId, $index, $actualLastIndex, $unassigned = false)
|
2015-12-19 14:38:45 -04:00
|
|
|
{
|
|
|
|
|
$labelingQueue = new GmailRelabeling();
|
2015-12-20 13:14:18 -04:00
|
|
|
$labelingQueue->setCreateDate(date('Y-m-d H:i:s'));
|
2015-12-21 10:35:12 -04:00
|
|
|
$labelingQueue->setLabelingUid(G::generateUniqueID());
|
2015-12-19 14:38:45 -04:00
|
|
|
$labelingQueue->setAppUid($caseId);
|
|
|
|
|
$labelingQueue->setDelIndex($index);
|
|
|
|
|
$labelingQueue->setCurrentLastIndex($actualLastIndex);
|
|
|
|
|
$labelingQueue->setUnassigned(($unassigned === true) ? 1 : 0);
|
|
|
|
|
$labelingQueue->setStatus('pending');
|
|
|
|
|
$labelingQueue->save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function processPendingRelabelingInQueue()
|
|
|
|
|
{
|
2016-01-06 11:07:56 -04:00
|
|
|
$c = new \Criteria('workflow');
|
|
|
|
|
$c->add(\GmailRelabelingPeer::STATUS, 'pending');
|
2015-12-21 10:35:12 -04:00
|
|
|
$c->addAscendingOrderByColumn('CREATE_DATE');
|
2015-12-19 14:38:45 -04:00
|
|
|
$list = \GmailRelabelingPeer::doSelect($c);
|
2016-01-06 11:07:56 -04:00
|
|
|
foreach ($list as $task) {
|
2015-12-19 14:38:45 -04:00
|
|
|
try {
|
|
|
|
|
$oResponse = $this->setLabels($task->getAppUid(),
|
|
|
|
|
$task->getDelIndex(),
|
|
|
|
|
$task->getCurrentLastIndex(),
|
|
|
|
|
($task->getUnassigned() === 1) ? true : false
|
|
|
|
|
);
|
|
|
|
|
$task->setStatus('completed');
|
2016-01-06 11:07:56 -04:00
|
|
|
} catch (exception $e) {
|
2015-12-19 14:38:45 -04:00
|
|
|
$task->setMsgError($e->getMessage());
|
|
|
|
|
$task->setStatus('pending');
|
|
|
|
|
}
|
|
|
|
|
$task->save();
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-07 11:55:46 -04:00
|
|
|
|
2016-01-06 11:07:56 -04:00
|
|
|
private function getLabelsIds($service)
|
|
|
|
|
{
|
2015-12-07 11:55:46 -04:00
|
|
|
$result = array();
|
2015-12-19 14:38:45 -04:00
|
|
|
try {
|
|
|
|
|
$listlabels = $this->listLabels($service);
|
|
|
|
|
foreach ($listlabels as $label) {
|
2016-01-06 11:07:56 -04:00
|
|
|
$labId = $label->getId();
|
2015-12-19 14:38:45 -04:00
|
|
|
$labName = $label->getName();
|
2016-01-06 11:07:56 -04:00
|
|
|
switch ($labName) {
|
2015-12-19 14:38:45 -04:00
|
|
|
case "* Inbox":
|
|
|
|
|
$result['Inbox'] = $labId;
|
|
|
|
|
break;
|
|
|
|
|
case "* Participated":
|
|
|
|
|
$result['Participated'] = $labId;
|
|
|
|
|
break;
|
|
|
|
|
case "* Unassigned":
|
|
|
|
|
$result['Unassigned'] = $labId;
|
|
|
|
|
break;
|
|
|
|
|
case "* Draft":
|
|
|
|
|
$result['Draft'] = $labId;
|
|
|
|
|
break;
|
|
|
|
|
case "* Paused":
|
|
|
|
|
$result['Paused'] = $labId;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-12-07 11:55:46 -04:00
|
|
|
}
|
2016-01-06 11:07:56 -04:00
|
|
|
} catch (Exception $e) {
|
2015-12-19 14:38:45 -04:00
|
|
|
throw $e;
|
|
|
|
|
}
|
2015-12-07 11:55:46 -04:00
|
|
|
return $result;
|
|
|
|
|
}
|
2015-11-09 11:01:11 -04:00
|
|
|
}
|