/**
  * pre-execution: 
  *  - get the request parameters, 
  *  - check if the user has the 'right' to bookmark, 
  *  - prepare variables
  */
 public function preExecute()
 {
     $item_model = $this->getRequestParameter('item_model');
     $item_pk = $this->getRequestParameter('item_pk');
     $this->user_id = deppPropelActAsBookmarkableToolkit::getUserId();
     $user = OppUserPeer::retrieveByPK($this->user_id);
     $this->item = deppPropelActAsBookmarkableToolkit::retrieveBookmarkableObject($item_model, $item_pk);
 }
 /**
  * pre-execution: 
  *  - get the request parameters, 
  *  - check if the user has the 'right' to bookmark, 
  *  - prepare variables
  */
 public function preExecute()
 {
     $item_model = $this->getRequestParameter('item_model');
     $item_pk = $this->getRequestParameter('item_pk');
     $this->user_id = deppPropelActAsBookmarkableToolkit::getUserId();
     $user = OppUserPeer::retrieveByPK($this->user_id);
     $this->item = deppPropelActAsBookmarkableToolkit::retrieveBookmarkableObject($item_model, $item_pk);
     // go to error page if user is not monitoring the object (security)
     $this->forward404Unless($user->isMonitoring($item_model, $item_pk) || $user->isIndirectlyMonitoringAct($item_pk) || $this->item->hasBeenPositivelyBookmarked($this->user_id));
     // an object was bookmarked, clear the acts cache
     $cacheManager = $this->getContext()->getViewCacheManager();
     $user_token = $this->getUser()->getToken();
     if (!is_null($cacheManager)) {
         $cacheManager->remove('monitoring/acts?user_token=' . $user_token);
     }
 }
 /**
  * Return an array of objects bookmarked (+|-) by a user
  *
  * @param  char(1)     +|- type of bookmarking
  * @param  mixed       $user_id  User primary key
  * @return array of Bookmarkable objects
  **/
 private static function _getAllBookmarked($bookmarking_type, $user_id)
 {
     if ($bookmarking_type != '+' && $bookmarking_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_objects = array();
     $bookmarked_ids = self::_getAllBookmarkedIds($bookmarking_type, $user_id);
     foreach ($bookmarked_ids as $model => $ids) {
         foreach ($ids as $id) {
             $bookmarked_objects[] = deppPropelActAsBookmarkableToolkit::retrieveBookmarkableObject($model, $id);
         }
     }
     return $bookmarked_objects;
 }
function depp_positive_bookmarker($object, $domid = 'depp-positive-bookmarker-block', $message = '', $options = array())
{
    if (is_null($object)) {
        sfLogger::getInstance()->debug('A NULL object cannot be bookmarked');
        return '';
    }
    $user_id = deppPropelActAsBookmarkableToolkit::getUserId();
    // anonymous bookmarks
    if ((is_null($user_id) || $user_id == '') && !$object->allowsAnonymousBookmarking()) {
        sfLogger::getInstance()->debug('anonymous bookmarking not allowed');
        return '';
    }
    $options = _parse_attributes($options);
    if (!isset($options['id'])) {
        $options = array_merge($options, array('id' => 'bookmarking-items'));
    }
    // already bookmarked
    if ($object->hasBeenPositivelyBookmarked($user_id)) {
        $message .= " " . link_to_remote(__('Remove from favourites'), array('url' => sprintf('deppBookmarking/ajaxPositiveUnbookmark?model=%s&id=%d', get_class($object), $object->getBookmarkableReferenceKey()), 'update' => $domid, 'script' => true, 'complete' => visual_effect('appear', $domid) . visual_effect('highlight', $domid)));
    } else {
        $message .= ' ' . link_to_remote(__('Add to favourites'), array('url' => sprintf('deppBookmarking/ajaxPositiveBookmark?model=%s&id=%d', get_class($object), $object->getBookmarkableReferenceKey()), 'update' => $domid, 'script' => true, 'complete' => visual_effect('appear', $domid) . visual_effect('highlight', $domid)));
    }
    return $message;
}
$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');
    return $obj;
}