Exemplo n.º 1
0
 /**
  * Get Application by app_uid
  * 
  * @param string $app_uid {@from path}
  *
  *
  * @url GET /application/:app_uid
  *
  */
 public function doGetApplication($app_uid)
 {
     try {
         $Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
         $response = $Pmgmail->getDraftApp($app_uid);
         return $response;
     } catch (\Exception $e) {
         throw new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage());
     }
 }
Exemplo n.º 2
0
 public function setLabels($caseId, $index, $actualLastIndex, $unassigned = false)
 {
     //First getting the actual thread data
     $Pmgmail = new \ProcessMaker\BusinessModel\Pmgmail();
     $appData = $Pmgmail->getDraftApp($caseId, $index);
     foreach ($appData as $application) {
         $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'];
     }
     if ($threadStatus == 'CLOSED' || $unassigned == true) {
         //Getting the privious User email
         $oUsers = new \Users();
         $usrData = $oUsers->loadDetails($threadUsr);
         $mail = $usrData['USR_EMAIL'];
         //The Subject to search the email
         $subject = "[PM] " . $proName . " Case: " . $appNumber;
         require_once PATH_TRUNK . 'vendor' . PATH_SEP . 'google' . PATH_SEP . 'apiclient' . PATH_SEP . 'src' . PATH_SEP . 'Google' . PATH_SEP . 'autoload.php';
         require_once PATH_HOME . "engine" . PATH_SEP . "classes" . PATH_SEP . "class.pmGoogleApi.php";
         $pmGoogle = new PMGoogleApi();
         $pmGoogle->setUser($mail);
         $pmGoogle->setScope('https://www.googleapis.com/auth/gmail.modify');
         $client = $pmGoogle->serviceClient();
         $service = new Google_Service_Gmail($client);
         $labelsIds = $this->getLabelsIds($service);
         if ($actualLastIndex == 0) {
             $labelsToRemove = $labelsIds['Draft'];
             $labelsToSearch = "*-draft";
             $labelsToAdd = $labelsIds['Participated'];
         } 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'];
                 }
             }
         }
         //Searching the email in the user's mail
         $q = "subject:('" . preg_quote($subject, '-') . "') label:('" . $labelsToSearch . "')";
         $messageList = $this->listMessages($service, $mail, $q, $labelsToRemove);
         foreach ($messageList as $message) {
             $messageId = $message->getId();
             $modifyResult = $this->modifyMessage($service, $mail, $messageId, array($labelsToAdd), array($labelsToRemove));
         }
     }
 }