public function like($user) { if (is_object($user) && !$this->isLikedByUser($user)) { if ($this->isDislikedByUser($user)) { $this->undislike($user); } if (!ChannelAction::exists(array('channel_id' => $user->getMainChannel()->id, 'type' => 'like_comment', 'target' => $this->id))) { ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $user->getMainChannel()->id, 'recipients_ids' => UserChannel::find($this->poster_id)->admins_ids, 'type' => 'like_comment', 'target' => $this->id, 'timestamp' => Utils::tps())); $this->likes++; $this->save(); } } }
public static function generateId($length) { $idExists = true; while ($idExists) { $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $id = ''; for ($i = 0; $i < $length - 2; $i++) { $id .= $chars[rand(0, strlen($chars) - 1)]; } $id = 'a_' . $id; $idExists = ChannelAction::exists(array('id' => $id)); } return $id; }
public function like($userId) { $voteId = VideoVote::generateId(6); VideoVote::create(array('id' => $voteId, 'user_id' => $userId, 'type' => 'video', 'obj_id' => $this->id, 'action' => 'like')); $this->likes++; $this->save(); if ($userId != Session::get()->id && !ChannelAction::exists(array('channel_id' => User::find($userId)->getMainChannel()->id, 'type' => 'like', 'target' => $this->id))) { ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => User::find($userId)->getMainChannel()->id, 'recipients_ids' => ChannelAction::filterReceiver(UserChannel::find($this->poster_id)->admins_ids, "like"), 'type' => 'like', 'target' => $this->id, 'timestamp' => Utils::tps())); } }
public function subscribe($subscriber) { Subscription::subscribeUserToChannel($subscriber, $this); $subscriberUser = User::find_by_id($subscriber); $subscribingChannel = $this; $subscribing = $this->id; if (!ChannelAction::exists(array('channel_id' => User::find($subscriber)->getMainChannel()->id, 'type' => 'subscription', 'target' => $subscribing))) { ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => User::find($subscriber)->getMainChannel()->id, 'recipients_ids' => ChannelAction::filterReceiver($subscribingChannel->admins_ids, "subscription"), 'type' => 'subscription', 'target' => $subscribing, 'timestamp' => Utils::tps())); } }