Ejemplo n.º 1
0
 function launch()
 {
     global $interface;
     global $configArray;
     if (isset($_REQUEST['rating'])) {
         $rating = $_REQUEST['rating'];
         $interface->assign('rating', $rating);
     }
     $id = $_REQUEST['id'];
     // Check if user is logged in
     if (!$this->user) {
         // Needed for "back to record" link in view-alt.tpl:
         $interface->assign('id', $id);
         //Display the login form
         $login = $interface->fetch('EContentRecord/ajax-rate-login.tpl');
         header('Content-type: text/plain');
         header('Cache-Control: no-cache, must-revalidate');
         // HTTP/1.1
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         echo json_encode(array('result' => 'true', 'loginForm' => $login));
         exit;
     }
     if (isset($_GET['submit'])) {
         //Save the rating
         require_once ROOT_DIR . '/sys/eContent/EContentRating.php';
         $eContentRating = new EContentRating();
         $eContentRating->rating = $rating;
         $eContentRating->recordId = $id;
         $eContentRating->userId = $this->user->id;
         $eContentRating->dateRated = time();
         $eContentRating->insert();
         return json_encode(array('result' => 'true', 'rating' => $rating));
     }
 }
Ejemplo n.º 2
0
 function RateTitle()
 {
     require_once ROOT_DIR . '/sys/eContent/EContentRating.php';
     global $user;
     if (!isset($user) || $user == false) {
         header('HTTP/1.0 500 Internal server error');
         return 'Please login to rate this title.';
     }
     $ratingValue = $_REQUEST['rating'];
     //Save the rating
     $rating = new EContentRating();
     $rating->recordId = $_REQUEST['id'];
     $rating->userId = $user->id;
     $existingRating = false;
     if ($rating->find(true) >= 1) {
         $existingRating = true;
     }
     $rating->rating = $ratingValue;
     $rating->dateRated = time();
     if ($existingRating) {
         $rating->update();
     } else {
         $rating->insert();
     }
     return $ratingValue;
 }