/*
Public: Dislike comment

$user - user object

Returns number of dislikes
517112
public function dislikeComment($ip, $useragent)
    {
        $app = App::getInstance();

        if (!$this->userLikedOrDislikedComment($ip, $useragent)) { // check user hasn't already liked the comment
            $sql = $app['safesql']->query(
                "INSERT INTO `comment_like`
				(
					ip,
					user_agent,
					comment,
					binlike,
					deleted
				) VALUES (
					'%s',
					'%s',
					%i,
					0,
					0
				)",
                array(
                    $ip,
                    $useragent,
                    $this->getId(),
                ));
            $app['db']->query($sql);

            $dislikes = $this->getDislikes() + 1;
            $this->setDislikes($dislikes)
                ->save();

            return $dislikes;
        } else {
            return false;
        }
    }
375311
function comments_weekly( $count = 20, $base_app = 0)
	{
		$params =  array();
		$params['count'] = intval($count);
		$params['base_app'] = intval($base_app);
		return $this->oauth->get( 'statuses/hot/comments_weekly', $params);
	}
165449
public function next_user() {
        if (!$this->users_rs) {
            return false; // no users present
        }

        if (!$this->users_rs->valid()) {
            if ($current = $this->_pop()) {
                // this is not good - user or grades updated between the two reads above :-(
            }

            return false; // no more users
        } else {
            $user = $this->users_rs->current();
            $this->users_rs->next();
        }

        // find grades of this user
        $grade_records = array();
        while (true) {
            if (!$current = $this->_pop()) {
                break; // no more grades
            }

            if (empty($current->userid)) {
                break;
            }

            if ($current->userid != $user->id) {
                // grade of the next user, we have all for this user
                $this->_push($current);
                break;
            }

            $grade_records[$current->itemid] = $current;
        }

        $grades = array();
        $feedbacks = array();

        if (!empty($this->grade_items)) {
            foreach ($this->grade_items as $grade_item) {
                if (!isset($feedbacks[$grade_item->id])) {
                    $feedbacks[$grade_item->id] = new stdClass();
                }
                if (array_key_exists($grade_item->id, $grade_records)) {
                    $feedbacks[$grade_item->id]->feedback       = $grade_records[$grade_item->id]->feedback;
                    $feedbacks[$grade_item->id]->feedbackformat = $grade_records[$grade_item->id]->feedbackformat;
                    unset($grade_records[$grade_item->id]->feedback);
                    unset($grade_records[$grade_item->id]->feedbackformat);
                    $grades[$grade_item->id] = new grade_grade($grade_records[$grade_item->id], false);
                } else {
                    $feedbacks[$grade_item->id]->feedback       = '';
                    $feedbacks[$grade_item->id]->feedbackformat = FORMAT_MOODLE;
                    $grades[$grade_item->id] =
                        new grade_grade(array('userid'=>$user->id, 'itemid'=>$grade_item->id), false);
                }
                $grades[$grade_item->id]->grade_item = $grade_item;
            }
        }

        // Set user suspended status.
        $user->suspendedenrolment = isset($this->suspendedusers[$user->id]);
        $result = new stdClass();
        $result->user      = $user;
        $result->grades    = $grades;
        $result->feedbacks = $feedbacks;
        return $result;
    }
78245
public function deserialize($data, Comment $comment = null, User $user = null, array $options = [])
    {
        if (empty($comment)) {
            $comment = new Comment();
        }

        if (!in_array(Options::REFRESH_UUID, $options)) {
            $this->sipe('id', 'setUuid', $data, $comment);
        }

        if (isset($data['message'])) {
            $comment->setMessage($data['message']);
        }

        if (isset($data['creationDate'])) {
            $comment->setCreationDate(DateNormalizer::denormalize($data['creationDate']));
        } else {
            $comment->setCreationDate(new \DateTime());
        }

        if (isset($data['isPublished'])) {
            $comment->publish();
            if (isset($data['publicationDate'])) {
                $comment->setPublicationDate(DateNormalizer::denormalize($data['publicationDate']));
            } else {
                $comment->setPublicationDate(new \DateTime());
            }
        }

        if (isset($data['updateDate'])) {
            $comment->setUpdateDate(DateNormalizer::denormalize($data['updateDate']));
        }

        if (isset($data['reported'])) {
            $comment->setReported($data['reported']);
        }

        if ($user) {
            $comment->setAuthor($user);
        } elseif (isset($data['user'])) {
            $user = isset($data['user']['id']) ? $this->userRepo->findOneBy(['id' => $data['user']['id']]) : null;
            $comment->setAuthor($user);
        }

        return $comment;
    }
832996
public function user() {
		$user = (int) $this->request->param('ID');
		
		$since = $this->owner->getRequest()->getVar('since');
		$offset = (int) $this->owner->getRequest()->getVar('before');
		if (!$offset) {
			$offset = false;
		}
		$filter = array('OwnerID' => $user);
		$tags = $this->getFilterTags();
		$target = $this->getTargetFilter();
		if ($target) {
			$filter['Target'] = $target;
		}
		
		$sort = $this->request->getVar('sort');
		if (!$sort) {
			$sort = 'ID';
		}
		
		
		$data = $this->owner->microBlogService->getStatusUpdates($filter, $sort, $since, $offset, $toplevel = true, $tags);
		
		$props = array(
			'Posts' => $data, 
			'Options' => $this->getOptions(),
			'QueryOffset'	=> $data->QueryOffset,
			'Target'		=> $target,
			'SortBy'		=> $sort
		);
		
		$timeline = trim($this->customise($props)->renderWith('Timeline'));

		if (Director::is_ajax()) {
			return $timeline;
		}

		$data = array(
			'Timeline'		=> '<strong>WARNING: USER VIEWS ARE IN ALPHA </strong>' . $timeline,
			'OwnerFeed'		=> $timeline,
		);

		return $this->customise($data)->renderWith(array('FullTimeline', 'Page'));
	}
147881
public function likeComment($ip, $useragent)
    {
        $app = App::getInstance();

        if (!$this->userLikedOrDislikedComment($ip, $useragent)) { // check user hasn't already liked the comment
            $sql = $app['safesql']->query(
                "INSERT INTO `comment_like`
				(
					ip,
					user_agent,
					comment,
					binlike,
					deleted
				) VALUES (
					'%s',
					'%s',
					%i,
					1,
					0
				)",
                array(
                    $ip,
                    $useragent,
                    $this->getId(),
                ));
            $app['db']->query($sql);

            $likes = $this->getLikes() + 1;
            $this->setLikes($likes)
                ->save();

            return $likes;
        } else {
            return false;
        }
    }
456978
public function canComment($user = null)
    {
        if ($this->getCommentStatus()->getId() == ArticleCommentStatus::ARTICLE_COMMENTS_OFF) {
            return false;
        }

        if ($this->getCommentStatus()->getId() == ArticleCommentStatus::ARTICLE_COMMENTS_INTERNAL) {
            if ($user && $user->isLoggedIn()) {
                return true;
            } else {
                return false;
            }
        }

        if ($this->getCommentStatus()->getId() == ArticleCommentStatus::ARTICLE_COMMENTS_ON) {
            return true;
        }

        return false;
    }
667273
def comment_form(context, object):
    
    user = context.get("user")
    form_class = context.get("form", CommentForm)
    form = form_class(obj=object, user=user)
    return form
971566
public function updateComment( $comment, $user=null, $time = null , $notified = null )
    {
        if ( $time === null )
        {
            $time = time();
        }

        $beforeUpdating = $this->beforeUpdatingComment( $comment, $notified, $time );
        if ( $beforeUpdating !== true )
        {
            return $beforeUpdating;
        }
        $comment->store();

        $afterUpdating = $this->afterUpdatingComment( $comment, $notified, $time );
        if ( $afterUpdating !== true )
        {
            return $afterUpdating;
        }
        return true;
    }
937119
public function unLikeIt($user = null)
    {
        if ($like = $this->isLiked($user)) {
            $like->delete();
            $this->decrementCount();
        }
    }
1303783
public function addComment($user, string $comment) : Comment
    {
        return $this->comments()->create([
            'user_id' => $user->id,
            'comment' => $comment,
        ]);
    }
221950
public function spam()
    {
        $comment = $this->getComment();
        if (!$comment) {
            return $this->httpError(404);
        }
        if (!$comment->canEdit()) {
            return Security::permissionFailure($this, 'You do not have permission to edit this comment');
        }
        if (!$comment->getSecurityToken()->checkRequest($this->request)) {
            return $this->httpError(400);
        }

        $comment->markSpam();
        return $this->renderChangedCommentState($comment);
    }
805228
function(member) {
            users = $module.data('users');
            if(member !== undefined && member.id !== 'anonymous') {
              delete users[ member.id ];
              $module
                .data('users', users)
              ;
              $userList
                .find('[data-id='+ member.id + ']')
                  .remove()
              ;
              if(settings.partingMessages) {
                $log
                  .append( settings.templates.left(member.info) )
                ;
                module.message.scroll.test();
              }
              module.user.updateCount();
            }
          }
1363159
public function likeIt($user = null)
    {
        if (!$this->isLiked()) {
            $this->likes()->create([
                'user_id'=> $user ? $user->id : auth()->id()
            ]);
            $this->incrementCount();
        }
    }
434142
public function vote(Request $request)
    {
    	/* Check if user is loged in*/
    	if (!Auth::check()) {
    		return response()->json(['flag' => 0]);
    	}

    	/* Prepare data */
    	$userId = Auth::user()->id;
    	$itemId = $request->item_id;
    	$vote = $request->vote;

    	/* Get item's current like, dislike total */
    	$totalLike = TotalLike::where('item_id', $itemId)->first();

    	/* Get user's vote on this item */
		$like = Like::where(['user_id' => $userId, 'item_id' => $itemId])->first();

		/* Check if users vote on this item exists */
		if ($like != null) {
			if ($like->vote == 1) {	// if previous vote was like
				$totalLike->total_like--;	// decrease item's total like by 1
				$totalLike->total_like = $totalLike->total_like == null ? 0 : $totalLike->total_like;	// set 0 if total like is null
				if ($vote == 1) {	// if current vote is like
					$vote = 0;	// previous vote and current vote is same so discarde vote
				}
			} else if ($like->vote == -1) {	// if previous vote was dislike
				$totalLike->total_dislike--;	// decrease item's total like by 1
				$totalLike->total_dislike = $totalLike->total_dislike == null ? 0 : $totalLike->total_dislike;	// set 0 if total dislike is null
				if ($vote == -1) {	// if current vote is dislike
					$vote = 0;	// previous vote and current vote is same so discarde vote
				}
			}
		} else {
			$like = new Like;	// create new like object if previous vote not exists
		}

		/* Update vote data */
		$like->user_id = $userId;
		$like->item_id = $itemId;
		$like->vote = $vote;

		if ($vote == 1) {
			$totalLike->total_like++;	// increase total like if vote is like
		} else if ($vote == -1) {
			$totalLike->total_dislike++;	// increase total dislike if vote is dislike
		}

		$like->save();		// save like
		$totalLike->save();	//save total like,dislike

    	return response()->json(['flag' => 1, 'vote' => $vote, 'totalLike' => $totalLike->total_like, 'totalDislike' => $totalLike->total_dislike]);
    }
866092
public function spam(Comment &$comment)
    {
        $endpoint = '/admin/comments/'.$comment->id.'/spam.json';
        $response = $this->request($endpoint, 'POST');
        $comment->setData($response['comment']);
    }
784948
public function downVoteAction(Request $request)
    {
        $reference = $request->get('reference');
        $value = $request->get('value');
        $this->get('event_dispatcher')->dispatch(Events::VOTE_DOWN, new DownVoteEvent($request, $reference, $value));

        return;
    }