Example #1
0
 public function testCreateCategory()
 {
     Category::reindex();
     $this->root->reload();
     // Get root node info, before it is modified
     $rootLft = $this->root->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME);
     $rootRgt = $this->root->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME);
     $rootID = $this->root->getID();
     // Create new category
     $newCategory = Category::getNewInstance($this->root);
     $newCategory->setValueByLang("name", 'en', 'TEST ' . rand(1, 1000));
     $newCategory->save();
     $this->assertTrue($newCategory->isExistingRecord());
     // Check if rgt and lft fields are calculated properly
     $this->root->reload();
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), $rootRgt);
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 2);
     // Check parrent id
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID(), $rootID);
     // Reload and check again
     $this->root->reload();
     $newCategory->reload();
     // Check
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), $rootRgt);
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::LEFT_NODE_FIELD_NAME), 1);
     $this->assertEqual($this->root->getFieldValue(ActiveTreeNode::RIGHT_NODE_FIELD_NAME), $rootRgt + 2);
     $this->assertEqual($newCategory->getFieldValue(ActiveTreeNode::PARENT_NODE_FIELD_NAME)->getID(), $rootID);
 }
 public function getCollection(Category $category)
 {
     return WikiaDataAccess::cache($this->getItemsCollectionCacheKey($category->getID()), self::CACHE_TTL_ITEMSCOLLECTION, function () use($category) {
         wfProfileIn(__METHOD__);
         $viewer = new WikiaMobileCategoryViewer($category);
         $viewer->doCategoryQuery();
         wfProfileOut(__METHOD__);
         return $viewer->getData();
     });
 }
Example #3
0
 public function registerAdditionalCategory(Category $category)
 {
     $this->additionalCategories[$category->getID()] = $category;
 }
Example #4
0
 private static function setCategoryOrder(Category $category, ARSelectFilter $f)
 {
     $f->setOrder(new ARExpressionHandle('CategoryPresentation.categoryID=' . $category->getID()), 'DESC');
     $f->setOrder(new ARFieldHandle('Category', 'lft'), 'DESC');
 }
Example #5
0
 /**
  *
  * Returns an array of News article IDs belonging to the search categories
  */
 protected function subsetNewsCategories()
 {
     global $_zp_CMS;
     if (!is_array($this->category_list)) {
         return false;
     }
     $cat = '';
     $list = $_zp_CMS->getAllCategories();
     if (!empty($list)) {
         foreach ($list as $category) {
             if (in_array($category['title'], $this->category_list)) {
                 $catobj = new Category($category['titlelink']);
                 $cat .= ' `cat_id`=' . $catobj->getID() . ' OR';
                 $subcats = $catobj->getSubCategories();
                 if ($subcats) {
                     foreach ($subcats as $subcat) {
                         $catobj = new Category($subcat);
                         $cat .= ' `cat_id`=' . $catobj->getID() . ' OR';
                     }
                 }
             }
         }
         if ($cat) {
             $cat = ' WHERE ' . substr($cat, 0, -3);
         }
     }
     $sql = 'SELECT DISTINCT `news_id` FROM ' . prefix('news2cat') . $cat;
     $result = query($sql);
     $list = array();
     if ($result) {
         while ($row = db_fetch_assoc($result)) {
             $list[] = $row['news_id'];
         }
         db_free_result($result);
     }
     return $list;
 }
Example #6
0
 public function testCategory()
 {
     $cat = new Category(123, 'A category');
     $this->assertEquals(123, $cat->getID());
     $this->assertEquals('A category', $cat->getName());
 }
Example #7
0
 /**
  * Validates that the given Google\MyBusiness\Category instance contains
  * either a name or ID that exists in the available category data.
  *
  * @param Google\MyBusiness\Category $category
  */
 public static function validateCategory(Category $category)
 {
     if (!self::$_staticPropsReady) {
         self::_initStaticProperties();
     }
     // Refresh category data if necessary
     $lastFetchData = self::_getLastFetchData('google_business_categories');
     if (!$lastFetchData || (int) $lastFetchData['fetch_date'] < time() - GOOGLE_MYBUSINESS_API_CATEGORIES_CACHE_DURATION) {
         self::_storeFetchData('google_business_categories', self::_refreshCategories());
     }
     $catID = $category->getID();
     $catName = $category->getName();
     if (!$catID && !$catName) {
         throw new InvalidArgumentException('Cannot validate a category unless it has an ID and/or a name.');
     }
     try {
         // Always prefer to validate on the basis of the ID, if present
         if ($catID) {
             $stmt = self::$_DB_STATEMENTS['google_business_categories']['select_by_id'];
             $stmt->bindValue(':id', $catID, \PDO::PARAM_STR);
         } else {
             $stmt = self::$_DB_STATEMENTS['google_business_categories']['select_by_name'];
             $stmt->bindValue(':name', $catName, \PDO::PARAM_STR);
         }
         $stmt->execute();
         $stmt->bindColumn('id', $dbID, \PDO::PARAM_STR);
         $stmt->bindColumn('name', $dbName, \PDO::PARAM_STR);
         if (!$stmt->fetch(\PDO::FETCH_BOUND)) {
             if ($catID) {
                 $message = 'The category ID "' . $catID . '" is invalid.';
             } else {
                 $message = 'The category name "' . $catName . '" is invalid.';
             }
             throw new UnexpectedValueException($message);
         }
         if ($catID) {
             $category->setName($dbName);
         } else {
             $category->setID($dbID);
         }
     } catch (\PDOException $e) {
         throw new RuntimeException('Caught database error while validating category.', null, $e);
     }
 }