Skip to content

Commit

Permalink
don't show ratableui on objects that don't exist. Fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
sheadawson committed Aug 28, 2015
1 parent 56d5b20 commit e34e3e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion code/controllers/RateableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function rate($request){
}

// check the object exists
if(!$object && !$object->EnableRatings){
if(!$object && !$object->checkRatingsEnabled()){
return Convert::raw2json(array(
'status' => 'error',
'message' => _t('RateableController.ERRORNOTFOUNT', 'Sorry, the item you are trying to rate could not be found')
Expand Down
11 changes: 10 additions & 1 deletion code/extensions/Rateable.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function UserHasRated(){
* @return String
**/
public function RateableUI($htmlIdPostfix = false){
if(!$this->owner->EnableRatings) return;
if(!$this->owner->checkRatingsEnabled()) return;

$this->htmlIdPostfix = $htmlIdPostfix;

Expand Down Expand Up @@ -129,6 +129,15 @@ public function getRatingCSSClass(){

return implode(' ', $parts);
}


/**
* Checks whether ratings should be enabled on this object
* @return Boolean
**/
public function checkRatingsEnabled(){
return $this->owner->EnableRatings && $this->owner->ID > 0;
}


/**
Expand Down

0 comments on commit e34e3e4

Please sign in to comment.