Example #1
0
 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 = 'v_' . $id;
         $idExists = VideoVote::exists(array('id' => $id));
     }
     return $id;
 }
Example #2
0
 public function removeDislike($userId)
 {
     if ($this->dislikes >= 1) {
         $this->dislikes--;
         $this->save();
         VideoVote::delete_all(array('conditions' => array('user_id = ? and obj_id = ?', $userId, $this->id)));
     }
 }
Example #3
0
 public function registervote($voteduser, $sourceid)
 {
     //return $voteduser;
     $voteruserid = Yii::app()->session['login']['id'];
     $check = VideoVote::model()->findByAttributes(array('voter_userid' => $voteruserid, 'voted_userid' => $voteduser, 'voted_sourceid' => $sourceid));
     if (!$check) {
         $newvote = new VideoVote();
         $newvote->voter_userid = $voteruserid;
         $newvote->voted_userid = $voteduser;
         $newvote->voted_sourceid = $sourceid;
         $newvote->createddate = new CDbExpression('NOW()');
         $newvote->status = 1;
         if ($newvote->save(false)) {
             return '-true';
             //voted success
         }
     } else {
         return '-false';
         //already voted
     }
 }
Example #4
0
 public function actionvoteVideo()
 {
     $model = new VideoVote();
     $model->voter_userid = $_POST['voteruserid'];
     $model->voted_userid = $_POST['voteduserid'];
     $model->voted_sourceid = $_POST['videoid'];
     $date = date('Y-m-d H:i:s');
     $model->createddate = $date;
     $model->status = 1;
     $model->insert();
     echo "sucess";
 }