public function topic($template = "default", $per_page = false, $ignore_context = false) { if (!$template) { $template = "default"; } list($template_block, $template_line) = self::loadTemplates("forum/" . $template, "messages_block", "messages_block_line"); $element_id = cmsController::getInstance()->getCurrentElementId(); $element = umiHierarchy::getInstance()->getElement($element_id); $unsubscribe_user_id = (string) getRequest('unsubscribe'); if ($unsubscribe_user_id) { $unsubscribe_user_id = base64_decode($unsubscribe_user_id); $unsubscribe_user = umiObjectsCollection::getInstance()->getObject($unsubscribe_user_id); if ($unsubscribe_user instanceof umiObject) { $topic_id = cmsController::getInstance()->getCurrentElementId(); $subscribed_pages = $unsubscribe_user->getValue("subscribed_pages"); $tmp = array(); foreach ($subscribed_pages as $page) { if ($page->getId() != $topic_id) { $tmp[] = $page; } } $subscribed_pages = $tmp; unset($tmp); $unsubscribe_user->setValue("subscribed_pages", $subscribed_pages); $unsubscribe_user->commit(); } } $this->pushEditable("forum", "topic", $element_id); $per_page = $per_page ? $per_page : $this->per_page; $curr_page = getRequest('p'); $sel = new umiSelection(); $sel->setElementTypeFilter(); $topic_hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("forum", "message")->getId(); $sel->addElementType($topic_hierarchy_type_id); if (!$ignore_context) { $sel->setHierarchyFilter(); $sel->addHierarchyFilter($element_id); } else { $sel->forceHierarchyTable(); } $object_type_id = umiObjectTypesCollection::getInstance()->getBaseType("forum", "message"); $object_type = umiObjectTypesCollection::getInstance()->getType($object_type_id); $publish_time_field_id = $object_type->getFieldId('publish_time'); if (getRequest('order_property')) { // == 'order by' requirements processing start $b_asc = false; $s_order_direction = getRequest('order_direction'); if (strtoupper($s_order_direction) === 'ASC') { $b_asc = true; } $s_order_property = getRequest('order_property'); if (!$s_order_property) { $s_order_property = 'publish_time'; } switch ($s_order_property) { /* Дата публикации - publish_time Автор - author_id sys::ord sys::rand sys::name sys::objectid */ case 'sys::ord': $sel->setOrderByOrd(); break; case 'sys::rand': $sel->setOrderByRand(); break; case 'sys::name': $sel->setOrderByName($b_asc); break; case 'sys::objectid': $sel->setOrderByObjectId($b_asc); break; default: $publish_time_field_id = $object_type->getFieldId($s_order_property); if (!$publish_time_field_id) { $publish_time_field_id = $object_type->getFieldId('publish_time'); } $sel->setOrderByProperty($publish_time_field_id, $b_asc); break; } // == 'order by' requirements processing fin } else { $sel->setOrderFilter(); $sel->setOrderByProperty($publish_time_field_id, true); } $sel->setPermissionsFilter(); $sel->addPermissions(); //$total = $element->getValue("messages_count"); //if($total === false) $total = umiSelectionsParser::runSelectionCounts($sel); $sel->setLimitFilter(); $sel->addLimit($per_page, $curr_page); $result = umiSelectionsParser::runSelection($sel); unset($sel); $lines = array(); $sz = sizeof($result); for ($i = 0; $i < $sz; $i++) { $message_element_id = $result[$i]; $message_element = umiHierarchy::getInstance()->getElement($message_element_id); if (!$message_element) { $total--; continue; } $line_arr = array(); $line_arr['attribute:id'] = $message_element_id; $line_arr['attribute:name'] = $message_element->getName(); $line_arr['attribute:num'] = $per_page * $curr_page + $i + 1; $line_arr['attribute:author_id'] = $author_id = $message_element->getValue("author_id"); $line_arr['xlink:href'] = "upage://" . $message_element_id; $line_arr['xlink:author-href'] = "udata://users/viewAuthor/" . $author_id; $message = $message_element->getValue("message"); $line_arr['node:message'] = self::formatMessage($message); $lines[] = self::parseTemplate($template_line, $line_arr, $message_element_id); $this->pushEditable("forum", "message", $message_element_id); umiHierarchy::getInstance()->unloadElement($element_id); } $block_arr = array(); $block_arr['attribute:id'] = $element_id; $block_arr['subnodes:lines'] = $lines; $block_arr['total'] = $total; $block_arr['per_page'] = $per_page; return self::parseTemplate($template_block, $block_arr, $element_id); }
public function category($template = "default", $element_path = false, $limit = false, $ignore_paging = false, $order = true) { if(!$template) $template = "default"; list($template_block, $template_block_empty, $template_line) = def_module::loadTemplates("faq/".$template, "questions_block", "questions_block_empty", "questions_block_line"); $category_id = $this->analyzeRequiredPath($element_path); $hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("faq", "question")->getId(); $per_page = ($limit) ? $limit : $this->per_page; $curr_page = (int) getRequest('p'); if($ignore_paging) $curr_page = 0; $sel = new umiSelection; $sel->addElementType($hierarchy_type_id); $sel->addHierarchyFilter($category_id); $sel->addLimit($per_page, $curr_page); $sel->addPermissions(); $sel->setOrderByOrd((bool) $order); $result = umiSelectionsParser::runSelection($sel); $total = umiSelectionsParser::runSelectionCounts($sel); if(($sz = sizeof($result)) > 0) { $block_arr = Array(); $block_arr['total'] = $total; $block_arr['per_page'] = $per_page; $lines = Array(); for($i = 0; $i < $sz; $i++) { if ($i < $limit || $limit === false) { $element_id = $result[$i]; $element = umiHierarchy::getInstance()->getElement($element_id); if(!$element) continue; $line_arr = Array(); $line_arr['attribute:id'] = $element_id; $line_arr['attribute:name'] = $line_arr['void:text'] = $element->getName(); $line_arr['void:alt_name'] = $element->getAltName(); $line_arr['attribute:link'] = umiHierarchy::getInstance()->getPathById($element_id); $line_arr['xlink:href'] = "upage://" . $element_id; $line_arr['question'] = nl2br($element->getValue("question")); $line_arr['answer'] = ($answer = $element->getValue("answer")) ? nl2br($answer) : nl2br($element->getValue("content")); $this->pushEditable("faq", "question", $element_id); $lines []= self::parseTemplate($template_line, $line_arr, $element_id); } } $block_arr['subnodes:items'] = $block_arr['void:lines'] = $lines; return self::parseTemplate($template_block, $block_arr, $category_id); } else { return $template_block_empty; } }
public function autoDetectOrders(umiSelection $sel, $object_type_id) { if (array_key_exists("order_filter", $_REQUEST)) { $sel->setOrderFilter(); $type = umiObjectTypesCollection::getInstance()->getType($object_type_id); $order_filter = getRequest('order_filter'); foreach ($order_filter as $field_name => $direction) { if ($direction === "asc") { $direction = true; } if ($direction === "desc") { $direction = false; } if ($field_name == "name") { $sel->setOrderByName((bool) $direction); continue; } if ($field_name == "ord") { $sel->setOrderByOrd((bool) $direction); continue; } if ($type) { if ($field_id = $type->getFieldId($field_name)) { $sel->setOrderByProperty($field_id, (bool) $direction); } else { continue; } } } } else { return false; } }
/** * @desc Выводит список блогов * @param Int $blogsCount Количество блогов для вывода (если отличается от умолчания) * @param Int|String $sortType Вид сортировки результата (по-алфавиту, случайно и т.д.) * @param Int $domainId Идентификатор домена * @param String $template Имя файла шаблона для вывода * @return string|array */ public function blogsList($blogsCount = false, $sortType = false, $domainId = false, $template = 'default') { list($sTemplateBlock, $sTemplateLine) = self::loadTemplates('blogs20/' . $template, 'blogs_list_block', 'blogs_list_line'); $page = (int) getRequest('p'); $sel = new umiSelection(); $hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("blogs20", "blog")->getId(); $sel->addElementType($hierarchy_type_id); $sel->addPermissions(); if ($blogsCount) { $sel->addLimit($blogsCount, 0); } else { $sel->addLimit($this->blogs_per_page, $page); } switch ($sortType) { case 1: case 'name': $sel->setOrderByName(true); break; case 2: case 'ord': $sel->setOrderByOrd(true); break; case 4: case 'rand': $sel->setOrderByRand(); break; } $result = umiSelectionsParser::runSelection($sel); $total = umiSelectionsParser::runSelectionCounts($sel); $oHierarchy = umiHierarchy::getInstance(); $result = array_unique($result); $aLines = array(); foreach ($result as $iBlogId) { $oBlog = $oHierarchy->getElement($iBlogId); $aLineParam = array(); $aLineParam['attribute:bid'] = $iBlogId; $aLineParam['attribute:title'] = $oBlog->getValue('title'); $aLineParam['attribute:link'] = $oHierarchy->getPathById($iBlogId); $aLineParam['node:name'] = $oBlog->getName(); $aLines[] = self::parseTemplate($sTemplateLine, $aLineParam, $iBlogId); $this->pushEditable("blogs20", "blog", $iBlogId); } $aBlockParam = array(); $aBlockParam['subnodes:items'] = $aBlockParam['void:lines'] = $aLines; $aBlockParam['per_page'] = $blogsCount ? $blogsCount : $this->blogs_per_page; $aBlockParam['total'] = $total; return self::parseTemplate($sTemplateBlock, $aBlockParam); }