*/ /** * This view handles calls from the javascript (AJAX) side and returns * data to the javascript by printing results. * * @package Rating */ class RatingCallbackView extends GalleryView { /** * @see GalleryView::isImmediate() */ function isImmediate() { return true; } /** * @see GalleryView::isImmediate() */ function renderImmediate($status, $error) { global $gallery; GalleryCoreApi::requireOnce('modules/rating/classes/RatingHelper.class'); list ($command, $itemId, $rating) = GalleryUtilities::getRequestVariables('command', 'itemId', 'rating'); list ($ret, $anonymousUserId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.anonymousUser'); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } if (!headers_sent()) { header("Content-type: text/plain; charset=UTF-8"); } switch($command) { case 'rate': list ($ret, $permission) = GalleryCoreApi::hasItemPermission($itemId, 'rating.add'); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } if (!$permission) { return null; } list ($ret, $results) = RatingHelper::rateItem($itemId, (int)$rating, $gallery->getActiveUserId()); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } print $results['itemId'] . "\n" . $results['rating'] . "\n" . $results['votes'] . "\n" . $results['userRating']; break; } return null; } } ?>