Esempio n. 1
0
 /**
  * Counts stars made by a given user.
  * 
  * @param  int  $user_id
  * @return int
  */
 public static function countUserStars($user_id = null)
 {
     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);
     return StarPeer::doCount($c);
 }
Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 4
0
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = StarPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setStarredModel($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setStarredId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setUserId($arr[$keys[3]]);
     }
 }
$app = substr($apps_dir[0], strrpos($apps_dir[0], DIRECTORY_SEPARATOR) + 1, strlen($apps_dir[0]));
if (!$app) {
    throw new Exception('No app has been detected in this project');
}
require_once $sf_root_dir . '/test/bootstrap/functional.php';
require_once $sf_symfony_lib_dir . '/vendor/lime/lime.php';
if (!defined('TEST_CLASS') || !class_exists(TEST_CLASS)) {
    // Don't run tests
    return;
}
// initialize database manager
$databaseManager = new sfDatabaseManager();
$databaseManager->initialize();
$con = Propel::getConnection();
// clean the database
StarPeer::doDeleteAll();
call_user_func(array(_create_object()->getPeer(), 'doDeleteAll'));
// create a new test browser
$browser = new sfTestBrowser();
$browser->initialize();
// start tests
$t = new lime_test(8, new lime_output_color());
// these tests check for the counter consistency
$t->diag('counter consistency');
$object = _create_object();
$object->save();
$t->ok($object->getCounter() == 0, 'a new object has a null counter.');
$object->incrementCounter();
$t->ok($object->getCounter() == 1, 'after one increment, the counters value is 1.');
$rand = rand(1, 100);
$i = 0;
 /**
  * Deletes all stars for a Starred object
  * 
  * @param  BaseObject  $object
  */
 public function preDelete(BaseObject $object)
 {
     try {
         $c = new Criteria();
         $c->add(StarPeer::STARRED_MODEL, get_class($object));
         $c->add(StarPeer::STARRED_ID, $object->getPrimaryKey());
         StarPeer::doDelete($c);
     } catch (Exception $e) {
         throw new sfException('Unable to delete starred object related records');
     }
 }