Advertisement
Talar97

Stronicowanie

Jun 22nd, 2019
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.53 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: TalarPC
  5.  * Date: 11.06.2019
  6.  * Time: 19:03
  7.  */
  8.  
  9. namespace app\controllers;
  10.  
  11. use core\App;
  12. use core\Logs;
  13. use core\ParamUtils;
  14. use core\Utils;
  15. use core\SessionUtils;
  16.  
  17. class ShopManagerControl
  18. {
  19.     public $places;
  20.     public $place;
  21.     public $offset = 1;
  22.     public $records = 50;
  23.  
  24.     public function getPlacesFromDB(){
  25.         try{
  26.             $this->places = App::getDB()->select("markers",[
  27.                 "[>]marker_details" => ["id" => "id_marker"],
  28.                 "[>]user" => ["marker_details.author" => "id"]
  29.             ],[
  30.                 'markers.id',
  31.                 'markers.name',
  32.                 'markers.address',
  33.                 'user.login',
  34.                 'user.id(userid)',
  35.                 'marker_details.votes',
  36.             ],[
  37.                 'LIMIT' => [(($this->offset - 1) * $this->records), $this->records]
  38.             ]);
  39.         }catch(\PDOException $e){
  40.             Utils::addErrorMessage("Błąd połączenia z bazą danych!".$e->getMessage());
  41.         }
  42.     }
  43.  
  44.     public function getPlaceFromDB($id){
  45.         try{
  46.             $this->place = App::getDB()->get("markers",[
  47.                 "[>]marker_details" => ["id" => "id_marker"],
  48.                 "[>]user" => ["marker_details.author" => "id"]
  49.             ],[
  50.                 'markers.id',
  51.                 'markers.name',
  52.                 'markers.address',
  53.                 'markers.lat',
  54.                 'markers.lng',
  55.                 'markers.type',
  56.                 'marker_details.description',
  57.                 'marker_details.category[JSON]',
  58.                 'marker_details.open_hour',
  59.                 'marker_details.close_hour',
  60.                 'marker_details.added_time',
  61.                 'marker_details.author',
  62.                 'marker_details.votes',
  63.                 'user.login',
  64.                 'user.id(userid)'
  65.             ],[
  66.                 'id_marker' => $id
  67.             ]);
  68.  
  69.             //$this->place['category'] = json_decode($this->place['category']);
  70.         }catch(\PDOException $e){
  71.             Utils::addErrorMessage("Błąd połączenia z bazą danych!");
  72.         }
  73.     }
  74.  
  75.     public function deletePlace($id){
  76.         try{
  77.             $result = App::getDB()->has("markers",[
  78.                 'id' => $id
  79.             ]);
  80.  
  81.             if($result){
  82.                 App::getDB()->delete("markers",[
  83.                     'id' => $id
  84.                 ]);
  85.  
  86.                 App::getDB()->delete("marker_details",[
  87.                     'id_marker' => $id
  88.                 ]);
  89.  
  90.                 Utils::addInfoMessage("Miejsce (".$id.") zostało usunięte");
  91.                 $admin_login = SessionUtils::load("login", true);
  92.                 Logs::addLog("Miejsce (".$id.") zostało usunięte przez ".$admin_login);
  93.             }
  94.             else{
  95.                 Utils::addErrorMessage("Miejsce nie istnieje");
  96.             }
  97.         }catch(\PDOException $e){
  98.             Utils::addErrorMessage("Błąd połączenia z bazą danych!");
  99.         }
  100.  
  101.         return false;
  102.     }
  103.  
  104.     public function action_managePlaces(){
  105.         $option = ParamUtils::getFromCleanURL(2);
  106.         $place_id = ParamUtils::getFromCleanURL(3);
  107.  
  108.         switch ($option){
  109.             case 'details':
  110.                 $this->getPlaceFromDB($place_id);
  111.                 App::getSmarty()->assign("details", true);
  112.                 App::getSmarty()->assign("placeDetails", $this->place);
  113.                 break;
  114.             case "delete" :
  115.                 $this->deletePlace($place_id);
  116.                 break;
  117.             case "edit" :
  118.                 $this->getPlaceFromDB($place_id);
  119.                 App::getSmarty()->assign("edit", true);
  120.                 App::getSmarty()->assign("placeDetails", $this->place);
  121.                 break;
  122.         }
  123.  
  124.  
  125.         $offset = ParamUtils::getFromCleanURL(1);
  126.         if(isset($offset) && is_numeric($offset) && $offset > 0) $this->offset += $offset - 1;
  127.         if(isset($offset) && $offset == 0) $this->records = App::getDB()->count("user","*");
  128.         $this->generateView();
  129.     }
  130.  
  131.     public function generateView(){
  132.         $this->getPlacesFromDB();
  133.         App::getSmarty()->assign("places", $this->places);
  134.         App::getSmarty()->assign("offset", $this->offset);
  135.         App::getSmarty()->assign("next_page", $this->offset + 1);
  136.         App::getSmarty()->assign("previous_page", $this->offset - 1);
  137.         App::getSmarty()->assign("page_title", "Zarządzanie miejscami");
  138.         App::getSmarty()->display("ManagePlacesView.tpl");
  139.     }
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement