Esempio n. 1
0
 public function testTotalPages()
 {
     $pagination = new Pagination(10, 1, 2);
     $this->assertEquals(5, $pagination->totalPages());
     $pagination = new Pagination(11, 1, 3);
     $this->assertEquals(4, $pagination->totalPages());
 }
Esempio n. 2
0
 public function inquiriesByMe()
 {
     $currentPage = $this->app['http']->request->get('page') <= 0 ? 1 : $this->app['http']->request->get('page');
     $itemsPerPage = $this->app['http']->request->get('count') <= 0 ? 5 : $this->app['http']->request->get('count');
     $neighbours = $this->app['http']->request->get('neighbor') <= 0 ? 1 : $this->app['http']->request->get('neighbor');
     $totalItems = $this->app['pdo']->ypyz_inquiry()->where('public_userid', $this->app['access_token_data']['user_id'])->count();
     if ($totalItems == 0) {
         return null;
     }
     $pagination = new Pagination($totalItems, $currentPage, $itemsPerPage, $neighbours);
     $offset = $pagination->offset();
     $limit = $pagination->limit();
     $results = $this->app['pdo']->ypyz_inquiry()->where('public_userid', $this->app['access_token_data']['user_id'])->order("inquiry_id DESC")->limit($limit, $offset);
     $result = array();
     foreach ($results as $key => $res) {
         $result['data'][$key]['inquiry_id'] = $res['inquiry_id'];
         $result['data'][$key]['patient_id'] = $res['patient_id'];
         $result['data'][$key]['casehistory_id'] = $res['casehistory_id'];
         $result['data'][$key]['description'] = $res['description'];
         $result['data'][$key]['public_userid'] = $res['public_userid'];
         $result['data'][$key]['public_time'] = $res['public_time'];
         $result['data'][$key]['is_solve'] = $res['is_solve'];
         $result['data'][$key]['end_time'] = $res['end_time'];
         $result['data'][$key]['is_reply'] = $res['is_reply'];
         $result['data'][$key]['last_reply_time'] = $res['last_reply_time'];
         $result['data'][$key]['last_reply_userid'] = $res['last_reply_userid'];
         $totalItemss = $this->app['pdo']->ypyz_dialog()->where(array('inquiry_id' => $res['inquiry_id'], 'to_userid' => $res['public_userid'], 'is_read' => 0))->count();
         $result['data'][$key]['unread_count'] = $totalItemss;
         $picture_arr = explode(',', $res['picture']);
         foreach ($picture_arr as $k => $pic) {
             $result['data'][$key]['picture'][$k] = "http://api.didijiankang.cn/api/images/uploads/" . $pic;
         }
         $res2 = $this->db_upihealth2->myconcern()->where(array('user_measure' => $res['patient_id']))->fetch();
         if ($res2 != null) {
             $result['data'][$key]['remark'] = $res2['remark'];
         } else {
             $result['data'][$key]['remark'] = null;
         }
     }
     $totalPages = $pagination->totalPages();
     if ($currentPage > $totalPages) {
         $result['page']['current_cursor'] = $totalPages;
         $result['page']['previous_cursor'] = $totalPages == 1 ? 1 : $totalPages - 1;
         $result['page']['next_cursor'] = $totalPages;
     } else {
         $result['page']['current_cursor'] = $currentPage;
         $result['page']['previous_cursor'] = $currentPage <= 1 ? 1 : $currentPage - 1;
         if ($currentPage + 1 >= $totalPages) {
             $result['page']['next_cursor'] = $totalPages;
         } else {
             $result['page']['next_cursor'] = $currentPage + 1;
         }
     }
     $result['page']['total_number'] = $totalItems;
     return $result;
 }
Esempio n. 3
0
 public function newsPublic()
 {
     $currentPage = $this->app['http']->request->get('page') <= 0 ? 1 : $this->app['http']->request->get('page');
     $itemsPerPage = $this->app['http']->request->get('count') <= 0 ? 5 : $this->app['http']->request->get('count');
     $neighbours = $this->app['http']->request->get('neighbor') <= 0 ? 1 : $this->app['http']->request->get('neighbor');
     $totalItems = $this->db_website->ypyz_document_article()->count();
     if ($totalItems == 0) {
         return null;
     }
     $pagination = new Pagination($totalItems, $currentPage, $itemsPerPage, $neighbours);
     $offset = $pagination->offset();
     $limit = $pagination->limit();
     $res = $this->pdo->query("SELECT ypyz_document_article.id,ypyz_document.title,ypyz_document.comment,ypyz_document.description,ypyz_picture.path FROM ypyz_document_article\n        LEFT JOIN ypyz_document ON ypyz_document_article.id=ypyz_document.id\n        LEFT JOIN ypyz_picture ON ypyz_picture.id=ypyz_document.cover_id LIMIT {$offset},{$limit}");
     $result_arr = $res->fetchAll(\PDO::FETCH_ASSOC);
     foreach ($result_arr as $key => $res) {
         $result['data'][$key]['id'] = $res['id'];
         $result['data'][$key]['title'] = $res['title'];
         if (emtpy($res['comment'])) {
             $result['data'][$key]['comment'] = 0;
         } else {
             $result['data'][$key]['comment'] = $res['comment'];
         }
         if (emtpy($res['description'])) {
             $result['data'][$key]['description'] = "暂无描述";
         } else {
             $result['data'][$key]['description'] = $res['description'];
         }
         if ($res['path'] != null) {
             $result['data'][$key]['thumb'] = "http://www.didijiankang.cn/webhtml/" . $res['path'];
         } else {
             $result['data'][$key]['thumb'] = "";
         }
     }
     $totalPages = $pagination->totalPages();
     if ($currentPage > $totalPages) {
         $result['page']['current_cursor'] = $totalPages;
         $result['page']['previous_cursor'] = $totalPages == 1 ? 1 : $totalPages - 1;
         $result['page']['next_cursor'] = $totalPages;
     } else {
         $result['page']['current_cursor'] = $currentPage;
         $result['page']['previous_cursor'] = $currentPage <= 1 ? 1 : $currentPage - 1;
         if ($currentPage + 1 >= $totalPages) {
             $result['page']['next_cursor'] = $totalPages;
         } else {
             $result['page']['next_cursor'] = $currentPage + 1;
         }
     }
     $result['page']['total_number'] = $totalItems;
     return $result;
 }
