Exemplo n.º 1
0
 /**
  * 
  * 
  * @param type $post
  * @return type 
  */
 public function save($post)
 {
     if (empty($post[$this->pkey])) {
         $post['added_at'] = now2mysql();
     }
     unset($post['login'], $post['email'], $post['avatar'], $post['banned'], $post['role']);
     $post[$this->pkey] = parent::save($post);
     // after that check tags, add them and link with our new post
     if (!empty($post['tags'])) {
         $post['type'] = blog_type('post');
         if (!isset($this->tag)) {
             $this->load->model('tag');
         }
         $post['tags'] = $this->tag->save($post);
         parent::save($post);
     }
     return $post['id'];
 }
Exemplo n.º 2
0
 public function voting($post_id = '', $user_id = '')
 {
     // check if we alredy have voted for this post
     $data = array('post_id' => $post_id, 'user_id' => $user_id);
     $voted = $this->where($data)->find(NULL, 1);
     if ($voted) {
         throw new Exception('Извините, вы уже голосовали за этот топик');
     }
     $data['weight'] = 1;
     $data['added_at'] = now2mysql();
     $this->save($data);
     $this->db->select('SUM(weight) AS rating')->where('post_id', $post_id);
     $res = $this->find(NULL, 1);
     if (empty($res)) {
         throw new Exception('Извините, какая-то ошибка при подсчете рейтинга');
     }
     $data = array('id' => $post_id, 'rating' => $res['rating']);
     $this->post->save($data);
     return $res['rating'];
 }
Exemplo n.º 3
0
 /**
  * Add new comment to topic
  */
 public function comment()
 {
     $this->load->model('comment');
     $comment['post_id'] = param('post_id');
     if (empty($comment['post_id'])) {
         set_flash_error('Ошибка в параметрах комментария');
         redirect();
     }
     $post = $this->post->find($comment['post_id'], 1);
     if (empty($post)) {
         set_flash_error('Такого топика не существует');
         redirect();
     }
     $comment['parent_id'] = param('parent_id');
     $comment['text'] = prepare_text(param('text', TRUE, FALSE));
     if (empty($comment['text'])) {
         set_flash_error('Вы не написали свой комментарий к топику');
         redirect(post_link($post));
     }
     $comment['user_id'] = $this->current_user['id'];
     $comment['added_at'] = now2mysql();
     $id = $this->comment->save($comment);
     if ($id) {
         set_flash_ok('Спасибо за ваш комментарий');
     } else {
         set_flash_error('Извините, но произошла ошибка и ваш комментарий сохранить не удалось');
     }
     redirect(post_link($post) . '#com' . $id);
 }
Exemplo n.º 4
0
/**
 * Сохраним наш лог действий пользователя
 *
 * @param mixed|string  $log
 * @param string        $comment
 */
function log_action($log = '', $comment = '')
{
    $site = CI()->config->item('site');
    if (!$site['log_action']) {
        return;
    }
    if (!is_string($log)) {
        $log = TextDump($log);
    }
    $debug = debug_backtrace();
    #dump( $debug );
    $user = CI()->user_mod->get_all();
    $data = array('date_at' => (string) now2mysql(), 'login' => (string) $user['login'], 'file' => (string) $debug[0]['file'], 'func' => (string) $debug[1]['function'], 'line' => (string) $debug[0]['line'], 'log' => (string) $log, 'comment' => (string) $comment);
    CI()->log_mod->save($data);
}
Exemplo n.º 5
0
 /**
  * Update user's time shift
  */
 public function save_shift()
 {
     $data['id'] = param('id|int');
     $data['staff_id'] = param('staff_id|int');
     // break if we dont have user's ID!
     if (empty($data['staff_id'])) {
         response_to(array('error' => 'Error, Staff ID is empty'));
         return;
     }
     // decode our row params from JSON
     $data['fromdate'] = mysql_date(not_empty(param('fromdate', FALSE, FALSE), now2mysql()));
     $data['shift_id'] = param('shift_id|int');
     try {
         $id = $this->staffshift->save($data);
         $data['id'] = $id;
         // make row for return if we create him
         $shiftheads = $this->shiftheads();
         //$data['shifts']      = $this->shifts( $id );
         $row = shift_row($data, TRUE, $shiftheads);
         //$id = $data['id'];
         $response = array('msg' => 'Good, TimeShift saved', 'id' => $id, 'row' => $row);
     } catch (Exception $e) {
         $response = array('error' => $e->getMessage());
     }
     response_to($response);
     return;
 }
Exemplo n.º 6
0
 /**
  * Новая запись вставляется в таблицу
  */
 public function insert($user = '')
 {
     if (empty($user)) {
         return FALSE;
     }
     unset($user[$this->pkey]);
     if (!empty($user['birth_at'])) {
         $user['birth_at'] = transform_date($user['birth_at']);
     }
     if (!empty($user['new_password'])) {
         srand(time());
         $user['salt'] = substr(md5(rand(100, time())), 0, 12);
         $user['password'] = $this->make_password($user['new_password'], $user['salt']);
     }
     unset($user['new_password']);
     $user['registered_at'] = not_empty(transform_date($user['registered_at']), now2mysql());
     $this->db->insert($this->table, $user);
     return $this->db->insert_id();
 }
Exemplo n.º 7
0
 /**
  * Method implements comments import
  * 
  * @param number $i_post_id BMF post ID
  * @param array $i_comments Post title (subject)
  */
 private function add_comment($i_post_id, $i_comment, $i_parent_id = 0)
 {
     //We should register the comment author in BMF
     //(If he haven't registered yet, else we should get his ID)
     if ($i_comment['postername'] != '') {
         $user_id = $this->get_user_id($i_comment['postername']);
     } else {
         $user_id = $this->get_user_id('anonymous');
     }
     //Add comment
     $comment = array('post_id' => $i_post_id, 'parent_id' => $i_parent_id, 'text' => prepare_text($i_comment['body']), 'user_id' => $user_id, 'added_at' => now2mysql());
     $comment_id = $this->comment->save($comment);
     //Recursive search GO!
     if (!empty($i_comment['children'])) {
         foreach ($i_comment['children'] as $child) {
             $this->add_comment($i_post_id, $child, $comment_id);
         }
     }
 }