PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/src/BITM/SEIPXXXX/Admin/Admin.php

https://gitlab.com/sdlion/project_the_beginner_b35
PHP | 234 lines | 188 code | 40 blank | 6 comment | 26 complexity | 51cc95c42f07090fde0e34a8baf2549e MD5 | raw file
  1. <?php
  2. namespace App\Admin;
  3. use App\Message\Message;
  4. use App\Utility\Utility;
  5. use App\Model\Database as DB;
  6. use PDO;
  7. class Admin extends DB{
  8. public $id;
  9. public $doctor_name;
  10. public $email;
  11. public $doctor_details;
  12. public $catagory;
  13. public $phone;
  14. public $address;
  15. public $time_duration;
  16. public $image;
  17. public $appointTimeStartHour;
  18. public $appointTimeStartMunute;
  19. public $appointTimeEndHour;
  20. public $appointTimeEndMunute;
  21. public function __construct(){
  22. parent::__construct();
  23. }
  24. public function setData($data=array()){
  25. if(array_key_exists('id',$data)){
  26. $this->id=$data['id'];
  27. }
  28. if(array_key_exists('doctor_name',$data)){
  29. $this->doctor_name=$data['doctor_name'];
  30. }
  31. if(array_key_exists('email',$data)){
  32. $this->email=$data['email'];
  33. }
  34. if(array_key_exists('doctor_details',$data)){
  35. $this->doctor_details=$data['doctor_details'];
  36. }
  37. if(array_key_exists('catagory',$data)){
  38. $this->catagory=$data['catagory'];
  39. }
  40. if(array_key_exists('phone',$data)){
  41. $this->phone=$data['phone'];
  42. }
  43. if(array_key_exists('address',$data)){
  44. $this->address=$data['address'];
  45. }
  46. if(array_key_exists('time_duration',$data)){
  47. $this->time_duration=$data['time_duration'];
  48. }
  49. if(array_key_exists('image',$data)){
  50. $this->image=$data['image'];
  51. }
  52. if(array_key_exists('appointTimeStartHour',$data)){
  53. $this->appointTimeStartHour=$data['appointTimeStartHour'];
  54. }
  55. if(array_key_exists('appointTimeStartMunute',$data)){
  56. $this->appointTimeStartMunute=$data['appointTimeStartMunute'];
  57. }
  58. if(array_key_exists('appointTimeEndHour',$data)){
  59. $this->appointTimeEndHour=$data['appointTimeEndHour'];
  60. }
  61. if(array_key_exists('appointTimeEndMunute',$data)){
  62. $this->appointTimeEndMunute=$data['appointTimeEndMunute'];
  63. }
  64. return $this;
  65. }
  66. public function store() {
  67. $arrData =array($this->doctor_name,$this->email,$this->doctor_details,$this->catagory,$this->phone,$this->address,$this->time_duration,$this->image,$this->appointTimeStartHour,$this->appointTimeStartMunute,$this->appointTimeEndHour,$this->appointTimeEndMunute);
  68. $sql="INSERT INTO doctor(doctor_name,email,doctor_details,catagory,phone,address,time_duration,image,appointTimeStartHour,appointTimeStartMunute,appointTimeEndHour,appointTimeEndMunute) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)";
  69. $STH = $this->conn->prepare($sql);
  70. $result = $STH->execute($arrData);
  71. if ($result) {
  72. Message::message("
  73. <div class=\"alert alert-success\">
  74. <strong>Success!</strong> Data has been stored successfully.
  75. </div>");
  76. return Utility::redirect($_SERVER['HTTP_REFERER']);
  77. }
  78. else {
  79. Message::message("
  80. <div class=\"alert alert-danger\">
  81. <strong>Failed!</strong> Data has not been stored successfully.
  82. </div>");
  83. return Utility::redirect($_SERVER['HTTP_REFERER']);
  84. }
  85. }
  86. public function index($fetchMode='ASSOC')
  87. {
  88. $STH = $this->conn->query('SELECT * from doctor');
  89. $fetchMode = strtoupper($fetchMode);
  90. if(substr_count($fetchMode,'OBJ') > 0)
  91. $STH->setFetchMode(PDO::FETCH_OBJ);
  92. else
  93. $STH->setFetchMode(PDO::FETCH_ASSOC);
  94. $arrAllData = $STH->fetchAll();
  95. return $arrAllData;
  96. }
  97. // end of index();
  98. public function view($fetchMode='ASSOC')
  99. {
  100. $STH = $this->conn->query('SELECT * from doctor where id='.$this->id);
  101. $fetchMode = strtoupper($fetchMode);
  102. if(substr_count($fetchMode,'OBJ') > 0)
  103. $STH->setFetchMode(PDO::FETCH_OBJ);
  104. else
  105. $STH->setFetchMode(PDO::FETCH_ASSOC);
  106. $arrOneData = $STH->fetch();
  107. return $arrOneData;
  108. }
  109. // end of view()
  110. public function update()
  111. {
  112. if(!empty($this->image)) {
  113. $arrData = array($this->doctor_name, $this->email, $this->doctor_details, $this->catagory, $this->phone, $this->address,$this->time_duration, $this->image,$this->appointTimeStartHour,$this->appointTimeStartMunute,$this->appointTimeEndHour,$this->appointTimeEndMunute);
  114. $sql = "UPDATE doctor set doctor_name =?,email =?, doctor_details=?,catagory =?,phone =?,address =?,time_duration=?,image=?,appointTimeStartHour =?,appointTimeStartMunute =?,appointTimeEndHour =?,appointTimeEndMunute =? where id=" . $this->id;
  115. }
  116. else {
  117. $arrData = array($this->doctor_name, $this->email, $this->password, $this->catagory, $this->phone, $this->address, $this->time_duration);
  118. $sql = "UPDATE doctor set doctor_name =?,email =?,doctor_details=?,catagory =?,phone =?,address =?,time_duration=? where id=" . $this->id;
  119. }
  120. $STH = $this->conn->prepare($sql);
  121. $STH->execute($arrData);
  122. Utility::redirect('index.php');
  123. }
  124. public function delete()
  125. {
  126. $sql="Delete from doctor where id=".$this->id;
  127. $STH = $this->conn->prepare($sql);
  128. $result=$STH->execute();
  129. if($result)
  130. Message::message("Success!Data has been deleted successfully");
  131. else
  132. Message::message("Failed!Data has been deleted successfully");
  133. Utility::redirect('index.php');
  134. }
  135. public function search($requestArray){
  136. $sql = "";
  137. if( isset($requestArray['byName']) && isset($requestArray['byCatagory']) ) $sql = "SELECT * FROM `doctor` AND (`doctor_name` LIKE '%".$requestArray['search']."%' OR `catagory` LIKE '%".$requestArray['search']."%')";
  138. if(isset($requestArray['byName']) && !isset($requestArray['byCatagory']) ) $sql = "SELECT * FROM `doctor` AND `doctor_name` LIKE '%".$requestArray['search']."%'";
  139. if(!isset($requestArray['byName']) && isset($requestArray['byCatagory']) ) $sql = "SELECT * FROM `doctor` AND `catagory` LIKE '%".$requestArray['search']."%'";
  140. $STH = $this->conn->query($sql);
  141. $STH->setFetchMode(PDO::FETCH_OBJ);
  142. $allData = $STH->fetchAll();
  143. return $allData;
  144. }
  145. public function getAllKeywords()
  146. {
  147. $_allKeywords = array();
  148. $WordsArr = array();
  149. $sql = "SELECT * FROM `doctor`";
  150. $STH = $this->conn->query($sql);
  151. $STH->setFetchMode(PDO::FETCH_OBJ);
  152. // for each search field block start
  153. $allData= $STH->fetchAll();
  154. foreach ($allData as $oneData) {
  155. $_allKeywords[] = trim($oneData->doctor_name);
  156. }
  157. $STH = $this->conn->query($sql);
  158. $STH->setFetchMode(PDO::FETCH_OBJ);
  159. $allData= $STH->fetchAll();
  160. foreach ($allData as $oneData) {
  161. $eachString= strip_tags($oneData->catagory);
  162. $eachString=trim( $eachString);
  163. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  164. $eachString= str_replace("&nbsp;","", $eachString);
  165. $WordsArr = explode(" ", $eachString);
  166. foreach ($WordsArr as $eachWord){
  167. $_allKeywords[] = trim($eachWord);
  168. }
  169. }
  170. // for each search field block end
  171. // for each search field block start
  172. $STH = $this->conn->query($sql);
  173. $STH->setFetchMode(PDO::FETCH_OBJ);
  174. $allData= $STH->fetchAll();
  175. foreach ($allData as $oneData) {
  176. $_allKeywords[] = trim($oneData->catagory);
  177. }
  178. $STH = $this->conn->query($sql);
  179. $STH->setFetchMode(PDO::FETCH_OBJ);
  180. $allData= $STH->fetchAll();
  181. foreach ($allData as $oneData) {
  182. $eachString= strip_tags($oneData->catagory);
  183. $eachString=trim( $eachString);
  184. $eachString= preg_replace( "/\r|\n/", " ", $eachString);
  185. $eachString= str_replace("&nbsp;","", $eachString);
  186. $WordsArr = explode(" ", $eachString);
  187. foreach ($WordsArr as $eachWord){
  188. $_allKeywords[] = trim($eachWord);
  189. }
  190. }
  191. // for each search field block end
  192. return array_unique($_allKeywords);
  193. }
  194. }