Пример #1
0
 /**
  * Decrements post count in all tables by [$count]
  * 
  * @param int $cid Category id
  * @param int $tid Topic id
  * @param int $uid User id
  * @param int $count Increment count
  */
 public function decPostCount($cid, $tid, $uid = false, $count = 1)
 {
     $qry = 'UPDATE codo_categories SET no_posts = no_posts-' . $count . ' WHERE cat_id=' . $cid;
     $this->db->query($qry);
     $qry = 'UPDATE codo_topics SET no_posts = no_posts-' . $count . ' WHERE topic_id=' . $tid;
     $this->db->query($qry);
     if ($uid) {
         $qry = 'UPDATE codo_users SET no_posts = no_posts-' . $count . ' WHERE id=' . $uid;
         $this->db->query($qry);
     }
     \CODOF\Util::set_promoted_or_demoted_rid();
 }
Пример #2
0
 public function down($post_id)
 {
     $pid = (int) $post_id;
     $user = \CODOF\User\User::get();
     $post_info = \DB::table(PREFIX . 'codo_posts')->where('post_id', '=', $pid)->select('uid', 'reputation')->first();
     $errors = array();
     $puid = $post_info['uid'];
     if ($this->can_down($pid, $puid)) {
         $this->inc_rep_log($user->id);
         \DB::table(PREFIX . 'codo_reputation')->insert(array('from_id' => $user->id, 'to_id' => $puid, 'post_id' => $pid, 'points' => -1, 'rep_time' => time()));
         \DB::table(PREFIX . 'codo_users')->where('id', '=', $puid)->decrement('reputation');
         \DB::table(PREFIX . 'codo_posts')->where('post_id', '=', $pid)->decrement('reputation');
         echo json_encode(array("done" => true, 'rep' => $post_info['reputation'] - 1));
     } else {
         if (!$user->can('rep down')) {
             $errors[] = _t("You do not have permission to give reputation");
         }
         if (!$this->rule1) {
             $errors[] = sprintf(_t("You cannot give more than %d reps per day"), \CODOF\Util::get_opt('max_rep_per_day'));
         }
         if (!$this->rule2) {
             $errors[] = _t("You do not have enough rep points or posts to give reputation");
         }
         if (!$this->rule3) {
             $errors[] = _t("You have already given the maximum number of reps to this user, please wait for sometime");
         }
         if (!$this->rule4) {
             $errors[] = _t("You cannot give reputation to the same post again");
         }
         if (!$this->rule5) {
             $errors[] = _t("You cannot give reputation to your own post");
         }
         echo json_encode(array("done" => false, 'errors' => $errors));
     }
     \CODOF\Util::set_promoted_or_demoted_rid();
 }