Fixed : Collection rating
Fixed : Sql Queries of view collection
This commit is contained in:
parent
cab4042f5a
commit
2661c4ea63
8 changed files with 140 additions and 9 deletions
|
@ -83,6 +83,15 @@ if(!empty($mode))
|
|||
$cbvid->show_video_rating($result);
|
||||
}
|
||||
break;
|
||||
case "collection":
|
||||
{
|
||||
$rating = $_POST['rating']*2;
|
||||
$id = $_POST['id'];
|
||||
$result = $cbcollection->rate_collection($id,$rating);
|
||||
$result['is_rating'] = true;
|
||||
$cbvid->show_video_rating($result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -952,6 +961,15 @@ if(!empty($mode))
|
|||
}
|
||||
break;
|
||||
|
||||
|
||||
case "viewCollectionRating":
|
||||
{
|
||||
$cid = mysql_clean($_POST['cid']);
|
||||
$returnedArray = $cbcollection->collection_voters($cid);
|
||||
echo ($returnedArray);
|
||||
}
|
||||
break;
|
||||
|
||||
case "loadAjaxPhotos":
|
||||
{
|
||||
$photosType = $_POST['photosType'];
|
||||
|
@ -1032,5 +1050,4 @@ if(!empty($mode))
|
|||
}else
|
||||
header('location:'.BASEURL);
|
||||
|
||||
|
||||
?>
|
|
@ -67,4 +67,6 @@ $pages->paginate($total_pages,$page);
|
|||
subtitle(lang('channels'));
|
||||
template_files('channels.html');
|
||||
display_it();
|
||||
|
||||
|
||||
?>
|
|
@ -218,6 +218,7 @@ class ADODB_mysql extends ADOConnection {
|
|||
$this->num_rows = $data->_numOfRows;
|
||||
$this->total_queries++;
|
||||
$this->total_queries_sql[] = $query;
|
||||
|
||||
//Now Get Rows and return that data
|
||||
if($this->num_rows > 0)
|
||||
return $data->getrows();
|
||||
|
|
|
@ -1248,6 +1248,115 @@ class Collections extends CBCategory
|
|||
return $this->get_default_thumb($size);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to display collection voterts details.
|
||||
* User who rated, how many stars and when user rated
|
||||
*/
|
||||
function collection_voters($id,$return_array=FALSE,$show_all=FALSE)
|
||||
{
|
||||
global $json;
|
||||
$c= $this->get_collection($id);
|
||||
if((!empty($c) && $c['userid'] == userid()) || $show_all === TRUE)
|
||||
{
|
||||
global $userquery;
|
||||
$voters = $c['voters'];
|
||||
if(phpversion() < "5.2.0")
|
||||
$voters = $json->json_decode($voters,TRUE);
|
||||
else
|
||||
$voters = json_decode($voters,TRUE);
|
||||
|
||||
if(!empty($voters))
|
||||
{
|
||||
if($return_array)
|
||||
return $voters;
|
||||
else
|
||||
{
|
||||
foreach($voters as $id=>$details)
|
||||
{
|
||||
$username = get_username($id);
|
||||
$output = "<li id='user".$id.$c['collection_id']."' class='PhotoRatingStats'>";
|
||||
$output .= "<a href='".$userquery->profile_link($id)."'>$username</a>";
|
||||
$output .= " rated <strong>". $details['rate']/2 ."</strong> stars <small>(";
|
||||
$output .= niceTime($details['time']).")</small>";
|
||||
$output .= "</li>";
|
||||
echo $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to get current rating
|
||||
*/
|
||||
function current_rating($id)
|
||||
{
|
||||
global $db;
|
||||
$result = $db->select(tbl('collections'),'allow_rating,rating,rated_by,voters'," collection_id = ".$id."");
|
||||
if($result)
|
||||
return $result[0];
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Used to rate photo
|
||||
*/
|
||||
function rate_collection($id,$rating)
|
||||
{
|
||||
global $db,$json;
|
||||
|
||||
if(!is_numeric($rating) || $rating < 1)
|
||||
$rating = 1;
|
||||
if($rating > 10)
|
||||
$rating = 10;
|
||||
|
||||
$c_rating = $this->current_rating($id);
|
||||
$voters = $c_rating['voters'];
|
||||
|
||||
$new_rate = $c_rating['rating'];
|
||||
$rated_by = $c_rating['rated_by'];
|
||||
|
||||
if(phpversion < '5.2.0')
|
||||
$voters = $json->json_decode($voters,TRUE);
|
||||
else
|
||||
$voters = json_decode($voters,TRUE);
|
||||
|
||||
if(!empty($voters))
|
||||
$already_voted = array_key_exists(userid(),$voters);
|
||||
|
||||
if(!userid())
|
||||
e(lang("please_login_to_rate"));
|
||||
elseif(!empty($already_voted))
|
||||
e(lang("you_hv_already_rated_photo"));
|
||||
elseif($c_rating['allow_rating'] == 'no' || config('photo_rating') != 1)
|
||||
e(lang("photo_rate_disabled"));
|
||||
else
|
||||
{
|
||||
$voters[userid()] = array('rate'=>$rating,'time'=>NOW());
|
||||
if(phpversion < '5.2.0')
|
||||
$voters = $json->json_encode($voters);
|
||||
else
|
||||
$voters = json_encode($voters);
|
||||
|
||||
$t = $c_rating['rated_by'] * $c_rating['rating'];
|
||||
$rated_by = $c_rating['rated_by'] + 1;
|
||||
$new_rate = ($t + $rating) / $rated_by;
|
||||
$db->update(tbl('collections'),array('rating','rated_by','voters'),
|
||||
array("$new_rate","$rated_by","|no_mc|$voters"),
|
||||
" collection_id = ".$id."");
|
||||
|
||||
e(lang("thnx_for_voting"),"m");
|
||||
}
|
||||
|
||||
$return = array("rating"=>$new_rate,"rated_by"=>$rated_by,'total'=>10,"id"=>$id,"type"=>"photo","disabled"=>"disabled");
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function used generate collection link
|
||||
*/
|
||||
|
@ -1346,7 +1455,7 @@ class Collections extends CBCategory
|
|||
* Function used return collection links
|
||||
*/
|
||||
function collection_links($details,$type=NULL)
|
||||
{
|
||||
{
|
||||
if(is_array($details))
|
||||
{
|
||||
if(empty($details['collection_id']))
|
||||
|
@ -1376,8 +1485,11 @@ class Collections extends CBCategory
|
|||
else
|
||||
return BASEURL."/view_collection.php?cid=".$cdetails['collection_id']."&type=".$cdetails['type'];
|
||||
} elseif($type == "vi" || $type == "view_item" ||$type == "item") {
|
||||
$item_type = $this->get_collection_field($cdetails['collection_id'],'type');
|
||||
|
||||
//$item_type = $this->get_collection_field($cdetails['collection_id'],'type');
|
||||
if($cdetails['videoid'])
|
||||
$item_type = 'videos';
|
||||
else
|
||||
$item_type = 'photos';
|
||||
switch($item_type)
|
||||
{
|
||||
case "videos":
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
<h2 class="title" style="font-family:Tahoma;"><a href="{$cbcollection->collection_links($collection,'view')}">{$collection.collection_name|truncate:30}</a></h2>
|
||||
<p class="vid_info">{$collection.views} {lang code="views"}</p>
|
||||
<p class="vid_info"><a href="{$userquery->profile_link($collection)}" title="{$collection.username}">{$collection.username|truncate:16}</a></p>
|
||||
{assign var=rating value=$cbcollection->collection_rating($collection.collection_id,$collection.type)}
|
||||
<div class="CollectionRating">{show_rating class='rating' rating=$rating total='10'}</div>
|
||||
|
||||
<div class="CollectionRating">{show_rating class='rating' rating=$collection.rating ratings=$collection.rated_by total='10'}</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
<div class="video_actions_cont clearfix">
|
||||
{assign var=rating value=$cbcollection->collection_rating($c.collection_id,$c.type)}
|
||||
<div class="rating_container">
|
||||
{show_rating class='viewCollectionRating' rating=$rating total='10'}
|
||||
{show_video_rating rating=$c.rating ratings=$c.rated_by total='10' id=$c.collection_id type=collection}
|
||||
<div style="text-align:center; font:normal 10px Tahoma;" title="Collection rating is based on it's objects average rating.">How we calculate rating ?</div>
|
||||
</div>
|
||||
<div class="actions clearfix" style="float:left; margin:8px 0 0 15px; padding:0px;">
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<div style="height:10px;"></div>
|
||||
<div class="video_actions_cont clearfix">
|
||||
<div class="rating_container">
|
||||
{show_video_rating rating=$photo.rating ratings=$photo.rated_by total='10' id=$photo.photo_id type=photo}
|
||||
{show_rating rating=$photo.rating ratings=$photo.rated_by total='10' id=$photo.photo_id type=photo}
|
||||
</div>
|
||||
<div style="float:left; margin-left:5px;" class="actions clearfix">
|
||||
<ul>
|
||||
|
|
|
@ -70,5 +70,4 @@ if($cbcollection->is_viewable($c))
|
|||
|
||||
template_files('view_collection.html');
|
||||
display_it();
|
||||
|
||||
?>
|
Loading…
Add table
Reference in a new issue