PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Bitm/SEIP124310/ProfilePicture/ImageUploader.php

https://gitlab.com/Hoq/lab_exem7_B21_Rakib_SEIP124310
PHP | 145 lines | 116 code | 28 blank | 1 comment | 12 complexity | e06e5fd17686f03f30e264612f71ec56 MD5 | raw file
  1. <?php
  2. namespace App\Bitm\SEIP124310\ProfilePicture;
  3. use App\Bitm\SEIP124310\Message\Message;
  4. use App\Bitm\SEIP124310\Utility\Utility;
  5. class ImageUploader
  6. {
  7. public $id = "";
  8. public $name = "";
  9. public $image_name = "";
  10. public $conn;
  11. public function __construct()
  12. {
  13. $this->conn = mysqli_connect("localhost", "root", "", "atomicprojectb21") or die("Database connection failed");
  14. }
  15. public function prepare($data = array())
  16. {
  17. if (array_key_exists("name", $data)) {
  18. $this->name = filter_var($data['name'], FILTER_SANITIZE_STRING);
  19. }
  20. if (array_key_exists("image", $data)) {
  21. $this->image_name = filter_var($data['image'], FILTER_SANITIZE_STRING);
  22. }
  23. if (array_key_exists("id", $data)) {
  24. $this->id = $data['id'];
  25. }
  26. return $this;
  27. }
  28. public function index(){
  29. $_allInfo= array();
  30. $query="SELECT * FROM `profilepicture`";
  31. $result= mysqli_query($this->conn,$query);
  32. //You can also use mysqli_fetch_object e.g: $row= mysqli_fetch_object($result)
  33. while($row= mysqli_fetch_assoc($result)){
  34. $_allInfo[]=$row;
  35. }
  36. return $_allInfo;
  37. }
  38. public function view(){
  39. $query="SELECT * FROM `profilepicture` WHERE `id`=".$this->id;
  40. $result= mysqli_query($this->conn,$query);
  41. $row= mysqli_fetch_assoc($result);
  42. return $row;
  43. }
  44. public function store() {
  45. $query="INSERT INTO `atomicprojectb21`.`profilepicture` (`name`,`images`) VALUES ('{$this->name}','{$this->image_name}')";
  46. $result= mysqli_query($this->conn,$query);
  47. if($result){
  48. Message::message("Data has benn stored successfully");
  49. Utility::redirect('index.php');
  50. }else{
  51. Message::message("Data has not been stored successfully");
  52. Utility::redirect('index.php');
  53. }
  54. }
  55. public function delete(){
  56. $query="DELETE FROM `atomicprojectb21`.`profilepicture` WHERE `profilepicture`.`id` = ".$this->id;
  57. $result= mysqli_query($this->conn,$query);
  58. if($result){
  59. Message::message("<div class=\"alert alert-success\">
  60. <strong>Deleted!</strong> Data has been deleted successfully.
  61. </div>");
  62. header('Location:index.php');
  63. } else {
  64. Message::message("<div class=\"alert alert-danger\">
  65. <strong>Error!</strong> Data has not been deleted successfully.
  66. </div>");
  67. Utility::redirect('index.php');
  68. }
  69. }
  70. public function update(){
  71. $query="UPDATE `atomicprojectb21`.`profilepicture` SET `name` = '{$this->name}', `images` = '{$this->image_name}' WHERE `profilepicture`.`id` = ".$this->id;
  72. $result= mysqli_query($this->conn,$query);
  73. if($result){
  74. Message::message("<div class=\"alert alert-info\">
  75. <strong>Updated!</strong> Data has been Updated successfully.
  76. </div>");
  77. header('Location:index.php');
  78. } else {
  79. Message::message("<div class=\"alert alert-danger\">
  80. <strong>Error!</strong> Data has not been updated successfully.
  81. </div>");
  82. Utility::redirect('index.php');
  83. }
  84. }
  85. public function active(){
  86. $query1="UPDATE `atomicprojectb21`.`profilepicture` SET `deleted_at` = NULL";
  87. $result1= mysqli_query($this->conn,$query1);
  88. $query="UPDATE `atomicprojectb21`.`profilepicture` SET `deleted_at` = 'A' WHERE `profilepicture`.`id` = ".$this->id;
  89. $result= mysqli_query($this->conn,$query);
  90. if($result){
  91. Message::message("<div class=\"alert alert-success\">
  92. <strong>Deleted!</strong> Data has been Activate successfully.
  93. </div>");
  94. header('Location:index.php');
  95. } else {
  96. Message::message("<div class=\"alert alert-danger\">
  97. <strong>Error!</strong> Data has not been Activate successfully.
  98. </div>");
  99. Utility::redirect('index.php');
  100. }
  101. }
  102. public function inactive(){
  103. $query="UPDATE `atomicprojectb21`.`profilepicture` SET `deleted_at` = NULL WHERE `profilepicture`.`id` = ".$this->id;
  104. $result= mysqli_query($this->conn,$query);
  105. if($result){
  106. Message::message("<div class=\"alert alert-success\">
  107. <strong>Deleted!</strong> Data has been Inactivated successfully.
  108. </div>");
  109. header('Location:index.php');
  110. } else {
  111. Message::message("<div class=\"alert alert-danger\">
  112. <strong>Error!</strong> Data has not been Inactivated successfully.
  113. </div>");
  114. Utility::redirect('index.php');
  115. }
  116. }
  117. }