Example #1
0
 public function index()
 {
     if ($this->params()->user_id) {
         // $this->params(user_id] = params[:user_id].to_i
         # Use .where to ignore error when invalid user_id entered.
         # .first because .where returns array.
         $this->user = User::where('id = ?', $this->params()->user_id)->first();
         $this->user_records = UserRecord::where("user_id = ?", $this->params()->user_id)->order("created_at desc")->paginate($this->page_number(), 20);
     } else {
         $this->user = false;
         $this->user_records = UserRecord::order("created_at desc")->paginate($this->page_number(), 20);
     }
 }
Example #2
0
      <td><strong><?php 
echo $this->t('user_record');
?>
</strong></td>
      <td>
        <?php 
if (!UserRecord::where("user_id = ?", $this->user->id)->exists()) {
    ?>
          <?php 
    echo $this->t('user_record_none');
    ?>
        <?php 
} else {
    ?>
          <?php 
    echo UserRecord::where("user_id = ? AND is_positive = true", $this->user->id)->count() - UserRecord::where("user_id = ? AND is_positive = false", $this->user->id)->count();
    ?>
        <?php 
}
?>
        (<?php 
echo $this->linkTo($this->t('user_record_add'), array('user_record#index', 'user_id' => $this->user->id));
?>
)
      </td>
    </tr>
    <?php 
if (current_user()->is_mod_or_higher()) {
    ?>
      <tr>
        <td><strong><?php 
Example #3
0
 public function invite($name, $level)
 {
     if ($this->invite_count <= 0) {
         throw new User_NoInvites();
     }
     if ((int) $level >= CONFIG()->user_levels["Contributor"]) {
         $level = CONFIG()->user_levels["Contributor"];
     }
     $invitee = User::where(['name' => $name])->first();
     if (!$invitee) {
         throw new Rails\ActiveRecord\Exception\RecordNotFoundException();
     }
     if (UserRecord::where("user_id = ? AND is_positive = false AND reported_by IN (SELECT id FROM users WHERE level >= ?)", $invitee->id, CONFIG()->user_levels["Mod"])->exists() && !$this->is_admin()) {
         throw new User_HasNegativeRecord();
     }
     // transaction do
     if ($level == CONFIG()->user_levels["Contributor"]) {
         Post::where("user_id = ? AND status = 'pending'", $this->id)->take()->each(function ($post) {
             $post->approve($id);
         });
     }
     $invitee->level = $level;
     $invitee->invited_by = $this->id;
     $invitee->save();
     # iTODO: add support for decrement!
     // decrement! :invite_count
     self::connection()->executeSql("UPDATE users SET invite_count = invite_count - 1 WHERE id = " . $this->id);
     $this->invite_count--;
     // end
 }