Exemplo n.º 1
0
 /**
  * Loads a category by an array of slugs
  * The array should be the order of slugs found in the URI
  * The whole slug array must match (including parent relationsips)
  *
  * @param array $slugs
  * @param Fishpig_Wordpress_Model_Term $object
  * @return false
  */
 public function loadBySlugs(array $slugs, Fishpig_Wordpress_Model_Term $object)
 {
     $slugs = array_reverse($slugs);
     $primarySlug = array_shift($slugs);
     try {
         $object->loadBySlug($primarySlug);
         if ($object->getId()) {
             $category = $object;
             foreach ($slugs as $slug) {
                 $parent = Mage::getModel($object->getResourceName())->loadBySlug($slug);
                 if ($parent->getId() !== $category->getParent()) {
                     throw new Exception('This path just ain\'t right, bro!');
                 }
                 $category->setParentTerm($parent);
                 $category = $parent;
             }
             if (!$category->getParentId()) {
                 return true;
             }
         }
     } catch (Exception $e) {
     }
     $object->setData(array())->setId(null);
     return false;
 }
Exemplo n.º 2
0
 /**
  * Loads the posts belonging to this category
  *
  * @return Fishpig_Wordpress_Model_Mysql4_Post_Collection
  */
 public function getPostCollection()
 {
     if (!$this->hasPostCollection()) {
         $this->setPostCollection(parent::getPostCollection()->addTagIdFilter($this->getId()));
     }
     return $this->_getData('post_collection');
 }
Exemplo n.º 3
0
 /**
  * Retrieve the URI for the category
  * This is a wrapper for the parent method and injects
  * the category base if WordPress is configured to use this
  *
  * @return string|false
  */
 public function getUri()
 {
     $helper = Mage::helper('wordpress/router');
     $uri = substr(parent::getUri(), strlen($this->getTaxonomy()) + 1);
     if (!$helper->categoryUrlHasBase()) {
         return $uri;
     }
     return $helper->getCategoryBase() . '/' . $uri;
 }
Exemplo n.º 4
0
 /**
  * Determine whether $post is in the current term
  *
  * @param Fishpig_Wordpress_Model_Term $term
  * @param int|Fishpig_Wordpress_Model_Post_Abstract $object
  * @return bool
  */
 public function containsPost($term, $object)
 {
     $objectId = is_object($object) ? $object->getId() : $object;
     if (!$objectId || $term->getItemCount() === 0) {
         return false;
     }
     $select = $this->_getReadAdapter()->select()->from($this->getTable('wordpress/term_relationship'), 'object_id')->where('term_taxonomy_id = ?', $term->getTermTaxonomyId())->where('object_id = ?', $objectId)->limit(1);
     return $this->_getReadAdapter()->fetchOne($select) !== false;
 }
 /**
  * Retrieve the URI for $term
  *
  * @param Fishpig_Wordpress_Model_Term $term
  * @return false|string
  */
 public function getTermUri(Fishpig_Wordpress_Model_Term $term)
 {
     return $this->getUriById($term->getId(), $term->getTaxonomyType());
 }