function dislike($secret_id, $user_id) { $l_ = new Like(); $l = $l_->where("secret_id = {$secret_id} and user_id = {$user_id}"); $l[0]->drop(); return 1; }
function get_likes(&$secrets) { $L = new Like(); for ($i = 0; $i < count($secrets); $i++) { $secrets[$i]["likes"] = $L->find_by("secret_id", $secrets[$i]["id"], false); //$Like->find_by("secret_id", $secrets[$i]["id"]), false); } }
public static function set($owner, $type, $user_id) { $l = new Like(); $l->owner = $owner; $l->type = $type; $l->user = $user_id; $l->time = sql_datetime(time()); $l->store(); }
public function actionIndex() { $product_id = intval($_REQUEST['id']); $pInfo = Product::model()->getProductInfoById($product_id); if (empty($pInfo)) { $this->redirect('/?from=no_goods'); //跳转到首页 } $brandInfo = ''; if ($pInfo['brand_id']) { $brandInfo = Brand::model()->findByPk($pInfo['brand_id']); } $stock = Product::model()->getProductStock($product_id, $pInfo['is_multiple']); $attrList = ProductAttributes::model()->getProductAttrNameList(); $extendAttrList = ProductExtend::model()->getProductExtendAttrs($product_id); $is_like = Like::model()->getLikeStatus($this->user_id, $product_id); $cake = Category::model()->getCakeLine($pInfo['cat_id']); //获取商品的面包屑 $viewData = array(); $viewData['pInfo'] = $pInfo; $viewData['brandInfo'] = $brandInfo; $viewData['is_like'] = $is_like; $viewData['cake'] = $cake; $viewData['stock'] = $stock; $viewData['attrList'] = $attrList; $viewData['extendAttrList'] = $extendAttrList; $this->render('item/index', $viewData); }
public static function deleteLike($rating_id) { $error_code = ApiResponse::OK; $user_id = Session::get('user_id'); if (Rating::where('id', $rating_id)->first()) { $like = Like::where('rating_id', $rating_id)->where('user_id', $user_id)->first(); if ($like) { //update like_count on rating $like_rating = Rating::where('id', $like->rating_id)->first(); if ($like_rating != null) { $like_rating->like_count = $like_rating->like_count - 1; $like_rating->save(); } $like->delete(); $data = 'Like deleted'; } else { $error_code = ApiResponse::NOT_EXISTED_LIKE; $data = ApiResponse::getErrorContent(ApiResponse::NOT_EXISTED_LIKE); } } else { $error_code = ApiResponse::UNAVAILABLE_RATING; $data = ApiResponse::getErrorContent(ApiResponse::UNAVAILABLE_RATING); } return array("code" => $error_code, "data" => $data); }
public static function delete($entry_id) { $likes = Like::where('entry_id', $entry_id)->get(); foreach ($likes as $like) { $like->delete(); } return true; }
public function __construct($data) { $guid = $data['guid']; if (LikesPlugin::loggedInUserHasLiked($guid)) { die; } $entity = getEntity($guid); $owner_guid = $entity->owner_guid; $owner = getEntity($owner_guid); $like = new Like(); $like->container_guid = $guid; $like->owner_guid = getLoggedInUserGuid(); $like->save(); new Activity(getLoggedInUserGuid(), "activity:like", array(getLoggedInUser()->getURL(), getLoggedInUser()->full_name, $owner->getURL(), $owner->full_name, $entity->getURL(), translate($entity->type))); notifyUser("like", $guid, getLoggedInUserGuid(), $owner_guid); die; }
public function getLike($slug) { $json_data = array('liked' => false); $product = Product::where('slug', '=', $slug)->first(); $user = Auth::user(); $like = Like::where('product_id', '=', $product->id)->where('user_id', '=', $user->id)->first(); if (empty($like)) { $new_like = new Like(); $new_like->product_id = $product->id; $new_like->user_id = $user->id; $new_like->save(); $json_data['liked'] = true; } if (Request::ajax()) { return Response::json($json_data); } return Redirect::back(); }
function remove($item_id) { $like = Like::get_by_user_item($_SESSION['user_id'], $item_id); $like->remove(); if (isset($this->plugins->log)) { $this->plugins->log->add($_SESSION['user_id'], 'like', $like->id, 'remove'); } $this->show($item_id); }
public function updateRank() { $likes = Like::where('comment_id', '=', $this->id)->get(); $rank = 0; foreach ($likes as $like) { $rank += $like->value; } $this->rank = $rank; $this->save(); }
public function getpost($id) { $result = Yii::app()->db->createCommand()->setText('SELECT a.*,b.nickName,b.portrait,b.title,c.name as companyName,d.name as location from post a LEFT JOIN user b on b.id = a.userId left join company c on c.id = b.company left join hub d on d.id = b.location where a.status=1 and a.id=' . $id)->queryRow(); $item = Like::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'postId' => $result['id'], 'status' => 1)); $result['islike'] = $item ? 1 : 0; $result['likeId'] = $item->id; $likelist = Yii::app()->db->createCommand()->setText('select b.portrait,b.nickName,b.id as userId,b.title,c.name as companyName,d.name as locationName from `like` a left join user b on a.userId=b.id left join company c on c.id = b.company left join hub d on d.id=b.location where a.status=1 and a.postId=' . $id)->queryAll(); $commentlist = Yii::app()->db->createCommand()->setText('select b.id as userId,a.createTime,a.content,b.nickName,b.portrait,b.title,c.name as companyName,d.name as location from comment a left join user b on a.userId=b.id left join company c on b.company=c.id left join hub d on d.id=b.location where a.status=1 and a.postId=' . $id)->queryAll(); return array('code' => 200, 'mes' => 'success', 'data' => array('post' => $result, 'likelist' => $likelist, 'commentlist' => $commentlist)); }
public function liked($id) { $result = Like::model()->findByAttributes(array('id' => $id)); $result->status = 0; $post = Posts::model()->findByAttributes(array('id' => $result->postId)); $post->like_num--; if ($result->save() && $post->save()) { echo CJSON::encode(array('code' => 200, 'mes' => 'success', 'data' => array('postId' => $result->postId))); } }
/** * Delete all posts */ public function dispose() { // Delete posts $posts = ForumPost::find('all', ['conditions' => ['theme_id = ?', $this->id]]); foreach ($posts as $post) { $post->delete(); } // Delete likes Like::table()->delete('post = "topic' . $this->id . '"'); }
public function testGetTimelineSuccess() { $this->setUpRating(); $this->setUpCountry(); $this->setUpWineNote(); $this->setUpProfile(); $_params = $this->_params; $_params['user_id'] = "user_id"; $response = $this->_getAuth($_params); $error_code = ApiResponse::OK; $user_timeline = array(); $user_timeline[] = $this->_user_id; $user_follow = Follow::where('from_id', $this->_user_id)->orderBy('updated_at', 'asc')->get(); if (isset($user_follow)) { foreach ($user_follow as $user) { $user_timeline[] = $user->to_id; } } $pagination = ApiResponse::pagination(); $page = $pagination['page']; $limit = $pagination['limit']; $wine = Wine::with('winery')->forPage($page, $limit)->get(); $ratings = Rating::whereIn('user_id', $user_timeline)->whereNotNull('wine_unique_id')->with('profile')->with('wine')->forPage($page, $limit)->get(); foreach ($ratings as $rating) { $winery = Winery::where('id', $rating->wine->winery_id)->first(); $rating->winery = $winery; $country = Country::where('id', $rating->winery->country_id)->first(); $rating->winery->country_name = $country->country_name; $like = Like::where('user_id', $this->_user_id)->where('rating_id', $rating->id)->first(); if ($like) { $rating->liked = true; } else { $rating->liked = false; } $wishlist = Wishlist::where('user_id', $this->_user_id)->where('wine_unique_id', $rating->wine_unique_id)->first(); if ($wishlist) { $rating->wishlist = true; } else { $rating->wishlist = false; } if ($rating->wine->image_url != null) { $rating->wine->image_url = URL::asset($rating->wine->image_url); } if ($rating->wine->wine_flag != null) { $rating->wine->wine_flag = URL::asset($rating->wine->wine_flag); } if ($rating->profile->image != null) { $rating->profile->image = URL::asset($rating->profile->image); } $rating->winery = $rating->winery->toArray(); } $data = $ratings; $this->assertEquals(array("code" => ApiResponse::OK, "data" => $ratings->toArray()), json_decode($response->getContent(), true)); }
/** * Executes the widget. */ public function run() { $currentUserLiked = false; $likes = Like::GetLikes(get_class($this->object), $this->object->id); foreach ($likes as $like) { if ($like->getUser()->id == Yii::app()->user->id) { $currentUserLiked = true; } } $this->render('likeLink', array('likes' => $likes, 'currentUserLiked' => $currentUserLiked, 'id' => $this->object->getUniqueId())); }
/** * Store a newly created resource in storage. * * @return Response */ public function store(LikeRequest $request) { $input = $request->all(); if (Auth::guest()) { \Session::flash('flash_message', 'You need to be logged in to like/dislike!'); } else { $input['user_id'] = Auth::id(); Like::create($input); } $video = Video::findOrFail($input['video_id']); return view('videos/show', compact('video')); }
public function delete() { Shared_With::delete_content($this->content_id); Like::delete_content($this->content_id); Comment::delete_content($this->content_id); global $database; $sql = "DELETE FROM " . self::$table_name . " "; $sql .= "WHERE content_id=" . $database->escape_value($this->content_id); $sql .= " LIMIT 1"; $database->query($sql); return $database->affected_rows() == 1 ? true : false; }
/** * Like Count for specifc model */ public static function GetLikes($objectModel, $objectId) { $cacheId = "likes_" . $objectModel . "_" . $objectId; $cacheValue = Yii::app()->cache->get($cacheId); if ($cacheValue === false) { $newCacheValue = Like::model()->findAllByAttributes(array('object_model' => $objectModel, 'object_id' => $objectId)); Yii::app()->cache->set($cacheId, $newCacheValue, HSetting::Get('expireTime', 'cache')); return $newCacheValue; } else { return $cacheValue; } }
public function run() { DB::table('likes')->delete(); $user_id = User::where('email', '*****@*****.**')->first()->user_id; $user_1 = User::where('email', '*****@*****.**')->first()->user_id; $user_2 = User::where('email', '*****@*****.**')->first()->user_id; Like::create(array('id' => '1', 'rating_id' => '1', 'user_id' => $user_id)); Like::create(array('id' => '2', 'rating_id' => '2', 'user_id' => $user_id)); Like::create(array('id' => '3', 'rating_id' => '2', 'user_id' => $user_1)); Like::create(array('id' => '4', 'rating_id' => '3', 'user_id' => $user_1)); Like::create(array('id' => '5', 'rating_id' => '2', 'user_id' => $user_2)); Like::create(array('id' => '6', 'rating_id' => '1', 'user_id' => $user_2)); }
/** * On run of integrity check command, validate all module data * * @param type $event */ public static function onIntegrityCheck($event) { $integrityChecker = $event->sender; $integrityChecker->showTestHeadline("Validating Like Module (" . Like::model()->count() . " entries)"); foreach (Like::model()->findAll() as $l) { if ($l->source === null) { $integrityChecker->showFix("Deleting like id " . $l->id . " without existing target!"); if (!$integrityChecker->simulate) { $l->delete(); } } } }
public function actionRate($type, $object_id) { // $model = Yii::import("mod.comments.models.NestedComments"); $like = new Like(); $like->model = 'mod.comments.models.Comments'; $like->rate = $type; $like->object_id = $object_id; if ($like->validate()) { $modelClass = Yii::import("mod.comments.models.Comments"); $model = $modelClass::model()->findByPk($object_id); if ($type == 'up') { $model->like += 1; } elseif ($type == 'down') { $model->like -= 1; } $model->saveNode(); $like->save(false, false); $json = array('num' => $model->getLikes()); } else { $json = array('error' => 'error validate'); } echo CJSON::encode($json); }
public function store() { $entry_id = Input::get('entry_id'); $user_id = Session::get('user')['id']; $like_id = FELikesHelper::getId($entry_id, $user_id, false); if ($like_id) { $like = Like::find($like_id); $like->is_deleted = 0; $like->save(); $result = $like->toArray(); $result['status'] = 'success'; echo json_encode($result); } else { $like = new Like(); $like->entry_id = $entry_id; $like['user_id'] = $user_id; $like->is_deleted = 0; $like->save(); $result = $like->toArray(); $result['status'] = 'success'; echo json_encode($result); } }
/** * Returns a user list which contains all users who likes it */ public function actionUserList() { $page = (int) Yii::app()->request->getParam('page', 1); $total = Like::model()->count('object_model=:omodel AND object_id=:oid', array(':omodel' => $this->contentModel, 'oid' => $this->contentId)); $usersPerPage = HSetting::Get('paginationSize'); $sql = "SELECT u.* FROM `like` l " . "LEFT JOIN user u ON l.created_by = u.id " . "WHERE l.object_model=:omodel AND l.object_id=:oid AND u.status=" . User::STATUS_ENABLED . " " . "ORDER BY l.created_at DESC " . "LIMIT " . intval(($page - 1) * $usersPerPage) . "," . intval($usersPerPage); $params = array(':omodel' => $this->contentModel, ':oid' => $this->contentId); $pagination = new CPagination($total); $pagination->setPageSize($usersPerPage); $users = User::model()->findAllBySql($sql, $params); $output = $this->renderPartial('application.modules_core.user.views._listUsers', array('title' => Yii::t('LikeModule.controllers_LikeController', "<strong>Users</strong> who like this"), 'users' => $users, 'pagination' => $pagination), true); Yii::app()->clientScript->render($output); echo $output; Yii::app()->end(); }
public function load($iRecipeID) { $connection = new Connection(); $sSQL = "SELECT RecipeID, Title, AuthorNotes, Ingredients, Directions, ImagePath, CreatedAt, UserID, RecipeTypeID\n FROM tbrecipe\n WHERE RecipeID = " . $iRecipeID; $resultSet = $connection->query($sSQL); $row = $connection->fetch_array($resultSet); //store into attributes: $this->iRecipeID = $row["RecipeID"]; $this->sTitle = $row["Title"]; $this->sAuthorNotes = $row["AuthorNotes"]; $this->sIngredients = $row["Ingredients"]; $this->sDirections = $row["Directions"]; $this->sImagePath = $row["ImagePath"]; $this->tCreatedAt = $row["CreatedAt"]; $this->iUserID = $row["UserID"]; $this->iRecipeTypeID = $row["RecipeTypeID"]; // get all likes from recipe: $sSQL = "SELECT LikeID\n FROM tblike\n WHERE RecipeID = " . $iRecipeID; $resultSet = $connection->query($sSQL); while ($row = $connection->fetch_array($resultSet)) { $iLikeID = $row["LikeID"]; $oLike = new Like(); $oLike->load($iLikeID); $this->aLikes[] = $iLikeID; } // get all comments on a recipe: $sSQL = "SELECT CommentID\n FROM tbcomment\n WHERE RecipeID = " . $iRecipeID . " ORDER BY CreatedAt DESC"; $resultSet = $connection->query($sSQL); while ($row = $connection->fetch_array($resultSet)) { $iCommentID = $row["CommentID"]; $oComment = new Comment(); $oComment->load($iCommentID); $this->aComments[] = $oComment; } $connection->close_connection(); }
public static function list_all($limit = 10, $offset = 0) { global $mysqli; $config = new Config(); $sql = "SELECT `id` FROM `{$config->database->{$config->site_identifier}->prefix}likes` ORDER BY `date` DESC"; // Limit string $limit = sanitize_input($limit); $sql .= " LIMIT {$limit}"; // Offset string $offset = sanitize_input($offset); $sql .= " OFFSET {$offset}"; // Get likes $query = mysqli_query($mysqli, $sql); // Loop through likes, fetching objects $likes = array(); while ($query && ($result = mysqli_fetch_assoc($query))) { $likes[] = Like::get_by_id($result['id']); } return $likes; }
/** * Fire this notification on given like object * * @param type $comment */ public static function fire($like) { // Get Users which are also likes this model $userIds = array(); $otherLikes = Like::model()->findAllByAttributes(array('object_model' => $like->object_model, 'object_id' => $like->object_id)); foreach ($otherLikes as $otherLike) { if ($like->created_by == $otherLike->created_by) { continue; } // This user will also gets a "New Like" notification if ($like->source->created_by == $otherLike->created_by) { continue; } $userIds[] = $otherLike->created_by; } $userIds = array_unique($userIds); // Determine Space Id if exists $spaceId = ""; if ($like->content->container instanceof Space) { $spaceId = $like->content->container->id; } // Write new Notification for them foreach ($userIds as $userId) { $notification = new Notification(); $notification->class = "AlsoLikesNotification"; $notification->user_id = $userId; $notification->space_id = $spaceId; // Which object throws this notification? $notification->source_object_model = 'Like'; $notification->source_object_id = $like->id; // Which object gets this notifiction $notification->target_object_model = $like->object_model; $notification->target_object_id = $like->object_id; $notification->save(); } }
public static function getActivity() { $user_id = Session::get('user_id'); $error_code = ApiResponse::OK; $act = array(); $ratings = Rating::where('user_id', $user_id)->get(); foreach ($ratings as $rating) { $likes = Like::where('rating_id', $rating->id)->whereNotIn('user_id', [$user_id])->get(); if ($likes) { $title = 'like'; foreach ($likes as $like) { $act[] = Rating::getProfile($like->user_id, $title, $like->id, $rating->id, $like->updated_at); } } $comments = Comment::where('rating_id', $rating->id)->whereNotIn('user_id', [$user_id])->get(); if ($comments) { $title = 'comment'; foreach ($comments as $comment) { $act[] = Rating::getProfile($comment->user_id, $title, $comment->id, $rating->id, $comment->updated_at); } } $wishlists = Wishlist::where('wine_unique_id', $rating->wine_unique_id)->whereNotIn('user_id', [$user_id])->get(); if ($wishlists) { $title = 'wishlist'; foreach ($wishlists as $wishlist) { $act[] = Rating::getProfile($wishlist->user_id, $title, $wishlist->id, $rating->id, $wishlist->updated_at); } } } $user_follow = Follow::where('to_id', $user_id)->get(); if ($user_follow) { $title = 'follow'; foreach ($user_follow as $user) { $act[] = Rating::getProfile($user->from_id, $title, $user->id, null, $user->updated_at); } } $data = Rating::orderBy($act, 'updated_at'); return array("code" => $error_code, "data" => $data); }
public function voteComment() { $value = Input::get('value'); $comment_id = Input::get('comment_id'); $user_id = Auth::user()->id; $consecutive_same_vote = false; $comment = Comment::find($comment_id); //we don't want user making more then 1 vote up or down. //if vote is up and already up vote, then vote is converted to down and vice versa if ($value == 1) { $positive_likes = $comment->likes()->where('user_id', '=', $user_id)->where('value', '=', '1')->get(); if ($positive_likes->count()) { $positive_likes->first()->delete(); $consecutive_same_vote = true; } } else { if ($value == -1) { $negative_likes = $comment->likes()->where('user_id', '=', $user_id)->where('value', '=', '-1')->get(); if ($negative_likes->count()) { $negative_likes->first()->delete(); $consecutive_same_vote = true; } } } if (!$consecutive_same_vote) { $like = Like::create(array('value' => $value, 'user_id' => $user_id, 'comment_id' => $comment_id)); $like->save(); } //calculate rank $rank = $comment->likes()->sum('value'); $comment->rank = $rank; $comment->save(); if ($value == -1) { $count = $comment->likes()->where('value', '=', '-1')->get()->count(); } else { $count = $comment->likes()->where('value', '=', '1')->get()->count(); } //email notification if ($comment->user->rank_notice) { if ($value == -1) { $vote = " up "; } else { $vote = " down "; } $message = "You're comment has been voted"; $message .= $vote . "!\n "; if ($comment->parent_id != 0) { $parent_comment = $comment->parent; } else { $parent_comment = $comment; } $message .= str_replace(' ', '%20', 'http://iratepolitics.com/politicians/' . $parent_comment->politician->full_name . '/#' . $parent_comment->user->username . '-' . $parent_comment->id); $message .= "\n\n\nTo disable comment response, uncheck 'Receive email notice of up/down votes on my comments.' here: "; $message .= URL::route('edit-myprofile'); $subject = "Someone has voted" . $vote . "your comment!"; // message lines should not exceed 70 characters (PHP rule), so wrap it $message = wordwrap($message, 70); mail($parent_comment->user->email, $subject, $message, "From: contact@iratepolitics.com\n"); } //return $count;//rand(1,10); //from old arangement counting likes up and down return $rank; //new arrangement returning comment rank }
/** * Updates the involved Users of this object. * Currently this will be execution always after saving, maybe find a better way. * * Fast Hack!11! * * ToDo: - Make it more flexible! * - Make it faster! * - Missing Users which likes a comment */ public function updateInvolvedUsers() { // Collect User Ids $foundUsersIds = array(); $foundUsersIds[] = $this->created_by; if ($this->object_model != "Activity") { $comments = Comment::model()->findAllByAttributes(array('object_model' => $this->object_model, 'object_id' => $this->object_id)); foreach ($comments as $comment) { $foundUsersIds[] = $comment->created_by; // Comment Likes $likes = Like::model()->findAllByAttributes(array('object_model' => 'Comment', 'object_id' => $comment->id)); foreach ($likes as $like) { $foundUsersIds[] = $like->created_by; } } $likes = Like::model()->findAllByAttributes(array('object_model' => $this->object_model, 'object_id' => $this->object_id)); foreach ($likes as $like) { $foundUsersIds[] = $like->created_by; } } UserContent::model()->deleteAllByAttributes(array('object_model' => $this->object_model, 'object_id' => $this->object_id)); // Add currently involved users foreach (array_unique($foundUsersIds) as $userId) { $userContent = new UserContent(); $userContent->object_model = $this->object_model; $userContent->object_id = $this->object_id; $userContent->user_id = $userId; $userContent->save(); } // Rewrite! }
public function testShouldValidateMatchingCase() { $pattern = 'Henrique Moody'; $filter = new Like($pattern); $this->assertFalse($filter->isValid('henrique moody')); }