public static function getTimeline($user, $offset = 0, $max = 20)
 {
     if ($user == NULL) {
         throw new Exception('user is null');
     }
     // Messages belonging to me or the users I follow
     $_or = Condition::_OR()->add(Condition::EQ(self::TABLE, 'createdBy_id', $user->getId()));
     // I want to see my messages also
     $following = $user->getFollowing();
     foreach ($following as $otherUser) {
         $_or->add(Condition::EQ(self::TABLE, 'createdBy_id', $otherUser->getId()));
     }
     // Paginated search
     // Messages ordered by createdOn, first the last messages
     $list = Message::findBy($_or, new ArrayObject(array('sort' => 'createdOn', 'dir' => 'desc', 'offset' => $offset, 'max' => $max)));
     return $list;
 }
 /**
  * FIXME: pasarle la clase, no una instancia.
  */
 public function countBy($ins, $condition)
 {
     Logger::getInstance()->pm_log("PM::countBy");
     $objTableName = YuppConventions::tableName($ins);
     $params = array();
     // Quiero solo los registros de las subclases y ella misma.
     $class = get_class($ins);
     $scs = ModelUtils::getAllSubclassesOf($class);
     $scs[] = $class;
     // Definicion de la condicion.
     $cond_total = Condition::_AND();
     if (count($scs) == 1) {
         $cond_total->add(Condition::EQ($objTableName, "class", $scs[0]));
     } else {
         $cond = Condition::_OR();
         foreach ($scs as $subclass) {
             $cond->add(Condition::EQ($objTableName, "class", $subclass));
         }
         $cond_total->add($cond);
     }
     // FIXED: igual que en findByAttributeMatrix usada por findBy
     // Si no tiene condicion deleted, le pone deleted false.
     if ($condition == NULL || !$condition->hasCondForAttr('deleted')) {
         $cond_total->add(Condition::EQ($objTableName, "deleted", 0));
     }
     // CRITERIO DE BUSQUEDA
     if ($condition != NULL) {
         $cond_total->add($condition);
     }
     $params['where'] = $cond_total;
     return $this->dal->count($objTableName, $params);
 }