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