Example #1
0
function saveVote($option)
{
    global $rsgConfig, $mainframe;
    $database = JFactory::getDBO();
    $my = JFactory::getUser();
    if ($rsgConfig->get('voting') < 1) {
        $mainframe->redirect(JRoute::_("index.php?option=com_rsgallery2"), JText::_('Voting is disabled!'));
    } else {
        $rating = rsgInstance::getInt('rating', '');
        $id = rsgInstance::getInt('id', '');
        $vote = new rsgVoting();
        //Check if user can vote
        if (!$vote->voteAllowed()) {
            $mainframe->redirect(JRoute::_("index.php?option=com_rsgallery2&page=inline&id={$id}"), JText::_('You are not authorized to vote!'));
        }
        //Check if user has already voted for this image
        if ($vote->alreadyVoted($id)) {
            $mainframe->redirect(JRoute::_("index.php?option=com_rsgallery2&page=inline&id={$id}"), JText::_('You already voted for this item!'));
        }
        //All checks OK, store vote in DB
        $total = $vote->getTotal($id) + $rating;
        $votecount = $vote->getVoteCount($id) + 1;
        $sql = "UPDATE #__rsgallery2_files SET rating = '{$total}', votes = '{$votecount}' WHERE id = '{$id}'";
        $database->setQuery($sql);
        if (!$database->query()) {
            $msg = JText::_('Vote could not be added to the database!');
        } else {
            $msg = JText::_('Vote added to database!');
            //Store cookie on system
            setcookie($rsgConfig->get('cookie_prefix') . $id, $my->id, time() + 60 * 60 * 24 * 365, "/");
        }
        $mainframe->redirect(JRoute::_("index.php?option=com_rsgallery2&page=inline&id={$id}"), $msg);
    }
}
 function calculateAverage($id)
 {
     if (rsgVoting::getVoteCount($id) > 0) {
         $avg = rsgVoting::getTotal($id) / rsgVoting::getVoteCount($id);
         $value = round($avg * 2, 0) / 2;
         return $value;
     } else {
         return 0;
     }
 }
Example #3
0
 /**
  * Shows the voting screen
  */
 function _showVotes()
 {
     global $mainframe, $rsgConfig, $rsgAccess;
     $gallery = rsgGalleryManager::get();
     $vote_view = $rsgConfig->get('voting') && ($rsgAccess->checkGallery("vote_view", $gallery->id) || $rsgAccess->checkGallery("vote_vote", $gallery->id));
     if ($vote_view) {
         $css = "<link rel=\"stylesheet\" href=\"" . JURI_SITE . "/components/com_rsgallery2/lib/rsgvoting/rsgvoting.css\" type=\"text/css\" />";
         $mainframe->addCustomHeadTag($css);
         $voting = new rsgVoting();
         if ($rsgAccess->checkGallery("vote_view", $gallery->id)) {
             $voting->showScore();
         }
         if ($rsgAccess->checkGallery("vote_vote", $gallery->id)) {
             $voting->showVoting();
         }
     } else {
         echo JText::_('Voting is disabled!');
     }
 }
Example #4
0
	<table border="0" width="200">
	<tr>
		<td><?php 
echo JText::_('Rating');
?>
:</td>
		<td><?php 
echo rsgVoting::calculateAverage($id);
?>
&nbsp;/&nbsp;<?php 
echo rsgVoting::getVoteCount($id);
?>
&nbsp;<?php 
echo JText::_('votes');
?>
</td>
   	</tr>
	</table>