/** * 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); } }
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; }