/** get Catalogue Item * @param $path * @return array */ private function getCatalogueItem($path) { $data = array(); $path_items = CatalogueUtils::getPathItems($path); $catalogue = array(); $catalogue["path_items"] = $path_items; $last = count($path) - 1; $catalogue["current_label"] = $path[$last]; /* * // prev item categories list * $arr = $this->address["path"]; array_pop($arr); $catalogue["prev_item_path"] = implode("/", $arr); $pre_last = count($this->address["path"]) - 2; if ($pre_last >= 0){ $childrenId = $path_items[$pre_last]["children_id"]; $current_categories = CatalogueUtils::getProducts($childrenId); } */ if (count($path) > 1) { $childrenId = $path_items[0]["children_id"]; $current_categories = CatalogueUtils::getProducts($childrenId); G::addToRender("blocks/sidebar_navigation.php", BLOCK_SIDEBAR_LEFT, CODE); } else { G::addToRender("<h1>" . G::$language->getText("common", "catalogue_link_text") . "</h1>", BLOCK_CONTENT); } $childrenId = $path_items[$last]["children_id"]; $products = array(); if ($path_items[$last]["type"] != TYPE_CATEGORY) { // single product $node = CatalogueUtils::getCatalogueNode($path_items[$last]["label"]); $current_product = new ProductItem($node); # required class ProductItem $data = $this->parsePageData($node); // "if hidden" HERE because - admin mode should load data of hidden elements if (!$path_items[$last]["hidden"]) { G::addToRender("catalogue/catalogue_single_product.php", BLOCK_CONTENT, CODE); G::addToRender("blocks/brand_block.php", BLOCK_SIDEBAR_RIGHT, CODE); } else { //$this->redirect(PAGE_PAGE404); when not AJAX $message = "<p class='grey-text' align='center'>" . G::$language->getText("catalogue", "category_fail") . "</p>"; G::addToRender($message, BLOCK_CONTENT); } } else { $node = CatalogueUtils::getCatalogueNode($path_items[$last]["label"]); $current_product = new ProductItem($node); $data = $this->parsePageData($node); if (strlen($childrenId) > 0) { //multiple categories|products $total = count(explode(",", $childrenId)); $page = intval($_GET["page"]); $items_limit = isset($_SESSION["page_items_limit"]) ? $_SESSION["page_items_limit"] : Paginator::PAGE_ITEMS_LIMIT; $max_pages = ceil($total / $items_limit); if ($page > $max_pages) { $_GET["page"] = $page = $max_pages; } if ($total > $_SESSION["page_items_limit"]) { $paginator = new Paginator($max_pages, $page); G::addToRender($paginator->render(), BLOCK_CONTENT, TEXT); } $products = CatalogueUtils::getProducts($childrenId, $_SESSION["page_items_limit"], $page); } if ($products && count($products) > 0) { G::addToRender("catalogue/catalogue_page_blocks.php", BLOCK_CONTENT, CODE); // die("HERE:".count($products)); } else { // no products in category $message = "<p class='grey-text' align='center'>" . G::$language->getText("common", "empty_category") . "</p>"; G::addToRender($message, BLOCK_CONTENT); } } $data["current_categories"] = $current_categories; $data["catalogue"] = $catalogue; $data["products"] = $products; $data["current_product"] = $current_product; // DEBUG $data["access"] = 4; if (!isset($data["title"])) { $data["title"] = G::$language->getText("common", "catalogue_link_text"); } $data["blocks_id"] = "1,3,4,5,6,7,8,9,10,11,12,15"; // return $data; }
} if (!empty($limit)) { $this->setItemsPerPage($limit); } // quickly calculate the offset based on the page if ($page > 0) { $page -= 1; } $offset = $page * $this->_itemsPerPage; // return the limit iterator return new LimitIterator($this->_it, $offset, $this->_itemsPerPage); } } // generate an example of page items to iterate over $items = array(array('id' => 1, 'name' => 'Item 1', 'desc' => 'Description', 'price' => 4.99), array('id' => 2, 'name' => 'Item 2', 'desc' => 'Description', 'price' => 4.99), array('id' => 3, 'name' => 'Item 3', 'desc' => 'Description', 'price' => 4.99), array('id' => 4, 'name' => 'Item 4', 'desc' => 'Description', 'price' => 4.99), array('id' => 5, 'name' => 'Item 5', 'desc' => 'Description', 'price' => 4.99), array('id' => 6, 'name' => 'Item 6', 'desc' => 'Description', 'price' => 4.99), array('id' => 7, 'name' => 'Item 7', 'desc' => 'Description', 'price' => 4.99), array('id' => 8, 'name' => 'Item 8', 'desc' => 'Description', 'price' => 4.99), array('id' => 9, 'name' => 'Item 9', 'desc' => 'Description', 'price' => 4.99), array('id' => 10, 'name' => 'Item 10', 'desc' => 'Description', 'price' => 4.99), array('id' => 11, 'name' => 'Item 11', 'desc' => 'Description', 'price' => 4.99), array('id' => 12, 'name' => 'Item 12', 'desc' => 'Description', 'price' => 4.99), array('id' => 13, 'name' => 'Item 13', 'desc' => 'Description', 'price' => 4.99), array('id' => 14, 'name' => 'Item 14', 'desc' => 'Description', 'price' => 4.99), array('id' => 15, 'name' => 'Item 15', 'desc' => 'Description', 'price' => 4.99), array('id' => 16, 'name' => 'Item 16', 'desc' => 'Description', 'price' => 4.99), array('id' => 17, 'name' => 'Item 17', 'desc' => 'Description', 'price' => 4.99), array('id' => 18, 'name' => 'Item 18', 'desc' => 'Description', 'price' => 4.99), array('id' => 19, 'name' => 'Item 19', 'desc' => 'Description', 'price' => 4.99), array('id' => 20, 'name' => 'Item 20', 'desc' => 'Description', 'price' => 4.99), array('id' => 21, 'name' => 'Item 21', 'desc' => 'Description', 'price' => 4.99)); // load the paginator $Paginator = new Paginator(new ArrayIterator($items)); // displays the initial set (page 1, limit 10) $results = $Paginator->render(); foreach ($results as $r) { var_dump($r); } // check for another page if ($Paginator->hasNextPage()) { echo 'DISPLAYING THE NEXT SET OF RESULTS AS AN EXAMPLE' . PHP_EOL; // displays the next page results as an example $results = $Paginator->render($Paginator->getCurrentPage() + 1); foreach ($results as $r) { var_dump($r); } }