Changeset 7475
- Timestamp:
- 02/13/08 14:06:14 (9 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/sfPropelActAsTaggableBehaviorPlugin/trunk/lib/model/TagPeer.php
r6442 r7475 2 2 /* 3 3 * This file is part of the sfPropelActAsTaggableBehavior package. 4 * 4 * 5 5 * (c) 2007 Xavier Lacot <xavier@lacot.org> 6 * 6 * 7 7 * For the full copyright and license information, please view the LICENSE 8 8 * file that was distributed with this source code. … … 11 11 /** 12 12 * Subclass for performing query and update operations on the 'tag' table. 13 * 13 * 14 14 * @package plugins.sfPropelActAsTaggableBehaviorPlugin.lib.model 15 */ 15 */ 16 16 class TagPeer extends BaseTagPeer 17 17 { 18 18 /** 19 19 * Returns all tags, eventually with a limit option. 20 * The first optionnal parameter permits to add some restrictions on the 20 * The first optionnal parameter permits to add some restrictions on the 21 21 * objects the selected tags are related to. 22 22 * The second optionnal parameter permits to restrict the tag selection with 23 23 * different criterias 24 * 24 * 25 25 * @param Criteria $c 26 26 * @param array $options … … 69 69 /** 70 70 * Returns all tags, sorted by name, with their number of occurencies. 71 * The first optionnal parameter permits to add some restrictions on the 71 * The first optionnal parameter permits to add some restrictions on the 72 72 * objects the selected tags are related to. 73 73 * The second optionnal parameter permits to restrict the tag selection with 74 74 * different criterias 75 * 75 * 76 76 * @param Criteria $c 77 77 * @param array $options … … 135 135 136 136 /** 137 * Returns the names of the models that have instances tagged with one or 138 * several tags. The optionnal parameter might be a string, an array, or a 137 * Returns the names of the models that have instances tagged with one or 138 * several tags. The optionnal parameter might be a string, an array, or a 139 139 * comma separated string 140 * 140 * 141 141 * @param mixed $tags 142 142 * @return array … … 190 190 191 191 /** 192 * Returns the most popular tags with their associated weight. See 192 * Returns the most popular tags with their associated weight. See 193 193 * sfPropelActAsTaggableToolkit::normalize for more details. 194 * 195 * The first optionnal parameter permits to add some restrictions on the 194 * 195 * The first optionnal parameter permits to add some restrictions on the 196 196 * objects the selected tags are related to. 197 197 * The second optionnal parameter permits to restrict the tag selection with 198 198 * different criterias 199 * 199 * 200 200 * @param Criteria $c 201 201 * @param array $options … … 219 219 220 220 /** 221 * Returns the tags that are related to one or more other tags, with their 222 * associated weight (see sfPropelActAsTaggableToolkit::normalize for more 221 * Returns the tags that are related to one or more other tags, with their 222 * associated weight (see sfPropelActAsTaggableToolkit::normalize for more 223 223 * details). 224 * The "related tags" of one tag are the ones which have at least one 224 * The "related tags" of one tag are the ones which have at least one 225 225 * taggable object in common. 226 * 227 * The first optionnal parameter permits to add some restrictions on the 226 * 227 * The first optionnal parameter permits to add some restrictions on the 228 228 * objects the selected tags are related to. 229 229 * The second optionnal parameter permits to restrict the tag selection with 230 230 * different criterias 231 * 231 * 232 232 * @param mixed $tags 233 233 * @param array $options … … 285 285 /** 286 286 * Retrieves the objects tagged with one or several tags. 287 * 287 * 288 288 * The second optionnal parameter permits to restrict the tag selection with 289 289 * different criterias 290 * 290 * 291 291 * @param mixed $tags 292 292 * @param array $options … … 314 314 315 315 /** 316 * Retrieve a Criteria instance for querying tagged model objects. 317 * 318 * Example: 319 * 320 * $c = TagPeer::getTaggedWithCriteria('Article', array('tag1', 'tag2')); 321 * $c->addDescendingOrderByColumn(ArticlePeer::POSTED_AT); 322 * $c->setLimit(10); 323 * $this->articles = ArticlePeer::doSelectJoinAuthor($c); 324 * 325 * @param string $model Taggable model name 326 * @param mixed $tags array of tags (can be a string where tags are 327 * comma separated) 328 * @param Criteria $c Existing Criteria to hydrate 329 * @return Criteria 330 */ 331 public static function getTaggedWithCriteria($model, $tags = array(), Criteria $c = null) 332 { 333 if (!$c instanceof Criteria) 334 { 335 $c = new Criteria(); 336 } 337 338 if (!class_exists($model) || !is_callable(new $model, 'getPeer')) 339 { 340 throw new PropelException(sprintf('The class "%s" does not exist, or it is not a model class.', 341 $model)); 342 } 343 344 $taggings = self::getTaggings($tags, array('model' => $model)); 345 $tagging = isset($taggings[$model]) ? $taggings[$model] : array(); 346 $peer = get_class(call_user_func(array(new $model, 'getPeer'))); 347 $c->add(constant($peer.'::ID'), $tagging, Criteria::IN); 348 349 return $c; 350 } 351 352 /** 316 353 * Returns the taggings associated to one tag or a set of tags. 317 * 354 * 318 355 * The second optionnal parameter permits to restrict the results with 319 356 * different criterias 320 * 321 * @param mixed $tags 322 * @param array $options 323 * @return array 324 */ 325 pr ivatestatic function getTaggings($tags = array(), $options = array())357 * 358 * @param mixed $tags Array of tag strings or string 359 * @param array $options Array of options parameters 360 * @return array 361 */ 362 protected static function getTaggings($tags = array(), $options = array()) 326 363 { 327 364 $tags = sfPropelActAsTaggableToolkit::explodeTagString($tags); … … 342 379 $c->addSelectColumn(TaggingPeer::TAGGABLE_ID); 343 380 381 // Taggable model class option 344 382 if (isset($options['model'])) 345 383 { 384 if (!class_exists($options['model']) || !is_callable(new $options['model'], 'getPeer')) 385 { 386 throw new PropelException(sprintf('The class "%s" does not exist, or it is not a model class.', 387 $options['model'])); 388 } 389 346 390 $c->add(TaggingPeer::TAGGABLE_MODEL, $options['model']); 347 391 } … … 409 453 /** 410 454 * Retrives a tag by his name. 411 * 455 * 412 456 * @param String $tagname 413 457 * @return Tag … … 423 467 * Retrieves a tag by his name. If it does not exist, creates it (but does not 424 468 * save it) 425 * 469 * 426 470 * @param String $tagname 427 471 * @return Tag plugins/sfPropelActAsTaggableBehaviorPlugin/trunk/lib/sfPropelActAsTaggableToolkit.class.php
r7390 r7475 124 124 if (!is_string($model)) 125 125 { 126 throw new Exception('The param passed to the met od isTaggable must bea string.');126 throw new Exception('The param passed to the method isTaggable must be an object or a string.'); 127 127 } 128 128