public function cronUnpublishPage($oEvent) { $object_type = umiObjectTypesCollection::getInstance()->getTypeByGUID('root-pages-type'); $field_id = $object_type->getFieldId("expiration_date"); $sel = new umiSelection(); $sel->addPropertyFilterLess($field_id, time()); $sel->addPropertyFilterNotEqual($field_id, 0); $sel->addActiveFilter(true); $sel->forceHierarchyTable(true); $result = umiSelectionsParser::runSelection($sel); $res = array(); foreach ($result as $key => $page_id) { $ePage = umiHierarchy::getInstance()->getElement($page_id, true); $ePage->setIsActive(false); $pageObject = $ePage->getObject(); $pageObject->setValue("publish_status", $this->getPageStatusIdByStatusSid("page_status_unpublish")); $pageObject->commit(); $ePage->commit(); if (!($publishComments = $ePage->getValue("publish_comments"))) { $publishComments = "Отсутствуют."; } $user_id = $ePage->getObject()->getOwnerId(); $oUser = umiObjectsCollection::getInstance()->getObject($user_id); if ($oUser instanceof umiObject && ($user_email = $oUser->getValue("e-mail"))) { //Составляем и посылаем сообщение пользователю $mail_message = new umiMail(); $from = regedit::getInstance()->getVal("//settings/email_from"); $mail_message->setFrom($from); $mail_message->setPriorityLevel("high"); $mail_message->setSubject(getLabel('label-notification-expired-mail-header')); list($body) = def_module::loadTemplatesForMail("mail/expired", "body"); $block['notify_header'] = getLabel('label-notification-expired-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(); } } }
/** * Применение кастомной логики к объекту 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; } } }
/** * @desc Выводит список постов, содержащих указаный тег * @param string $tag Тег * @param string $template Имя файла шаблона для вывода * @return string|array */ public function postsByTag($tag = false, $template = 'default', $limit = false) { list($sTemplateBlock, $sTemplateLine) = self::loadTemplates('blogs20/' . $template, 'posts_list_block', 'posts_list_line'); $page = (int) getRequest('p'); $oBlog = null; $oHierarchy = umiHierarchy::getInstance(); if ($tag === false) { $tag = ($tmp = getRequest('param0')) ? $tmp : $tag; } $sel = new umiSelection(); $hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("blogs20", "post")->getId(); $sel->addElementType($hierarchy_type_id); $typesCollection = umiObjectTypesCollection::getInstance(); $typeId = $typesCollection->getTypeByHierarchyTypeId($hierarchy_type_id); $postType = $typesCollection->getType($typeId); $sel->addPropertyFilterNotEqual($postType->getFieldId('only_for_friends'), 1); $sel->addPropertyFilterEqual($postType->getFieldId('tags'), $tag); $sel->setOrderByProperty($postType->getFieldId('publish_time'), false); $sel->addLimit($limit ? $limit : $this->posts_per_page, $page); $result = umiSelectionsParser::runSelection($sel); $total = umiSelectionsParser::runSelectionCounts($sel); $aLines = array(); foreach ($result as $iPostId) { $oPost = $oHierarchy->getElement($iPostId); if (!$oPost) { continue; } $oBlog = $oHierarchy->getElement($oPost->getRel()); $sPostLink = $oHierarchy->getPathById($iPostId, true); $sBlogLink = $oHierarchy->getPathById($oBlog->getId(), true); $aLineParam = array(); $aLineParam['attribute:id'] = $iPostId; $aLineParam['attribute:author_id'] = $oPost->getObject()->getOwnerId(); $aLineParam['name'] = $oPost->getName(); $aLineParam['post_link'] = $sPostLink; $aLineParam['blog_link'] = $sBlogLink; $aLineParam['bid'] = $oBlog->getId(); $aLineParam['blog_title'] = $oBlog->getValue('title'); $aLineParam['blog_name'] = $oBlog->getName(); $aLineParam['title'] = $oPost->getValue('title'); $aLineParam['cut'] = $this->prepareCut($oPost->getValue('content'), $sPostLink, $template); $aLineParam['subnodes:tags'] = $this->prepareTags($oPost->getValue('tags')); $aLineParam['comments_count'] = $oHierarchy->getChildsCount($iPostId, false); $aLineParam['publish_time'] = ($d = $oPost->getValue('publish_time')) ? $d->getFormattedDate('U') : ""; $aLines[] = self::parseTemplate($sTemplateLine, $aLineParam, $iPostId); $this->pushEditable("blogs20", "post", $iPostId); } $aBlockParam = array(); $aBlockParam['void:lines'] = $aBlockParam['subnodes:items'] = $aLines; $aBlockParam['per_page'] = $limit ? $limit : $this->posts_per_page; $aBlockParam['total'] = $total; return self::parseTemplate($sTemplateBlock, $aBlockParam); }