상속: extends CI_Model
예제 #1
0
 function change_publish_status()
 {
     $comments_model = new Comments_model();
     $comments_service = new Comments_service();
     $comments_model->set_id(trim($this->input->post('id', TRUE)));
     $comments_model->set_is_published(trim($this->input->post('value', TRUE)));
     echo $comments_service->publish_comment($comments_model);
 }
 /**
  * Get comments from user for dish
  * url: http://localhost/user/<number_of_user>/comments?to=yyyy-mm-dd&days=duration
  * Method: GET
  * @param       int  $user_id
  * @param       date('y-m-d')  $to
  * @param       int  $days
  * @return      json
  */
 function comments_of_user_get($user_id)
 {
     $this->authenticate();
     $messages_lang = $this->common->set_language_for_server_api('comments_api', array('get_comments_success', 'get_comments_failure', 'get_comments_not_valid'));
     $to = $this->input->get('to') == NULL ? date('Y-m-d') : $this->input->get('to');
     $days = $this->input->get('days');
     $response = array();
     if (strtotime($to)) {
         $date_to = (new DateTime($to))->format('Y-m-d');
         $date_from = (new DateTime($to))->sub(new DateInterval('P' . $days . 'D'))->format('Y-m-d');
         $result = Comments_model::get_comments_of_user($user_id, $date_from, $date_to);
         $data = array();
         if ($result != NULL) {
             $comments = array();
             foreach ($result as $temp) {
                 $comment = array();
                 $comment['id'] = (int) $temp->id;
                 $comment['dish_id'] = is_null($temp->dish_id) ? NULL : (int) $temp->dish_id;
                 $comment['content'] = $temp->content;
                 $comment['title'] = $temp->title;
                 $comment['meal_date'] = $temp->meal_date;
                 $comment['number_of_replies'] = (int) $temp->number_of_replies;
                 $comment['number_of_have_read_replies'] = (int) $temp->count_replies_have_read;
                 $comment['read_flag'] = $temp->have_read;
                 $comment['created_at'] = $temp->created_at;
                 $comment['updated_at'] = $temp->updated_at;
                 $comment['user_id'] = (int) $temp->user_id;
                 $comment['email'] = $temp->email;
                 $comment['avatar_content_file'] = $temp->avatar_content_file;
                 array_push($comments, $comment);
             }
             $date_to = date('Y-m-d', strtotime($comments[sizeof($comments) - 1]['created_at']));
             $is_more_comments = Comments_model::get_comments_of_user($user_id, NULL, $date_to) != NULL ? TRUE : FALSE;
             $data['is_more_comments'] = $is_more_comments;
             $data['current_day'] = $to;
             $data['date_get_more_comments'] = $date_from;
             $data['comments'] = $comments;
             $response['status'] = $messages_lang['success'];
             $response['message'] = $messages_lang['get_comments_success'];
             $response['data'] = $data;
         } else {
             $data['comments'] = NULL;
             $is_more_comments = Comments_model::get_comments_of_user($user_id, NULL, $date_from) != NULL ? TRUE : FALSE;
             $data['is_more_comments'] = $is_more_comments;
             $data['date_get_more_comments'] = $date_from;
             $response['status'] = $messages_lang['success'];
             $response['message'] = $messages_lang['get_comments_failure'];
             $response['data'] = $data;
         }
     } else {
         $response['status'] = $messages_lang['failure'];
         $response['message'] = $messages_lang['get_comments_not_valid'];
     }
     $this->response($response, 200);
 }
예제 #3
0
 public function delete($comment_id)
 {
     $this->common->authenticate();
     $message = $this->common->get_message('delete_comment', array('delete_success', 'delete_failure'));
     if (Comments_model::delete_comment($comment_id)) {
         $data = array('status' => 'success', 'message' => $message['delete_success']);
     } else {
         $data = array('status' => 'failure', 'message' => $message['delete_failure']);
     }
     echo json_encode($data);
 }
예제 #4
0
    function add_website_comments()
    {
        $comments_service = new Comments_service();
        $comments_model = new Comments_model();
        $comments_model->set_description($this->input->post('description', TRUE));
        $comments_model->set_title($this->input->post('title', TRUE));
        $comments_model->set_added_date(date("Y-m-d H:i:s"));
        $comments_model->set_added_by($this->session->userdata('USER_ID'));
        $comments_model->set_is_published('1');
        $comments_model->set_is_deleted('0');
        $comments_service->add_website_comments($comments_model);
        $website_comments = $comments_service->get_all_comments_list();
        foreach ($website_comments as $value) {
            ?>
            <li class="comment"><br>
                <figure><br><br>
                    <div class="image">
                        <?php 
            if ($value->profile_pic == '') {
                ?>
                            <img class="img-responsive img-circle" style="width:100px; height:50px;" src="<?php 
                echo base_url() . 'uploads/user_avatars/avatar.png';
                ?>
"/>
                        <?php 
            } else {
                ?>
                            <img class="img-responsive img-circle" style="width:100px; height:50px;" src="<?php 
                echo base_url() . 'uploads/user_avatars/' . $value->profile_pic;
                ?>
"/>
                        <?php 
            }
            ?>
                    </div>
                </figure>
                <div class="comment-wrapper">
                    <?php 
            if ($value->added_by_user != '') {
                ?>
                        <div class="name pull-left"><?php 
                echo ucfirst($value->added_by_user);
                ?>
</div>
                    <?php 
            }
            ?>
                    <span class="date pull-right"><br><br><br><br>
                        <span class="fa fa-calendar"></span>
                        <?php 
            echo date('Y.m.d', strtotime($value->added_date));
            ?>
                    </span>
                    <p><header><a href="blog-detail.html"><h2><?php 
            echo $value->title;
            ?>
</h2></a></header>
                    <?php 
            echo $value->description;
            ?>
</p>
            </div>
            </li>

            <?php 
        }
    }