private function FindCurrentCategoriesFromUrl($url, CategoryCollection $categories_to_search) { # Strip any querystring $pos = strpos($url, '?'); if ($pos) { $url = substr($url, 0, $pos); } # If there's a filename, strip it if (strpos($url, ".php")) { $url = substr($url, 0, strpos($url, basename($url))); } # Strip any surrounding slashes $url = trim($url, '/'); # If there's more than one folder, loop from the deepest to the highest looking for one which matches a category $folders = explode('/', $url); if (is_array($folders)) { for ($i = count($folders) - 1; $i >= 0; $i--) { $category = $categories_to_search->GetByUrl($folders[$i]); if ($category != false) { $this->o_current_categories->Add($category); break; } } } }
public function create() { $data = array(); $categoryCollection = new CategoryCollection(); $categories = $categoryCollection->getAll(); $insertInfo = array('name' => '', 'image' => '', 'category_id' => '', 'description' => ''); $errors = array(); if (isset($_POST['createTour'])) { $fileUpload = new fileUpload('image'); $file = $fileUpload->getFilename(); $fileExtention = $fileUpload->getFileExtention(); $imageErrors = array(); if ($file != '') { $imageErrors = $fileUpload->validate(); $newName = sha1(time()) . '.' . $fileExtention; } else { $newName = ''; } $insertInfo = array('name' => $_POST['name'], 'image' => $newName, 'category_id' => $_POST['categories'], 'description' => $_POST['description']); if (empty($imageErrors) && empty($errors)) { $toursCollection = new ToursCollection(); $toursEntity = new ToursEntity(); $obj = $toursEntity->init($insertInfo); $toursCollection->save($obj); $fileUpload->upload('uploads/tours/' . $newName); header("Location: index.php?c=tour&m=index"); } } $data['errors'] = $errors; $data['categories'] = $categories; $data['insertInfo'] = $insertInfo; $this->loadView('tours/create', $data); }
/** * @test * @covers WalmartApiClient\Entity\Collection\CategoryCollection::toArray * @covers WalmartApiClient\Entity\Collection\CategoryCollection::toArrayRecursive */ public function testToArray() { $subcategory = new \WalmartApiClient\Entity\Category(['id' => '1_1', 'name' => 'subcategory', 'path' => 'subcategory']); $category = new \WalmartApiClient\Entity\Category(['id' => '1', 'name' => 'category', 'path' => 'category', 'children' => [$subcategory]]); $collection = new CategoryCollection([$category]); $array = $collection->toArray(); $this->assertTrue($array[0]['id'] === '1'); $this->assertTrue($array[0]['children'][0]['id'] === '1_1'); }
function CategorySelectControl(CategoryCollection $o_categories, $page_valid = null) { # set properties parent::XhtmlSelect('category', null, $page_valid); $this->SetBlankFirst(true); # add categories $a_categories = $o_categories->GetItems(); foreach ($a_categories as $o_category) { $o_opt = new XhtmlOption($o_category->GetName(), $o_category->GetId()); $o_opt->AddAttribute('style', 'padding-left: ' . ($o_category->GetHierarchyLevel() - 1) * 20 . 'px'); $this->AddControl($o_opt); unset($o_opt); } }
public function delete() { if (!$this->loggedIn()) { header('Location: index.php?c=login&m=login'); } if (!isset($_GET['id'])) { header('Location: index.php?c=category&m=index'); } $categoryCollection = new CategoryCollection(); $category = $categoryCollection->getOne($_GET['id']); if (is_null($category)) { header('Location: index.php?c=category&m=index'); } $categoryCollection->delete($category->getId()); header('Location: index.php?c=category&m=index'); }
/** * Returns a prefilled CategoryCollection * * @return \BFewo\Iterator\CategoryCollection */ protected function prepareCategoryCollection() { $categoryCollection = new CategoryCollection(); for ($c = 0; $c < 5; $c++) { $postCollection = new PostCollection(); $category = new Category($postCollection); $categoryCollection->append($category); for ($p = 0; $p < 5; $p++) { $tagCollection = new TagCollection(); $post = new Post($tagCollection); $postCollection->append($post); for ($t = 0; $t < 5; $t++) { $tag = new Tag(); $tagCollection->append($tag); } } } return $categoryCollection; }
/** * Rebuilds the category tree. We are using the Nested Set tree model. * * @param bool $BySort Rebuild the tree by sort order instead of existing tree order. * @ref http://en.wikipedia.org/wiki/Nested_set_model * * @since 2.0.0 * @access public */ public function rebuildTree($BySort = false) { // Grab all of the categories. if ($BySort) { $Order = 'Sort, Name'; } else { $Order = 'TreeLeft, Sort, Name'; } $Categories = $this->SQL->get('Category', $Order); $Categories = Gdn_DataSet::Index($Categories->resultArray(), 'CategoryID'); // Make sure the tree has a root. if (!isset($Categories[-1])) { $RootCat = array('CategoryID' => -1, 'TreeLeft' => 1, 'TreeRight' => 4, 'Depth' => 0, 'InsertUserID' => 1, 'UpdateUserID' => 1, 'DateInserted' => Gdn_Format::toDateTime(), 'DateUpdated' => Gdn_Format::toDateTime(), 'Name' => 'Root', 'UrlCode' => '', 'Description' => 'Root of category tree. Users should never see this.', 'PermissionCategoryID' => -1, 'Sort' => 0, 'ParentCategoryID' => null); $Categories[-1] = $RootCat; $this->SQL->insert('Category', $RootCat); } // Build a tree structure out of the categories. $Root = null; foreach ($Categories as &$Cat) { if (!isset($Cat['CategoryID'])) { continue; } // Backup category settings for efficient database saving. try { $Cat['_TreeLeft'] = $Cat['TreeLeft']; $Cat['_TreeRight'] = $Cat['TreeRight']; $Cat['_Depth'] = $Cat['Depth']; $Cat['_PermissionCategoryID'] = $Cat['PermissionCategoryID']; $Cat['_ParentCategoryID'] = $Cat['ParentCategoryID']; } catch (Exception $Ex) { } if ($Cat['CategoryID'] == -1) { $Root =& $Cat; continue; } $ParentID = $Cat['ParentCategoryID']; if (!$ParentID) { $ParentID = -1; $Cat['ParentCategoryID'] = $ParentID; } if (!isset($Categories[$ParentID]['Children'])) { $Categories[$ParentID]['Children'] = array(); } $Categories[$ParentID]['Children'][] =& $Cat; } unset($Cat); // Set the tree attributes of the tree. $this->_SetTree($Root); unset($Root); // Save the tree structure. foreach ($Categories as $Cat) { if (!isset($Cat['CategoryID'])) { continue; } if ($Cat['_TreeLeft'] != $Cat['TreeLeft'] || $Cat['_TreeRight'] != $Cat['TreeRight'] || $Cat['_Depth'] != $Cat['Depth'] || $Cat['PermissionCategoryID'] != $Cat['PermissionCategoryID'] || $Cat['_ParentCategoryID'] != $Cat['ParentCategoryID'] || $Cat['Sort'] != $Cat['TreeLeft']) { $this->SQL->put('Category', array('TreeLeft' => $Cat['TreeLeft'], 'TreeRight' => $Cat['TreeRight'], 'Depth' => $Cat['Depth'], 'PermissionCategoryID' => $Cat['PermissionCategoryID'], 'ParentCategoryID' => $Cat['ParentCategoryID'], 'Sort' => $Cat['TreeLeft']), array('CategoryID' => $Cat['CategoryID'])); } } $this->SetCache(); $this->collection->flushCache(); }
/** * @return void * @param Category[] $a_stack * @param Category[] $a_categories * @param CategoryCollection $o_sorted_categories * @param Object which can generate the category URLs $url_manager * @param Name of method to generate the category URLs $url_method * @desc Recursively look for and gather categories in hierarchical order */ private function GatherChildCategories(&$a_stack, &$a_categories, &$o_sorted_categories, $url_manager, $url_method) { $i_total_categories = count($a_categories); for ($i = 0; $i < $i_total_categories; $i++) { array_push($a_stack, $a_categories[$i]); $o_child =& $this->IsChildCategory($a_stack, $url_manager, $url_method); if (is_object($o_child)) { $o_sorted_categories->Add($o_child); $this->GatherChildCategories($a_stack, $a_categories, $o_sorted_categories, $url_manager, $url_method); } array_pop($a_stack); } }
} ?> <?php } ?> <li class="divider"></li> <li><a class="text-center" href="">View Cart</a></li> </ul> </li> </ul> <ul class="nav navbar-nav navbar-right"> <li class="dropdown "> <a href="#" class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true">Tours Categories <b class="caret"></b></a> <ul class="dropdown-menu"> <?php $categoryCollection = new CategoryCollection(); $categories = $categoryCollection->getAll(); ?> <li> <a href="index.php?c=tours&m=index&id=0">All Categories</a> </li> <?php foreach ($categories as $category) { ?> <li> <a href="index.php?c=tours&m=index&id=<?php echo $category->getId(); ?> "><?php echo $category->getName(); ?>
<?php require_once 'common/header.php'; if (!loggedIn()) { header('Location: login.php'); } if (!loggedIn()) { header('Location: login.php'); } if (!isset($_GET['id'])) { header('Location: clients.php'); } $categoryCollection = new CategoryCollection(); $category = $categoryCollection->getOne($_GET['id']); if (is_null($category)) { header('Location: categories.php'); } $insertInfo = array('name' => $category->getName(), 'description' => $category->getDescription()); $errors = array(); if (isset($_POST['editCategory'])) { $insertInfo = array('name' => isset($_POST['name']) ? $_POST['name'] : '', 'description' => isset($_POST['description']) ? $_POST['description'] : ''); if (!isset($_POST['name']) || strlen($_POST['name']) < 3 || strlen($_POST['name']) > 255) { $errors['name'] = 'Incorrect name'; } if (!isset($_POST['description']) || strlen($_POST['description']) < 3 || strlen($_POST['description']) > 255) { $errors['description'] = 'Incorrect description'; } if (empty($errors)) { $categoryEntity = new CategoryEntity(); $categoryEntity->setId($_GET['id']); $obj = $categoryEntity->init($insertInfo);
/** * Create a new category collection tied to this model. * * @return CategoryCollection Returns a new collection. */ public function createCollection(Gdn_SQLDriver $sql = null, Gdn_Cache $cache = null) { if ($sql === null) { $sql = $this->SQL; } if ($cache === null) { $cache = Gdn::cache(); } $collection = new CategoryCollection($sql, $cache); // Inject the calculator dependency. $collection->setConfig(Gdn::config()); $collection->setStaticCalculator(function (&$category) { self::calculate($category); }); $collection->setUserCalculator(function (&$category) { $this->calculateUser($category); }); return $collection; }
protected function parseCategories() { $categoryCollection = new CategoryCollection(); $this->crawler->filter('.video-info-row:contains("Categories:") a:not(:contains("Suggest"))')->each(function (Crawler $node) use($categoryCollection) { $categoryCollection->add(new Category($this->client, $node->link()->getUri())); }); $this->categories = $categoryCollection; }
public function getChilds() { $childs = new CategoryCollection(); $childs->where(array('parent_id' => $this->id)); return $childs; }