Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public function fastInsert($placeName)
 {
     $sel = new umiSelection();
     // type filter
     $sel->setObjectTypeFilter();
     $hierarchyTypeId = umiHierarchyTypesCollection::getInstance()->getTypeByName("banners", "banner")->getId();
     $objectTypeId = umiObjectTypesCollection::getInstance()->getTypeByHierarchyTypeId($hierarchyTypeId);
     $objectType = umiObjectTypesCollection::getInstance()->getType($objectTypeId);
     if (!$objectType) {
         return false;
     }
     $bannerTypes = umiObjectTypesCollection::getInstance()->getTypesByHierarchyTypeId($hierarchyTypeId);
     $sel->addObjectType(array_keys($bannerTypes));
     $sel->addPropertyFilterEqual($objectType->getFieldId('place'), $this->getPlaceId($placeName));
     $sel->setOrderByRand();
     $result = umiSelectionsParser::runSelection($sel);
     $objects = umiObjectsCollection::getInstance();
     foreach ($result as $bannerId) {
         $banner = $objects->getObject($bannerId);
         if (!$banner->is_active) {
             continue;
         }
         if ($this->checkIfValidParent($banner->view_pages, $banner->not_view_pages) == false) {
             continue;
         }
         if ($renderedBanner = $this->renderBanner($bannerId)) {
             return $renderedBanner;
         }
     }
 }