Development

Changeset 7552

You must first sign up to be able to contribute.

Changeset 7552

Show
Ignore:
Timestamp:
02/20/08 11:35:52 (9 months ago)
Author:
francois
Message:

sfPropelActAsCountableBehaviorPlugin Added automatic update of nb_sf_counts columns

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelActAsCountableBehaviorPlugin/tags/0.1/README

    r7048 r7552  
    111111}}} 
    112112 
     113This method is resource intensive, so if you want to manipulate your countable objects more easily, for instance to achieve a sort by number of counts in a single query, you should add a `nb_sf_counts` column to your object to keep the number of counts. The behavior will keep this column up to date, provided that you declare it in the `app.yml`: 
     114{{{ 
     115all: 
     116  sfPropelActAsCountableBehaviorPlugin: 
     117    count: 
     118      enabled: true           # whether or not the method must be called for updating the count 
     119      method:  setNbSfCounts  # name of the method to call in order to update the count. If you call the comments count column "gerard", simply put "setGerard" on this line 
     120}}} 
     121 
     122With this trick, sorting objects by their counter value is rather straightforward: 
     123{{{ 
     124$c = new Criteria(); 
     125$c->addDescendingOrderByColumn(PostPeer::NB_SF_COUNTS); 
     126$posts = PostPeer::doSelect($c); 
     127}}} 
     128 
    113129== API == 
    114130The behavior implement the following methods: 
     
    143159== Changelog == 
    144160 
     161=== Trunk - 2008-02-20 === 
     162 
     163 * francois: Added automatic update of `nb_sf_counts` columns 
     164 
    145165=== version 0.1 - 2008-01-14 === 
    146166Initial public release. 
  • plugins/sfPropelActAsCountableBehaviorPlugin/tags/0.1/lib/sfPropelActAsCountableBehavior.class.php

    r7048 r7552  
    172172 
    173173    $object->_counter->save(); 
     174     
     175    $count_options = array_merge(array('method'    => 'setNbSfCounts', 
     176                                       'enabled'   => true), 
     177                                 sfConfig::get('app_sfPropelActAsCountableBehaviorPlugin_count', array())); 
     178 
     179    if ($count_options['enabled'] && is_callable(get_class($object), $count_options['method'])) 
     180    { 
     181      call_user_func(array($object, $count_options['method']), $object->_counter->getCounter()); 
     182      $object->save(); 
     183    } 
    174184  } 
    175185}