Пример #1
0
 /**
  * Retrieves starred objects for a user
  *
  * @param  int    $user_id
  * @param  array  $options
  * @return array  
  **/
 public static function getUserStars($user_id = null, $options = array())
 {
     if (!$user_id) {
         $user_id = sfPropelActAsStarredBehaviorToolkit::getUserId();
     }
     if (!$user_id) {
         throw new sfException('Cannot retrieve current user.');
     }
     $c = new Criteria();
     $c->add(StarPeer::USER_ID, $user_id);
     if (isset($options['model'])) {
         $c->add(StarPeer::STARRED_MODEL, $options['model']);
     }
     $c->addAscendingOrderByColumn(StarPeer::STARRED_MODEL);
     $stars = StarPeer::doSelect($c);
     $results = array();
     foreach ($stars as $star) {
         $c = new Criteria();
         $peer = $star->getStarredModel() . 'Peer';
         $object = call_user_func(array($peer, 'retrieveByPK'), $star->getStarredId());
         $results[] = $object;
     }
     return $results;
 }
Пример #2
0
 public static function retrievePagerByUserStarred($user_id, $page = 1, $max = null)
 {
     if ($max == null) {
         $max = sfConfig::get('app_pager_project_max');
     }
     $c = new Criteria();
     $c->add(StarPeer::USER_ID, $user_id);
     $c->add(StarPeer::STARRED_MODEL, 'Project');
     $c->addAscendingOrderByColumn(StarPeer::STARRED_MODEL);
     sfContext::getInstance()->getLogger()->info('Grab starred project records...');
     $stars = StarPeer::doSelect($c);
     $c = new Criteria();
     $projects = array();
     sfContext::getInstance()->getLogger()->info('build project ids for query');
     foreach ($stars as $star) {
         $projects[] = $star->getStarredId();
     }
     sfContext::getInstance()->getLogger()->info('ID List Built! ' . print_r($projects, true));
     $c->add(self::ID, $projects, Criteria::IN);
     sfContext::getInstance()->getLogger()->info('init starred pager');
     $pager = new sfPropelPager('Project', $max);
     $pager->setCriteria($c);
     $pager->setPage($page);
     $pager->init();
     sfContext::getInstance()->getLogger()->info('got starred pager');
     return $pager;
 }
Пример #3
0
 public static function retrieveByPKs($pks, $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(self::DATABASE_NAME);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria();
         $criteria->add(StarPeer::ID, $pks, Criteria::IN);
         $objs = StarPeer::doSelect($criteria, $con);
     }
     return $objs;
 }