Esempio n. 4
0
 public function inquiriesPublic()
 {
     $currentPage = $this->app['http']->request->get('page') <= 0 ? 1 : $this->app['http']->request->get('page');
     $itemsPerPage = $this->app['http']->request->get('count') <= 0 ? 5 : $this->app['http']->request->get('count');
     $neighbours = $this->app['http']->request->get('neighbor') <= 0 ? 1 : $this->app['http']->request->get('neighbor');
     $totalItems = $this->app['pdo']->ypyz_inquiry()->count();
     if ($totalItems == 0) {
         return null;
     }
     $pagination = new Pagination($totalItems, $currentPage, $itemsPerPage, $neighbours);
     $offset = $pagination->offset();
     $limit = $pagination->limit();
     $results = $this->app['pdo']->ypyz_inquiry()->order("inquiry_id DESC")->limit($limit, $offset);
     $result = array();
     foreach ($results as $key => $res) {
         $result['data'][$key]['inquiry_id'] = $res['inquiry_id'];
         $result['data'][$key]['patient_id'] = $res['patient_id'];
         $result['data'][$key]['casehistory_id'] = $res['casehistory_id'];
         $result['data'][$key]['description'] = $res['description'];
         $result['data'][$key]['public_userid'] = $res['public_userid'];
         $result['data'][$key]['public_time'] = $res['public_time'];
         $result['data'][$key]['is_solve'] = $res['is_solve'];
         $result['data'][$key]['end_time'] = $res['end_time'];
         $result['data'][$key]['is_reply'] = $res['is_reply'];
         $result['data'][$key]['last_reply_time'] = $res['last_reply_time'];
         $result['data'][$key]['last_reply_userid'] = $res['last_reply_userid'];
         $picture_arr = explode(',', $res['picture']);
         foreach ($picture_arr as $k => $pic) {
             $result['data'][$key]['picture'][$k] = "http://api.didijiankang.cn/api/images/uploads/" . $pic;
         }
     }
     $totalPages = $pagination->totalPages();
     if ($currentPage > $totalPages) {
         $result['page']['current_cursor'] = $totalPages;
         $result['page']['previous_cursor'] = $totalPages == 1 ? 1 : $totalPages - 1;
         $result['page']['next_cursor'] = $totalPages;
     } else {
         $result['page']['current_cursor'] = $currentPage;
         $result['page']['previous_cursor'] = $currentPage <= 1 ? 1 : $currentPage - 1;
         if ($currentPage + 1 >= $totalPages) {
             $result['page']['next_cursor'] = $totalPages;
         } else {
             $result['page']['next_cursor'] = $currentPage + 1;
         }
     }
     $result['page']['total_number'] = $totalItems;
     return $result;
 }
