/**
  * Return a hash with a list of ids of objects bookmarked (+|-) by a user
  * bookmarked_ids = array('OppAtto' => array(1, 15, 143), ...);
  *
  * @param  char(1)     +|- type of bookmarking
  * @param  mixed       $user_id  User primary key
  * @return array (see description)
  **/
 private static function _getAllBookmarkedIds($type, $user_id)
 {
     if ($type != '+' && $type != '-') {
         throw new deppPropelActAsBookmarkableException('Type can only be + or -');
     }
     if (is_null($user_id) or trim((string) $user_id) === '') {
         throw new deppPropelActAsBookmarkableException('Impossible to clear a user bookmarking with no user primary key provided');
     }
     $bookmarked_ids = array();
     $c = new Criteria();
     $c->add(sfBookmarkingPeer::USER_ID, $user_id);
     $c->add(sfBookmarkingPeer::BOOKMARKING, $type == '+' ? 1 : -1);
     $c->clearSelectColumns();
     $c->addSelectColumn(sfBookmarkingPeer::BOOKMARKABLE_MODEL);
     $c->addSelectColumn(sfBookmarkingPeer::BOOKMARKABLE_ID);
     $rs = sfBookmarkingPeer::doSelectRS($c);
     while ($rs->next()) {
         $key = $rs->getString(1);
         if (!array_key_exists($key, $bookmarked_ids)) {
             $bookmarked_ids[$key] = array();
         }
         array_push($bookmarked_ids[$key], $rs->getInt(2));
     }
     return $bookmarked_ids;
 }
 public function executeActsForType()
 {
     $this->type_id = $this->type->getId();
     $this->type_denominazione = $this->type->getDescrizione();
     // filtri per ramo e stato avanzamento
     $act_filtering_criteria = null;
     if ($this->filters['act_ramo'] != '0') {
         if (is_null($act_filtering_criteria)) {
             $act_filtering_criteria = new Criteria();
         }
         $act_filtering_criteria->add(OppAttoPeer::RAMO, $this->filters['act_ramo']);
     }
     if ($this->filters['act_stato'] != '0') {
         if (is_null($act_filtering_criteria)) {
             $act_filtering_criteria = new Criteria();
         }
         $act_filtering_criteria->add(OppAttoPeer::STATO_COD, $this->filters['act_stato']);
     }
     $blocked_items_pks = sfBookmarkingPeer::getAllNegativelyBookmarkedIds($this->user_id);
     if (array_key_exists('OppAtto', $blocked_items_pks)) {
         if (is_null($act_filtering_criteria)) {
             $act_filtering_criteria = new Criteria();
         }
         $blocked_acts_pks = $blocked_items_pks['OppAtto'];
         $act_filtering_criteria->add(OppAttoPeer::ID, $blocked_acts_pks, Criteria::NOT_IN);
     }
     $indirectly_monitored_acts = OppAttoPeer::doSelectIndirectlyMonitoredByUser($this->user, $this->type, $this->tag_filtering_criteria, $this->my_monitored_tags_pks, $act_filtering_criteria);
     if ($this->filters['tag_id'] == '0') {
         $directly_monitored_acts = OppAttoPeer::doSelectDirectlyMonitoredByUser($this->user, $this->type, $act_filtering_criteria);
     } else {
         $directly_monitored_acts = array();
     }
     $monitored_acts = OppAttoPeer::merge($indirectly_monitored_acts, $directly_monitored_acts);
     $this->n_total_acts = count($monitored_acts);
     if ($this->filters['act_type_id'] == 0) {
         $monitored_acts = array_slice($monitored_acts, 0, sfConfig::get('app_monitored_acts_per_type_limit'));
     }
     $this->monitored_acts = $monitored_acts;
 }
 /**
  * Deletes all bookmarking for a bookmarkable object (delete cascade emulation)
  * 
  * @param  BaseObject  $object
  */
 public function preDelete(BaseObject $object)
 {
     try {
         $c = new Criteria();
         $c->add(sfBookmarkingPeer::BOOKMARKABLE_ID, $object->getBookmarkableReferenceKey());
         sfBookmarkingPeer::doDelete($c);
     } catch (Exception $e) {
         throw new deppPropelActAsBookmarkableException('Unable to delete bookmarkable object related bookmarkings records');
     }
 }
 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(sfBookmarkingPeer::ID, $pks, Criteria::IN);
         $objs = sfBookmarkingPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 public function executeBlockedActs()
 {
     // embed javascripts for advanced javascripts
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('jquery.js');
     // calcola l'utente e l'id
     $this->user_id = $this->getUser()->getId();
     $this->user = OppUserPeer::retrieveByPK($this->user_id);
     // estrae gli atti favoriti
     $this->blocked_acts = sfBookmarkingPeer::getAllNegativelyBookmarked($this->user_id);
 }
