public function cronSendNotification($oEvent) { $object_type = umiObjectTypesCollection::getInstance()->getTypeByGUID('root-pages-type'); $field_id = $object_type->getFieldId("notification_date"); $field_id_expiration = $object_type->getFieldId("expiration_date"); $sel = new umiSelection(); $sel->addPropertyFilterLess($field_id, time()); $sel->addPropertyFilterMore($field_id_expiration, time()); $sel->addPropertyFilterNotEqual($field_id, 0); $sel->addActiveFilter(true); $sel->forceHierarchyTable(true); $result = umiSelectionsParser::runSelection($sel); $regedit = regedit::getInstance(); $lastCheckDate = (int) $regedit->getVal("//modules/content/last-notification-date"); foreach ($result as $key => $page_id) { $ePage = umiHierarchy::getInstance()->getElement($page_id, true, true); if ($ePage instanceof umiHierarchyElement == false) { continue; } $notificationDate = $ePage->getValue('notification_date')->getDateTimeStamp(); if ($lastCheckDate && $lastCheckDate - 3600 * 24 < time() && $lastCheckDate > $notificationDate) { continue; } $oPage = $ePage->getObject(); $oPage->setValue("publish_status", $this->getPageStatusIdByStatusSid("page_status_preunpublish")); if (!($publishComments = $ePage->getValue("publish_comments"))) { $publishComments = "Отсутствуют."; } $user_id = $oPage->getOwnerId(); $oUser = umiObjectsCollection::getInstance()->getObject($user_id); if ($oUser instanceof umiObject && ($user_email = $oUser->getValue("e-mail"))) { //Составляем и посылаем сообщение пользователю $mail_message = new umiMail(); $from = $regedit->getVal("//settings/email_from"); $mail_message->setFrom($from); $mail_message->setPriorityLevel("high"); $mail_message->setSubject(getLabel('label-notification-mail-header')); list($body) = def_module::loadTemplatesForMail("mail/notify", "body"); $block['notify_header'] = getLabel('label-notification-mail-header'); $block['page_header'] = $ePage->getName(); $block['publish_comments'] = $publishComments; $domain = domainsCollection::getInstance()->getDomain($ePage->getDomainId()); $page_host = "http://" . $domain->getHost() . umiHierarchy::getInstance()->getPathById($page_id); $block['page_link'] = $page_host; $mail_html = def_module::parseTemplateForMail($body, $block, $page_id); $mail_message->addRecipient($user_email); $mail_message->setContent($mail_html); $mail_message->commit(); $mail_message->send(); } $oPage->commit(); $ePage->commit(); } $regedit->setVal("//modules/content/last-notification-date", time()); }
/** * Применение кастомной логики к объекту umiSelection * * @param umiSelection $selection Объект umiSelection */ public function applyCustomCountFilters(&$selection) { $arCustomFilters = $this->customLogic->filters(); $oType = umiObjectTypesCollection::getInstance()->getType($this->objectsTypeId); if (!$oType) { return; } foreach ($arCustomFilters as $arCustomFilter) { $iFieldId = $oType->getFieldId($arCustomFilter[0]); $sOperator = $arCustomFilter[1]; $value = $arCustomFilter[2]; switch ($sOperator) { case "eq": $selection->addPropertyFilterEqual($iFieldId, $value); break; case "noteq": $selection->addPropertyFilterNotEqual($iFieldId, $value); break; case "null": $selection->addPropertyFilterIsNull($iFieldId); break; case "notnull": $selection->addPropertyFilterIsNotNull($iFieldId); break; case "gt": $selection->addPropertyFilterMore($iFieldId, $value); break; case "lt": $selection->addPropertyFilterLess($iFieldId, $value); break; case "like": $selection->addPropertyFilterLike($iFieldId, $value); break; } } }