Esempio n. 5
0
 public function replyPublic()
 {
     $currentPage = $this->app['http']->request->get('page') <= 0 ? 1 : $this->app['http']->request->get('page');
     $itemsPerPage = $this->app['http']->request->get('count') <= 0 ? 5 : $this->app['http']->request->get('count');
     $neighbours = $this->app['http']->request->get('neighbor') <= 0 ? 1 : $this->app['http']->request->get('neighbor');
     $totalItems = $this->db_website->ypyz_document_reply()->where('document_id', $this->app['http']->request->get('id'))->count();
     if ($totalItems == 0) {
         return null;
     }
     $pagination = new Pagination($totalItems, $currentPage, $itemsPerPage, $neighbours);
     $offset = $pagination->offset();
     $limit = $pagination->limit();
     $results = $this->db_website->ypyz_document_reply()->where('document_id', $this->app['http']->request->get('id'))->order("id DESC")->limit($limit, $offset);
     $i = 0;
     foreach ($results as $key => $res) {
         $result['data'][$i]['id'] = $res['id'];
         $result['data'][$i]['document_id'] = $res['document_id'];
         $result['data'][$i]['by_userid'] = $res['by_userid'];
         $result['data'][$i]['message'] = $res['message'];
         $result['data'][$i]['public_time'] = $res['public_time'];
         $user = $this->usersShow($res['by_userid']);
         $result['data'][$i]['avatar'] = "http://api.didijiankang.cn/api/images/" . $user['avatar'];
         $result['data'][$i]['nickname'] = $user['nickname'];
         $i++;
     }
     $totalPages = $pagination->totalPages();
     if ($currentPage > $totalPages) {
         $result['page']['current_cursor'] = $totalPages;
         $result['page']['previous_cursor'] = $totalPages == 1 ? 1 : $totalPages - 1;
         $result['page']['next_cursor'] = $totalPages;
     } else {
         $result['page']['current_cursor'] = $currentPage;
         $result['page']['previous_cursor'] = $currentPage <= 1 ? 1 : $currentPage - 1;
         if ($currentPage + 1 >= $totalPages) {
             $result['page']['next_cursor'] = $totalPages;
         } else {
             $result['page']['next_cursor'] = $currentPage + 1;
         }
     }
     $result['page']['total_number'] = $totalItems;
     return $result;
 }
Esempio n. 6
0
 /**
  * Возвращает массив с постраничной навигацией
  *
  * @param $totalItems
  * @param int $currentPage
  * @param int $itemsPerPage
  * @param int $neighbours
  *
  * @return array
  */
 public function getPagination($totalItems, $currentPage = 1, $itemsPerPage = 10, $neighbours = 2)
 {
     $pagination = new Pagination($totalItems, $currentPage, $itemsPerPage, $neighbours);
     return $pagination->build();
 }
Esempio n. 7
0
 public function advisoriesShow()
 {
     $currentPage = $this->app['http']->request->get('page') <= 0 ? 1000000 : $this->app['http']->request->get('page');
     $itemsPerPage = $this->app['http']->request->get('count') <= 0 ? 5 : $this->app['http']->request->get('count');
     $neighbours = $this->app['http']->request->get('neighbor') <= 0 ? 1 : $this->app['http']->request->get('neighbor');
     $totalItems = $this->app['pdo']->ypyz_dialog()->where(array('inquiry_id' => $this->app['http']->request->get('inquiry_id'), 'by_userid' => $this->app['access_token_data']))->count();
     if ($totalItems == 0) {
         return null;
     }
     $pagination = new Pagination($totalItems, $currentPage, $itemsPerPage, $neighbours);
     $offset = $pagination->offset();
     $limit = $pagination->limit();
     $results = $this->app['pdo']->ypyz_dialog()->where(array('inquiry_id' => $this->app['http']->request->get('inquiry_id'), 'by_userid' => $this->app['access_token_data']))->order("send_time ASC")->limit($limit, $offset);
     $result = array();
     foreach ($results as $key => $res) {
         $result['data'][$key]['dialog_id'] = $res['dialog_id'];
         $result['data'][$key]['inquiry_id'] = $res['inquiry_id'];
         $result['data'][$key]['by_userid'] = $res['by_userid'];
         $result['data'][$key]['to_userid'] = $res['to_userid'];
         $result['data'][$key]['reply_id'] = $res['reply_id'];
         $result['data'][$key]['message'] = $res['message'];
         $result['data'][$key]['send_time'] = $res['send_time'];
         $result['data'][$key]['avatar'] = "http://api.didijiankang.cn/api/images/" . $this->userInfo['avatar'];
         $reply_results = $this->app['pdo']->ypyz_dialog()->where(array('reply_id' => $res['dialog_id']))->order("send_time ASC");
         if (count($reply_results)) {
             foreach ($reply_results as $k => $r) {
                 $result['data'][$key]['reply'][$k] = array('dialog_id' => $r['dialog_id'], 'inquiry_id' => $r['inquiry_id'], 'by_userid' => $r['by_userid'], 'to_userid' => $r['to_userid'], 'reply_id' => $r['reply_id'], 'message' => $r['message'], 'send_time' => $r['send_time'], 'avatar' => "http://api.didijiankang.cn/api/images/" . $this->userInfo['avatar']);
             }
         } else {
             $result['data'][$key]['reply'] = array();
         }
     }
     $totalPages = $pagination->totalPages();
     if ($currentPage > $totalPages) {
         $result['page']['current_cursor'] = $totalPages;
         $result['page']['previous_cursor'] = $totalPages == 1 ? 1 : $totalPages - 1;
         $result['page']['next_cursor'] = $totalPages;
     } else {
         $result['page']['current_cursor'] = $currentPage;
         $result['page']['previous_cursor'] = $currentPage <= 1 ? 1 : $currentPage - 1;
         if ($currentPage + 1 >= $totalPages) {
             $result['page']['next_cursor'] = $totalPages;
         } else {
             $result['page']['next_cursor'] = $currentPage + 1;
         }
     }
     $result['page']['total_number'] = $totalItems;
     return $result;
 }