public function group($group)
 {
     $this->_render['template'] = 'index';
     $type = Activity::group($group);
     $this->set(compact('group'));
     return $this->index(array('conditions' => compact('type')));
 }
Exemplo n.º 2
0
 /**
  * returns a list of activies, according to a given type, group or other conditions
  *
  * {{{
  *   Activities::get('event_type');
  *   Activities::get('group_name');
  *   Activities::get(array('type' => 'event_type'));
  *   Activities::get(array('type' => array('event_type1', 'event_type2')));
  *   Activities::get(array('group' => 'group_name'));
  *   Activities::get(array('foreign_id' => $id));
  *   Activities::get(array('foreign_id' => array($id1, $id2)));
  * }}}
  *
  * @see lithium\data\Model::find()
  * @param string|array $scope if string is given, a check is made of a group with that name
  *        exists and if so, the types for that group will be retrieved. If no group exists, it
  *        will be used as name for event_type, without any further checks.
  *        If it is an array, it can be used like `conditions` as on `Model::find()`, the most
  *        useful use-case would be to pass in a foreign_id, like `array('user_id' => $id)`.
  * @param array $options additional options, identical to those for `Model::find()`
  * @return object a collection object, containing all resulting activities, also:
  *     - `since`: id of last activity, to retrieve data since then
  * @filter
  */
 public static function get($scope, array $options = array())
 {
     $defaults = array('since' => false);
     $options += $defaults;
     $params = compact('scope', 'options');
     return static::_filter(__METHOD__, $params, function ($self, $params) {
         extract($params);
         if (is_string($scope)) {
             $types = Activity::group($scope);
             $scope = !empty($types) ? array('type' => $types) : array('type' => $scope);
         }
         if (isset($scope['group'])) {
             $scope['type'] = Activity::group($scope['group']);
             unset($scope['group']);
         }
         if ($options['since']) {
             $entity = $self::first($options['since'], array('fields' => 'created'));
             if ($entity) {
                 $scope['created'] = array('>=' => $entity->created);
             }
         }
         unset($options['since']);
         $options['conditions'] = $scope;
         return $self::find('all', $options);
     });
 }