예제 #1
0
 /**
  * @param $params
  *  {
  *  "page":1,
  *  "moduleid": 86
  *  }
  *
  * @return RokCommon_Ajax_Result
  */
 public function getPage($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $html = '';
         $container = RokCommon_Service::getContainer();
         /** @var $platformHelper RokSprocket_PlatformHelper */
         $platformHelper = $container->roksprocket_platformhelper;
         $module_params = $platformHelper->getModuleParameters($params->moduleid);
         // add the layout classpath
         $layout_lib_path = $container['roksprocket.layouts.mosaic.library.paths'];
         foreach ($layout_lib_path as $lib_path) {
             RokCommon_ClassLoader::addPath($lib_path);
         }
         $container = RokCommon_Service::getContainer();
         /** @var $platformHelper RokSprocket_PlatformHelper */
         $platformHelper = $container->roksprocket_platformhelper;
         $items = $platformHelper->getFromCache(array('RokSprocket', 'getItemsWithParams'), array($params->moduleid, $module_params, true, false, $params->displayed), $module_params, $params->moduleid);
         /** @var $layout RokSprocket_Layout_Mosaic */
         $layout = $container->getService('roksprocket.layout.mosaic');
         $layout->initialize($items, $module_params);
         $items = $layout->getItems();
         if (isset($params->filter) && $params->filter && $params->filter != 'all') {
             $filtered = new RokSprocket_ItemCollection();
             foreach ($items as $item) {
                 if ($this->in_arrayi($params->filter, $item->getTags())) {
                     $filtered->addItem($item);
                 }
             }
             $items = $filtered;
         }
         $total_items = count($items);
         $limit = $module_params->get('display_limit', '∞');
         $per_page = $module_params->get('mosaic_items_per_page', 1);
         $displayed_items = isset($params->displayed) ? count($params->displayed) : 0;
         $new_limit = (int) $limit > (int) $displayed_items ? (int) $limit - (int) $displayed_items : 0;
         $original_total = $displayed_items + $total_items;
         //trim to allowed limit
         if ($limit != '∞' && (int) $new_limit > 0 && $total_items > $new_limit) {
             $items = $items->trim($new_limit);
         }
         //trim if showing only next page
         if (!isset($params->all) && count($items) > $per_page) {
             $items = $items->trim($per_page);
         }
         $items = $platformHelper->processItemsForEvents($items, $module_params);
         $more = true;
         if (isset($params->all) && $params->all) {
             //showing all
             $more = false;
         }
         if ($limit != '∞' && $displayed_items + count($items) >= $limit) {
             //limit is met
             $more = false;
         }
         if ($displayed_items + count($items) >= $original_total) {
             //all have been shown
             $more = false;
         }
         $provider_type = $module_params->get('provider', 'joomla');
         $sort_type = $module_params->get($provider_type . '_sort', 'automatic');
         if ($sort_type == RokSprocket_ItemCollection::SORT_METHOD_RANDOM) {
             $items->sort($sort_type);
         }
         $themecontext = $layout->getThemeContent();
         ob_start();
         $index = 0;
         $displayed = $params->displayed;
         foreach ($items as $item_id => &$item) {
             echo $themecontext->load('item.php', array('item' => $item, 'parameters' => $module_params, 'index' => $index));
             array_push($displayed, (int) $item->getId());
             $index++;
         }
         $html .= ob_get_clean();
         $html = $platformHelper->processOutputForEvents($html, $module_params);
         $result->setPayload(array('page' => $params->page, 'more' => $more, 'behavior' => $params->behavior, 'displayed' => $displayed, 'html' => $html));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }
예제 #2
0
 /**
  * @param $params
  * {
  *  "page":1,
  *  "moduleid": 86
  * }
  *
  * @return RokCommon_Ajax_Result
  */
 public function getPage($params)
 {
     $result = new RokCommon_Ajax_Result();
     try {
         $html = '';
         $container = RokCommon_Service::getContainer();
         /** @var $platformHelper RokSprocket_PlatformHelper */
         $platformHelper = $container->roksprocket_platformhelper;
         $module_params = $platformHelper->getModuleParameters($params->moduleid);
         // add the layout classpath
         $layout_lib_path = $container['roksprocket.layouts.mosaic.library.paths'];
         foreach ($layout_lib_path as $lib_path) {
             RokCommon_ClassLoader::addPath($lib_path);
         }
         $container = RokCommon_Service::getContainer();
         /** @var $platformHelper RokSprocket_PlatformHelper */
         $platformHelper = $container->roksprocket_platformhelper;
         $items = $platformHelper->getFromCache(array('RokSprocket', 'getItemsWithParams'), array($params->moduleid, $module_params, true), $module_params, $params->moduleid);
         /** @var $layout RokSprocket_Layout_Mosaic */
         $layout = $container->getService('roksprocket.layout.mosaic');
         $layout->initialize($items, $module_params);
         $items = $layout->getItems();
         if (isset($params->filter) && $params->filter && $params->filter != 'all') {
             $filtered = new RokSprocket_ItemCollection();
             foreach ($items as $item) {
                 $tags = $item->getParam('mosaic_item_tags', '');
                 $tags = explode(",", $tags);
                 foreach ($tags as $i => $tag) {
                     $cleanName = trim($tag);
                     $tags[$i] = str_replace(' ', '-', str_replace(array("'", '"'), '', $cleanName));
                 }
                 if (in_array($params->filter, $tags)) {
                     $filtered->addItem($item);
                 }
             }
             $items = $filtered;
         }
         $total_items = count($items);
         $provider_type = $module_params->get('provider', 'joomla');
         $sort_type = $module_params->get($provider_type . '_sort', 'automatic');
         if ($sort_type == RokSprocket_ItemCollection::SORT_METHOD_RANDOM) {
             $items->sort($sort_type);
         }
         $limit = $module_params->get('display_limit', '∞');
         if ($limit != '∞' && (int) $limit > 0) {
             $items = $items->trim($limit);
         }
         $per_page = $module_params->get('mosaic_items_per_page', 1);
         $offset = ($params->page - 1) * $per_page;
         if (isset($params->all) && $params->all) {
             $items = $items->slice($offset, $total_items);
         } else {
             $items = $items->slice($offset, $per_page);
         }
         $items = $platformHelper->processItemsForEvents($items, $module_params);
         $more = isset($params->all) && $params->all ? false : $params->page < ceil($total_items / $per_page);
         $themecontext = $layout->getThemeContent();
         ob_start();
         $index = 0;
         foreach ($items as $item) {
             echo $themecontext->load('item.php', array('item' => $item, 'parameters' => $module_params, 'index' => $index));
             $index++;
         }
         $html .= ob_get_clean();
         $result->setPayload(array('page' => $params->page, 'more' => $more, 'behavior' => $params->behavior, 'html' => $html));
     } catch (Exception $e) {
         throw $e;
     }
     return $result;
 }