예제 #1
0
 /**
  * Function to get contents of this task
  * @param <Object> $entity
  * @return <Array> contents
  */
 public function getContents($entity, $entityCache = false)
 {
     if (!$this->contents) {
         global $adb, $current_user;
         $taskContents = array();
         $entityId = $entity->getId();
         $utils = new VTWorkflowUtils();
         $adminUser = $utils->adminUser();
         if (!$entityCache) {
             $entityCache = new VTEntityCache($adminUser);
         }
         $fromUserId = Users::getActiveAdminId();
         $entityOwnerId = $entity->get('assigned_user_id');
         if ($entityOwnerId) {
             list($moduleId, $fromUserId) = explode('x', $entityOwnerId);
         }
         $ownerEntity = $entityCache->forId($entityOwnerId);
         if ($ownerEntity->getModuleName() === 'Groups') {
             list($moduleId, $recordId) = vtws_getIdComponents($entityId);
             $fromUserId = Vtiger_Util_Helper::getCreator($recordId);
         }
         if ($this->fromEmail && !($ownerEntity->getModuleName() === 'Groups' && strpos($this->fromEmail, 'assigned_user_id : (Users) ') !== false)) {
             $et = new VTEmailRecipientsTemplate($this->fromEmail);
             $fromEmailDetails = $et->render($entityCache, $entityId);
             $con1 = strpos($fromEmailDetails, '&lt;');
             $con2 = strpos($fromEmailDetails, '&gt;');
             if ($con1 && $con2) {
                 list($fromName, $fromEmail) = explode('&lt;', $fromEmailDetails);
                 list($fromEmail, $rest) = explode('&gt;', $fromEmail);
             } else {
                 $fromName = "";
                 $fromEmail = $fromEmailDetails;
             }
         } else {
             $userObj = CRMEntity::getInstance('Users');
             $userObj->retrieveCurrentUserInfoFromFile($fromUserId);
             if ($userObj) {
                 $fromEmail = $userObj->email1;
                 $fromName = $userObj->user_name;
             } else {
                 $result = $adb->pquery('SELECT user_name, email1 FROM vtiger_users WHERE id = ?', array($fromUserId));
                 $fromEmail = $adb->query_result($result, 0, 'email1');
                 $fromName = $adb->query_result($result, 0, 'user_name');
             }
         }
         if (!$fromEmail) {
             $utils->revertUser();
             return false;
         }
         $taskContents['fromEmail'] = $fromEmail;
         $taskContents['fromName'] = $fromName;
         if ($entity->getModuleName() === 'Events') {
             $contactId = $entity->get('contact_id');
             if ($contactId) {
                 $contactIds = '';
                 list($wsId, $recordId) = explode('x', $entityId);
                 $webserviceObject = VtigerWebserviceObject::fromName($adb, 'Contacts');
                 $result = $adb->pquery('SELECT contactid FROM vtiger_cntactivityrel WHERE activityid = ?', array($recordId));
                 $numOfRows = $adb->num_rows($result);
                 for ($i = 0; $i < $numOfRows; $i++) {
                     $contactIds .= vtws_getId($webserviceObject->getEntityId(), $adb->query_result($result, $i, 'contactid')) . ',';
                 }
             }
             $entity->set('contact_id', trim($contactIds, ','));
             $entityCache->cache[$entityId] = $entity;
         }
         $et = new VTEmailRecipientsTemplate($this->recepient);
         $toEmail = $et->render($entityCache, $entityId);
         $ecct = new VTEmailRecipientsTemplate($this->emailcc);
         $ccEmail = $ecct->render($entityCache, $entityId);
         $ebcct = new VTEmailRecipientsTemplate($this->emailbcc);
         $bccEmail = $ebcct->render($entityCache, $entityId);
         if (strlen(trim($toEmail, " \t\n,")) == 0 && strlen(trim($ccEmail, " \t\n,")) == 0 && strlen(trim($bccEmail, " \t\n,")) == 0) {
             $utils->revertUser();
             return false;
         }
         $taskContents['toEmail'] = $toEmail;
         $taskContents['ccEmail'] = $ccEmail;
         $taskContents['bccEmail'] = $bccEmail;
         $st = new VTSimpleTemplate($this->subject);
         $taskContents['subject'] = $st->render($entityCache, $entityId);
         $ct = new VTSimpleTemplate($this->content);
         $taskContents['content'] = $ct->render($entityCache, $entityId);
         $this->contents = $taskContents;
         $utils->revertUser();
     }
     if (is_array($this->contents)) {
         $this->contents = Zend_Json::encode($this->contents);
     }
     return $this->contents;
 }
