Example #1
0
 /**
  * Add/remove record if $props['liked'] is TRUE
  * @param array $props
  * @return bool TRUE for success operation
  */
 public static function likeItem($props)
 {
     if ($props['liked']) {
         return self::destroy($props['id']);
     } else {
         $record = new GhContributorModel();
         $record->username = $props['name'];
         $record->ghuser_id = cur_gh_user_id;
         return $record->save();
     }
 }
Example #2
0
 /**
  * Add/Delete record if like-button
  */
 public function changeLikeStatus()
 {
     if (!Request::ajax()) {
         return false;
     }
     $properties = array('table' => $_POST['datatype'], 'id' => $_POST['id'], 'name' => $_POST['name'], 'liked' => $_POST['liked']);
     if ($properties['table'] == 'user') {
         $result = GhContributorModel::likeItem($properties);
     } else {
         $result = GhRepoModel::likeItem($properties);
     }
     return \View::make('ghpb::parts.btn_star')->with(array('text' => $properties['liked'] ? 'Like' : 'Unlike'));
 }