$t->ok($obj1->hasBeenNegativelyBookmarked($user_2_id) == true, 'hasBeenNegativelyBookmarked() - obj1 was negatively bookmarked by user 1');
$t->ok($obj1->hasBeenNegativelyBookmarked($user_3_id) == false, 'hasBeenNegativelyBookmarked() - obj1 was NOT negatively bookmarked by user 1');
$t->diag('List of bookmarked objects');
$bookmarked_ids = sfBookmarkingPeer::getAllPositivelyBookmarkedIds($user_1_id);
$t->ok($bookmarked_ids[TEST_CLASS][0] == $obj1->getId(), 'sfBookmarkingPeer::getAllPositivelyBookmarkedIds() - is working');
$bookmarked_ids = sfBookmarkingPeer::getAllPositivelyBookmarkedIds($user_2_id);
$t->ok($bookmarked_ids == array(), 'sfBookmarkingPeer::getAllPositivelyBookmarkedIds() - empty case scenario');
$bookmarked_ids = sfBookmarkingPeer::getAllNegativelyBookmarkedIds($user_2_id);
$t->ok($bookmarked_ids[TEST_CLASS][0] == $obj1->getId(), 'sfBookmarkingPeer::getAllNegativelyBookmarkedIds() - is working');
$bookmarked_ids = sfBookmarkingPeer::getAllNegativelyBookmarkedIds($user_1_id);
$t->ok($bookmarked_ids == array(), 'sfBookmarkingPeer::getAllNegativelyBookmarkedIds() - empty case scenario');
$bookmarked_objs = sfBookmarkingPeer::getAllPositivelyBookmarked($user_1_id);
$t->ok($bookmarked_objs[0] == $obj1, 'sfBookmarkingPeer::getAllPositivelyBookmarked() - is working');
$bookmarked_objs = sfBookmarkingPeer::getAllNegativelyBookmarked($user_2_id);
$t->ok($bookmarked_objs[0] == $obj1, 'sfBookmarkingPeer::getAllNegativelyBookmarked() - is working');
$bookmarked_objs = sfBookmarkingPeer::getAllPositivelyBookmarked($user_2_id);
$t->ok($bookmarked_objs == array(), 'sfBookmarkingPeer::getAllPositivelyBookmarked() - empty case');
$t->diag('List of some toolkit methods');
$t->ok(deppPropelActAsBookmarkableToolkit::isBookmarkable(TEST_CLASS) == true, 'deppPropelActAsBookmarkableToolkit::isBookmarkable() - is working');
$t->diag('Tests terminated');
// test object creation
function _create_object()
{
    $classname = TEST_CLASS;
    $method = TEST_METHOD_SETTER;
    if (!class_exists($classname)) {
        throw new Exception(sprintf('Unknow class "%s"', $classname));
    }
    $obj = new $classname();
    // set a field to set the status of the object to isModified and have the doSave() function work
    $obj->{$method}('Trial value');
 public static function getTodayNewsForUserCriteria($user, $date = null)
 {
     $monitored_objects = $user->getMonitoredObjects();
     // criterio di selezione delle news dagli oggetti monitorati
     $c = self::getMyMonitoredItemsNewsCriteria($monitored_objects);
     // eliminazione delle notizie relative agli oggetti bookmarkati negativamente (bloccati)
     $blocked_items_ids = sfBookmarkingPeer::getAllNegativelyBookmarkedIds($user->getId());
     if (array_key_exists('OppAtto', $blocked_items_ids) && count($blocked_items_ids['OppAtto'])) {
         $blocked_news_ids = array();
         $bc = new Criteria();
         $bc->add(self::RELATED_MONITORABLE_MODEL, 'OppAtto');
         $bc->add(self::RELATED_MONITORABLE_ID, $blocked_items_ids['OppAtto'], Criteria::IN);
         $bc->clearSelectColumns();
         $bc->addSelectColumn(self::ID);
         $rs = self::doSelectRS($bc);
         while ($rs->next()) {
             array_push($blocked_news_ids, $rs->getInt(1));
         }
         $c0 = $c->getNewCriterion(self::ID, $blocked_news_ids, Criteria::NOT_IN);
         $c->addAnd($c0);
     }
     // le news di gruppo non sono considerate, perché ridondanti (#247)
     $c->add(self::GENERATOR_PRIMARY_KEYS, null, Criteria::ISNOTNULL);
     // add a filter on the date (today's news) or a test date
     // remove news related to actions dated more than 15 days ago (related to the date passed)
     if (is_null($date)) {
         $date = date('Y-m-d');
     }
     # some dates
     $default_time = sfConfig::get('app_default_newsletter_sendtime', '12:45:00');
     $date_noon = date("Y-m-d {$default_time}", strtotime($date));
     $date_noon_minus_24 = date("Y-m-d {$default_time}", strtotime('1 day ago', strtotime($date)));
     $fifteen_days_ago = date('Y-m-d', strtotime('15 days ago', strtotime($date)));
     # today's news are last 24 hours news, starting at 12:45:00
     $crit0 = $c->getNewCriterion(self::CREATED_AT, $date_noon, Criteria::LESS_EQUAL);
     $crit1 = $c->getNewCriterion(self::CREATED_AT, $date_noon_minus_24, Criteria::GREATER_THAN);
     $crit0->addAnd($crit1);
     $c->add($crit0);
     # check date, if present
     $crit0 = $c->getNewCriterion(self::DATE, null, Criteria::ISNOTNULL);
     $crit1 = $c->getNewCriterion(self::DATE, $fifteen_days_ago, Criteria::GREATER_THAN);
     $crit0->addAnd($crit1);
     # check data_presentazione_atto, if present
     $crit2 = $c->getNewCriterion(self::DATA_PRESENTAZIONE_ATTO, null, Criteria::ISNOTNULL);
     $crit3 = $c->getNewCriterion(self::DATA_PRESENTAZIONE_ATTO, $fifteen_days_ago, Criteria::GREATER_THAN);
     $crit2->addAnd($crit3);
     # perform OR
     $crit0->addOr($crit2);
     # add orred criterion to main criteria
     $c->add($crit0);
     return $c;
 }