예제 #2
0
 /**
  * generation of a position, logoot algorithm
  * @param <Object> $start is the previous logootPosition
  * @param <Object> $end is the next logootPosition
  * @param <Integer> $N number of positions generated (should be 1 in our case)
  * @param <Object> $sid session id
  * @return <Object> a logootPosition between $start and $end
  */
 private function getLogootPosition($start, $end, $N, $sid)
 {
     $result = array();
     $Id_Max = LogootId::IdMax();
     $Id_Min = LogootId::IdMin();
     $i = 0;
     $pos = array();
     $currentPosition = new LogootPosition($pos);
     // voir constructeur
     $inf = new Math_BigInteger("0");
     $sup = new Math_BigInteger("0");
     $isInf = false;
     while (true) {
         $inf = new Math_BigInteger($start->get($i)->getInt());
         if ($isInf == true) {
             $sup = new Math_BigInteger(INT_MAX);
         } else {
             $sup = new Math_BigInteger($end->get($i)->getInt());
         }
         $tmpVal = $sup->subtract($inf);
         $tmpVal1 = $tmpVal->subtract(new Math_BigInteger("1"));
         if ($tmpVal1->compare($N) > 0) {
             //				inf = start.get(i).getInteger();
             //				sup = end.get(i).getInteger();
             break;
         }
         $currentPosition->add($start->get($i));
         $i++;
         if ($i == $start->size()) {
             $start->add($Id_Min);
         }
         if ($i == $end->size()) {
             $end->add($Id_Max);
         }
         if ($inf->compare($sup) < 0) {
             $isInf = true;
         }
     }
     $binf = $inf->add(new Math_BigInteger("1"));
     $bsup = $sup->subtract(new Math_BigInteger("1"));
     $slot = $bsup->subtract($binf);
     $stepTmp = $slot->divide($N);
     $step = $stepTmp[0];
     // quotient, [1] is the remainder
     $old = clone $currentPosition;
     if ($step->compare(new Math_BigInteger(INT_MAX)) > 0) {
         $lstep = new Math_BigInteger(INT_MAX);
         $r = clone $currentPosition;
         $tmpVal2 = $inf->random($inf, $sup);
         $r->set($i, $tmpVal2->toString(), $sid);
         $result[] = $r;
         // result est une arraylist<Position>
         return $result;
     } else {
         $lstep = $step;
     }
     if ($lstep->compare(new Math_BigInteger("0")) == 0) {
         $lstep = new Math_BigInteger("1");
     }
     $p = clone $currentPosition;
     $p->set($i, $inf->toString(), $sid);
     $tmpVal3 = (int) $N->toString();
     for ($j = 0; $j < $tmpVal3; $j++) {
         $r = clone $p;
         if (!($lstep->compare(new Math_BigInteger("1")) == 0)) {
             $tmpVal4 = new Math_BigInteger($p->get($i)->getInt());
             $tmpVal5 = $tmpVal4->add($lstep);
             // max
             $tmpVal6 = new Math_BigInteger($p->get($i)->getInt());
             // min
             $add = $tmpVal6->random($tmpVal6, $tmpVal5);
             $r->set($i, $add->toString(), $sid);
         } else {
             $r->add1($i, new Math_BigInteger("1"), $sid);
         }
         $result[] = clone $r;
         // voir
         $old = clone $r;
         $tmpVal7 = new Math_BigInteger($p->get($i)->getInt());
         $tmpVal7 = $tmpVal7->add($lstep);
         $p->set($i, $tmpVal7->toString(), $sid);
     }
     return $result;
 }