Exemplo n.º 1
0
 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;
     }
 }
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
 /**
  * @desc Выводит форму редактирования/добавления пользовательских блогов, производит сохранение изменений
  * @param int $blogId Идентификатор редактируемого блога
  * @param string $template имя файла шаблона
  * @return string|array
  */
 public function editUserBlogs($blogId = false, $template = 'default')
 {
     if ($blogId === false) {
         $iTmp = getRequest('param0');
         if ($iTmp) {
             $blogId = $iTmp;
         }
     }
     if ($blogId != 'new') {
         $blogId = (int) $blogId;
     }
     $regedit = regedit::getInstance();
     $oHierarchy = umiHierarchy::getInstance();
     $hierarchy_type_id = umiHierarchyTypesCollection::getInstance()->getTypeByName("blogs20", "blog")->getId();
     $oUsers = cmsController::getInstance()->getModule('users');
     if (intval($blogId) > 0 || $blogId == 'new') {
         $aBlogInfo = getRequest('blog');
         $aBlogInfo = $aBlogInfo[$blogId];
         if ($aBlogInfo && isset($aBlogInfo['title']) && strlen($aBlogInfo['title'])) {
             $title = $aBlogInfo['title'];
             $description = isset($aBlogInfo['description']) ? $aBlogInfo['description'] : '';
             $friendlist = isset($aBlogInfo['friendlist']) ? array_map('intval', $aBlogInfo['friendlist']) : array();
             if ($blogId == 'new') {
                 $path = $regedit->getVal("//modules/blogs20/autocreate_path");
                 $parentId = intval($oHierarchy->getIdByPath($path));
                 $blogId = $oHierarchy->addElement($parentId, $hierarchy_type_id, $title, $title);
                 permissionsCollection::getInstance()->setDefaultPermissions($blogId);
                 $user = umiObjectsCollection::getInstance()->getObject($oUsers->user_id);
                 $groups = $user->getValue('groups');
                 $pCollection = permissionsCollection::getInstance();
                 foreach ($groups as $id) {
                     $pCollection->setElementPermissions($id, $blogId, 1);
                 }
                 $pCollection->setElementPermissions($oUsers->user_id, $blogId, 31);
             }
             if ($oBlog = $oHierarchy->getElement($blogId)) {
                 $oBlog->setIsActive();
                 $oBlog->setValue('title', $title);
                 $oBlog->setValue('description', $description);
                 $oBlog->setValue('friendlist', $friendlist);
                 $oBlog->commit();
             }
             $sRedirectURI = getRequest('redirect');
             if ($sRedirectURI) {
                 $this->redirect($sRedirectURI);
             }
         } else {
             //$this->redirect( getServer('HTTP_REFERER') );
         }
         if ($blogId != 'new') {
             $result = array($blogId);
         } else {
             $result = array();
         }
     } else {
         $sel = new umiSelection();
         $sel->addElementType($hierarchy_type_id);
         $sel->setOrderByName(true);
         $sel->addPermissions();
         $sel->setPermissionsLevel(2);
         $result = umiSelectionsParser::runSelection($sel);
     }
     list($templateBlock, $templateLine, $templateNew) = self::loadTemplates('blogs20/' . $template, 'blod_edit_block', 'blog_edit_line', 'blog_new_line');
     $oCollection = umiObjectsCollection::getInstance();
     $userTypeId = umiObjectTypesCollection::getInstance()->getBaseType('users', 'user');
     $aUsers = $oCollection->getGuidedItems($userTypeId);
     $aLines = array();
     $ownerBlogs = 0;
     foreach ($result as $blogId) {
         $oBlog = $oHierarchy->getElement($blogId);
         if (!$oBlog) {
             continue;
         }
         $aLineParam = array();
         $aLineParam['bid'] = $blogId;
         $aLineParam['title'] = $oBlog->getValue('title');
         $aLineParam['description'] = $oBlog->getValue('description');
         $aLineParam['path'] = $oHierarchy->getPathById($blogId);
         $aFriendList = $oBlog->getValue('friendlist');
         $sOptions = '';
         foreach ($aUsers as $userId => $userName) {
             $sOptions .= '<option value="' . $userId . '" ' . (in_array($userId, $aFriendList) ? 'selected' : '') . '>' . $userName . '</option>';
         }
         $aLineParam['friends'] = $sOptions;
         $aLineParam['current_page'] = getServer('REQUEST_URI');
         $aLines[] = self::parseTemplate($templateLine, $aLineParam);
         if ($oBlog->getObject()->getOwnerId() == $oUsers->user_id) {
             $ownerBlogs++;
         }
     }
     if ($ownerBlogs < $regedit->getVal("//modules/blogs20/blogs_per_user")) {
         $aLineParam = array('bid' => 'new', 'title' => '', 'description' => '');
         $sOptions = '';
         foreach ($aUsers as $userId => $userName) {
             $sOptions .= '<option value="' . $userId . '">' . $userName . '</option>';
         }
         $aLineParam['friends'] = $sOptions;
         $aLineParam['current_page'] = getServer('REQUEST_URI');
         $aLines[] = self::parseTemplate($templateNew, $aLineParam);
     }
     $aBlock = array();
     $aBlock['subnodes:blogs'] = $aBlock['void:lines'] = $aLines;
     return self::parseTemplate($templateBlock, $aBlock);
 }