adminUser(); $ws_id = $entity->getId(); $entityCache = new VTEntityCache($admin); $et = new VTSimpleTemplate($this->sms_recepient); $recepient = $et->render($entityCache, $ws_id); $recepients = explode(',',$recepient); $relatedIds = $this->getRelatedIdsFromTemplate($this->sms_recepient, $entityCache, $ws_id); $relatedIds = explode(',', $relatedIds); $relatedIdsArray = array(); foreach ($relatedIds as $entityId) { if (!empty($entityId)) { list($moduleId, $recordId) = vtws_getIdComponents($entityId); if (!empty($recordId)) { $relatedIdsArray[] = $recordId; } } } $ct = new VTSimpleTemplate($this->content); $content = $ct->render($entityCache, $ws_id); $relatedCRMid = substr($ws_id, stripos($ws_id, 'x')+1); $relatedIdsArray[] = $relatedCRMid; $relatedModule = $entity->getModuleName(); /** Pickup only non-empty numbers */ $tonumbers = array(); foreach($recepients as $tonumber) { if(!empty($tonumber)) $tonumbers[] = $tonumber; } //As content could be sent with HTML tags. $content = strip_tags(br2nl($content)); //SalesPlatform.ru begin $this->smsNotifierId = SMSNotifier::sendsms($content, $tonumbers, $current_user->id, $relatedIdsArray, $relatedModule, $this->sms_recepient); //$this->smsNotifierId = SMSNotifier::sendsms($content, $tonumbers, $current_user->id, $relatedIdsArray); //SalesPlatform.ru end } } public function getRelatedIdsFromTemplate($template, $entityCache, $entityId) { $this->template = $template; $this->cache = $entityCache; $this->parent = $this->cache->forId($entityId); return preg_replace_callback('/\\$(\w+|\((\w+) : \(([_\w]+)\) (\w+)\))/', array($this,"matchHandler"), $this->template); } public function matchHandler($match) { preg_match('/\((\w+) : \(([_\w]+)\) (\w+)\)/', $match[1], $matches); // If parent is empty then we can't do any thing here if(!empty($this->parent)){ if(count($matches) != 0){ list($full, $referenceField, $referenceModule, $fieldname) = $matches; $referenceId = $this->parent->get($referenceField); if($referenceModule==="Users" || $referenceId==null){ $result =""; } else { $result = $referenceId; } } } return $result; } } ?>