/** * testDeepAssociationsBelongsTo * * @link https://github.com/CakeDC/tags/issues/15 * @return void */ public function testDeepAssociationsBelongsTo() { $this->Tagged->bindModel(array('belongsTo' => array('Article' => array('className' => 'TaggedArticle', 'foreignKey' => 'foreign_key')))); $this->Tagged->Article->bindModel(array('belongsTo' => array('User' => array()))); $result = $this->Tagged->find('all', array('contain' => array('Article' => array('User')))); $this->assertEquals($result[0]['Article']['User']['name'], 'CakePHP'); }
/** * Test custom _findTagged method with additional conditions on the model * * @return void */ public function testFindTaggedWithConditions() { $this->Tagged->recursive = -1; $result = $this->Tagged->find('tagged', array('by' => 'cakephp', 'model' => 'Article', 'conditions' => array('Article.title LIKE' => 'Second %'))); $this->assertEqual(count($result), 0); $result = $this->Tagged->find('tagged', array('by' => 'cakephp', 'model' => 'Article', 'conditions' => array('Article.title LIKE' => 'First %'))); $this->assertEqual(count($result), 1); $this->assertEqual($result[0]['Article']['id'], 'article-1'); }
/** * Test custom _findTagged method * * @return void */ public function testFindTagged() { $result = $this->Tagged->find('tagged', array('by' => 'cakephp', 'model' => 'Article')); $this->assertEqual(count($result), 1); $this->assertEqual($result[0]['Article']['id'], 1); $result = $this->Tagged->find('tagged', array('model' => 'Article')); $this->assertEqual(count($result), 2); // Test call to paginateCount by Controller::pagination() $result = $this->Tagged->paginateCount(array(), 1, array('model' => 'Article', 'type' => 'tagged')); $this->assertEqual($result, 2); }
/** * Deletes all Tags assigned to these tagged object. * * @param Tagged $object object whose assigned to tags should be deleted */ public function deleteObjectTags(Tagged $object, $languageIDArray = array(), $deleteUnassignedTags = true) { if (!count($languageIDArray)) { $languageIDArray = array(0); } $sql = "DELETE FROM \twcf" . WCF_N . "_tag_to_object\n\t\t\tWHERE \t\ttaggableID = " . $object->getTaggable()->getTaggableID() . "\n\t\t\t\t\tAND languageID IN (" . implode(',', $languageIDArray) . ")\n\t\t\t\t\tAND objectID = " . $object->getObjectID(); WCF::getDB()->sendQuery($sql); if ($deleteUnassignedTags) { $this->deleteUnassignedTags(); } }
/** * Return an array of all of the tags that are in use by this model * * @return Collection */ public static function existingTags() { return Tagged::distinct()->join('tags', 'tag_slug', '=', 'tags.slug')->where('taggable_type', '=', (new static())->getMorphClass())->orderBy('tag_slug', 'ASC')->get(array('tag_slug as slug', 'tag_name as name', 'tags.count as count')); }