diff --git a/server/SHServ/Entities/Favorite.php b/server/SHServ/Entities/Favorite.php deleted file mode 100644 index bf15da2..0000000 --- a/server/SHServ/Entities/Favorite.php +++ /dev/null @@ -1,33 +0,0 @@ - remove_entity()) { - return false; - } - - if($this -> assignment == "UAdPost") { - (new UAdPost($this -> ent_id)) -> statistics() -> in_favorites_decrease(); - } - - return true; - } -} \ No newline at end of file diff --git a/server/SHServ/Entities/Image.php b/server/SHServ/Entities/Image.php deleted file mode 100644 index ee888af..0000000 --- a/server/SHServ/Entities/Image.php +++ /dev/null @@ -1,75 +0,0 @@ - get_path_to_image($size)); - } - - public function get_url(String $size = "original") { - if(!isset(FCONF["image_resize_map"][$size])){ - // TODO: NORMAL ERR VIEW - dd("Error of size name `{$size}`"); - } - - $postfix = $size == "original" ? "" : "_{$size}"; - - if(!$this -> image_exists($size)) { - if($size == "original") { - return $this -> default_image(); - } else { - return $this -> get_url("original"); - } - } - - $img_name = "{$this -> alias}{$postfix}.jpg"; - - return app() -> routes -> urlto("ImgUploaderController@show_img", [ - "img_name" => $img_name - ]); - } - - public function get_path_to_image(String $size = "original") { - if(!isset(FCONF["image_resize_map"][$size])){ - // TODO: NORMAL ERR VIEW - dd("Error of size name `{$size}`"); - } - - $postfix = $size == "original" ? "" : "_{$size}"; - return FCONF["users_folder"] . "/{$this -> alias}{$postfix}.jpg"; - } - - protected function remove_files() { - foreach (FCONF["image_resize_map"] as $size => $props) { - if($this -> image_exists($size)) { - unlink($this -> get_path_to_image($size)); - } - } - - return true; - } - - public function remove() { - $this -> remove_files(); - return $this -> remove_entity(); - } - - public function default_image() { - return "/SHServ/Resources/img/default-product-img.png"; - } -} \ No newline at end of file diff --git a/server/SHServ/Entities/NPDelivery.php b/server/SHServ/Entities/NPDelivery.php deleted file mode 100644 index ed0ce11..0000000 --- a/server/SHServ/Entities/NPDelivery.php +++ /dev/null @@ -1,22 +0,0 @@ - np_department); - } -} \ No newline at end of file diff --git a/server/SHServ/Entities/Order.php b/server/SHServ/Entities/Order.php deleted file mode 100644 index 2ab5486..0000000 --- a/server/SHServ/Entities/Order.php +++ /dev/null @@ -1,104 +0,0 @@ - uadpost = new UAdPost($this -> uap_id); - $this -> seller = new User($this -> seller_id); - $this -> customer = new User($this -> customer_id); - } - - public function uadpost(): UAdPost { - if(!$this -> was_filled()) { - $this -> fill(); - } - - $this -> uadpost -> currency = $this -> currency; - $this -> uadpost -> price = $this -> price; - return $this -> uadpost; - } - - public function get_formatted_create_at() { - return app() -> utils -> formatted_timestamp($this -> create_at, true); - } - - public function get_delivery_method_text_name() { - $delivery_map = app() -> utils -> get_delivery_method_map(); - return isset($delivery_map[$this -> delivery_method]) ? $delivery_map[$this -> delivery_method] : ""; - } - - public function seller(): User { - if(!$this -> was_filled()) { - $this -> fill(); - } - - return $this -> seller; - } - - public function customer(): User { - if(!$this -> was_filled()) { - $this -> fill(); - } - - return $this -> customer; - } - - public function confirm() { - $this -> state = "confirmed"; - return $this -> update(); - } - - public function cancel() { - $this -> state = "canceled"; - return $this -> update(); - } - - public function complete() { - $this -> state = "completed"; - $this -> seller() -> statistics() -> total_saled_increase(); - $this -> uadpost() -> statistics() -> sales_increase(); - return $this -> update(); - } - - public function remove() { - $this -> remove_entity(); - } - - public function nova_poshta_delivery(): ?NPDelivery { - if($this -> delivery_method !== "1") { - return null; - } - - return $this -> get_pet_instance( - "NPDelivery", - fn() => (new NovaPoshta()) -> get_by_order_id($this -> id) - ); - } -} \ No newline at end of file diff --git a/server/SHServ/Entities/Profile.php b/server/SHServ/Entities/Profile.php index 8ff8e58..310eba8 100644 --- a/server/SHServ/Entities/Profile.php +++ b/server/SHServ/Entities/Profile.php @@ -1,29 +1,18 @@ imgs_container = new ImgsContainer($profile_id, "Profile"); } - public function userpic(): ?Image { - return $this -> imgs_container -> get_first_img(); - } - public function userpic_url(String $size): String { $userpic = $this -> userpic(); return $userpic diff --git a/server/SHServ/Entities/UAdPost.php b/server/SHServ/Entities/UAdPost.php deleted file mode 100644 index 4746885..0000000 --- a/server/SHServ/Entities/UAdPost.php +++ /dev/null @@ -1,213 +0,0 @@ - statistics = new UAdPostStatistics($id); - $this -> imgs_container = new ImgsContainer($id, "UAdPost"); - } - - public function get_images(): Array { - if(!$this -> imgs_container -> was_filled()) { - $this -> imgs_container -> fill_container(); - } - - return $this -> imgs_container -> get_imgs(); - } - - public function get_first_image(): ?Image { - return $this -> imgs_container -> get_first_img(); - } - - public function has_images(): Bool { - return count($this -> get_images()) != 0; - } - - public function fill(Array $data = []) { - parent::fill($data); - $this -> user = new User($this -> uid); - } - - public function user(): User { - if(!$this -> was_filled()) { - $this -> fill(); - } - - return $this -> user; - } - - public function statistics(): UAdPostStatistics { - return $this -> statistics; - } - - public function favorite(): ?Favorite { - if(app() -> sessions -> is_auth() and !$this -> favorite and is_null($this -> favorite_state_for_current_user)) { - $this -> favorite = (new Favourites()) -> get_one_by( - $this -> id(), - "UAdPost", - app() -> sessions -> auth_user() -> id() - ); - } - - $this -> set_favorite_state_for_current_user(!is_null($this -> favorite)); - - return $this -> favorite; - } - - public function set_favorite(Favorite $favorite): ?Favorite { - $this -> favorite = $favorite; - return $this -> favorite(); - } - - public function get_url(): String { - return app() -> routes -> urlto("UAdPostController@view_page", [ - "alias" => "{$this -> alias}.html" - ]); - } - - public function get_formatted_timestamp(): String { - return app() -> utils -> formatted_timestamp($this -> create_at); - } - - public function get_formatted_price(): String { - $price = number_format($this -> price, 2, ",", " "); - return $price; - } - - public function get_price_particles(): Array { - list($banknotes, $coins) = explode(",", $this -> get_formatted_price()) ; - return compact("banknotes", "coins"); - } - - public function get_single_price_particles(): Array { - list($banknotes, $coins) = explode(",", number_format($this -> single_price, 2, ",", " ")); - return compact("banknotes", "coins"); - } - - public function get_formatted_currency(String $currency = ""): String { - $t = [ - "UAH" => "грн", - "EUR" => "€", - "USD" => "$" - ]; - - return $t[ strlen($currency) ? $currency : $this -> currency ]; - } - - public function remove(): Void { - if($this -> has_images()) { - $imgs = $this -> get_images(); - foreach($imgs as $img) { - $img -> remove(); - } - } - - if($this -> state == "published") { - $this -> deactivate(); - } - - $this -> statistics() -> clear_all_fields(); - $this -> remove_entity(); - } - - public function make_removed(): Void { - if($this -> state == "published") { - $this -> deactivate(); - } - - $this -> state = "removed"; - $this -> update(); - } - - public function deactivate(): Void { - $this -> state = "unpublished"; - $this -> update(); - $this -> user() -> statistics() -> total_published_uadposts_decrease(); - $this -> remove_keywords(); - (new Favourites()) -> remove_for_assignment_unit($this -> id(), "UAdPost"); - } - - public function activate(): Void { - $this -> state = "published"; - $this -> update(); - $this -> user() -> statistics() -> total_published_uadposts_increase(); - $this -> refresh_keywords(); - } - - public function is_favorite_for_current_user(): Bool { - if(is_null($this -> favorite_state_for_current_user)) { - $this -> favorite(); - } - - return $this -> favorite_state_for_current_user; - } - - public function set_favorite_state_for_current_user(Bool $state): void { - $this -> favorite_state_for_current_user = $state; - } - - public function generate_keywords(): Array { - $keywords = (new Keywords) -> create_keywords_by_content( - "{$this -> title}", - $this -> id - ); - - $keywords_reload_url = FCONF["services"]["keywords"]["keywords_reload"]; - if($keywords_reload_url) { - @file_get_contents($keywords_reload_url); - } - return $keywords; - } - - public function remove_keywords(): Mixed { - $res = (new Keywords) -> remove_keywords_by_uap_id($this -> id); - $keywords_reload_url = FCONF["services"]["keywords"]["keywords_reload"]; - if($keywords_reload_url) { - @file_get_contents($keywords_reload_url); - } - - return $res; - } - - public function refresh_keywords(): Array { - if(!$this -> remove_keywords()) { - return []; - } - - return $this -> generate_keywords(); - } - - public function keywords(): KeywordsContainer { - return $this -> get_pet_instance( - "KeywordsContainer", - fn() => (new Keywords) -> get_keywords_by_uap_id($this -> id) - ); - } -} \ No newline at end of file diff --git a/server/SHServ/Entities/User.php b/server/SHServ/Entities/User.php index a54b41a..45bf131 100644 --- a/server/SHServ/Entities/User.php +++ b/server/SHServ/Entities/User.php @@ -3,102 +3,32 @@ namespace SHServ\Entities; use \SHServ\Entities\Session; -use \SHServ\Containers\UserStatistics; -use \SHServ\Containers\Registration\UsersContainer; -use \SHServ\Containers\Registration\UAdPostsContainer; -use \SHServ\Models\UAdPosts; -use \SHServ\Models\Favourites; -use \SHServ\Models\Orders; use \SHServ\Entities\Profile; class User extends \SHServ\Middleware\Entity { public static $table_name = "users"; protected static $fields = [ - "id", "alias", "status", "role", "email", "password", "create_at", "update_at" + "id", "role", "nickname", "password", "create_at", "update_at" ]; - protected UserStatistics $statistics; + protected Profile $profile; public function __construct(Int $uid, Array $data = []) { parent::__construct(self::$table_name, $uid, $data); - $this -> statistics = new UserStatistics($uid); // TODO: `uid` - is fail, need `profile_id` $this -> profile = new Profile($uid); - UsersContainer::add_entity_item($this); } public function profile(): Profile { return $this -> profile; } - public function statistics(): UserStatistics { - return $this -> statistics; - } - - public function get_last_uadpost(): ?UAdPost { - $posts = app() -> factory -> getter() -> get_uadposts_by("uid", $this -> id(), 1); - return count($posts) ? $posts[0] : null; - } - - public function total_uadposts(String $state = "published"): Int { - return (new UAdPosts()) -> total_by_user($this -> id(), $state); - } - - public function get_uadposts(String $state = "published", Int $page_num = 1): Array { - $uadposts = (new UAdPosts()) -> get_by_user( - $this -> id(), - $state, - FCONF["profile_uadposts_per_page"], - $page_num, - "update_at" - ); - - UAdPostsContainer::fill(); - - return $uadposts; - } - public function last_session(): ?\SHServ\Entities\Session { return $this -> get_pet_instance("Session", function() { return app() -> factory -> getter() -> get_session_by("uid", $this -> id()); }); } - public function total_favourites_uadposts(): Int { - return (new Favourites()) -> total_by_user( $this -> id(), "UAdPost" ); - } - - public function get_orders(String $utype, Int $page_num = 1, Array $including_states = []): Array { - $sorting_cases = [ - "unconfirmed", - "confirmed", - "canceled", - "completed", - ]; - $order_by = "CASE "; - foreach($sorting_cases as $i => $case) { - $then = $i + 1; - $order_by .= "WHEN `state`='{$case}' THEN {$then} "; - } - $order_by .= " ELSE " . (count($sorting_cases) + 1) . " END"; - $order_by .= ", `create_at`"; - - $orders_model = new Orders(); - $orders = $orders_model -> get_by_user( - $utype, - $this -> id, FCONF["user_orders_per_page"], - $page_num, - $order_by, - "DESC", - $including_states - ); - return $orders; - } - - public function total_orders(String $utype, Array $including_states = []): Int { - return (new Orders()) -> total_by_user($utype, $this -> id, $including_states); - } - public function role_is(String $role_name): Bool { return $this -> role == $role_name; } diff --git a/server/SHServ/Factory/Creator.php b/server/SHServ/Factory/Creator.php index 657529e..6997111 100644 --- a/server/SHServ/Factory/Creator.php +++ b/server/SHServ/Factory/Creator.php @@ -4,10 +4,7 @@ use \SHServ\Entities\Profile; use \SHServ\Entities\User; -use \SHServ\Entities\Image; -use \SHServ\Entities\UAdPost; use \SHServ\Entities\Meta; -use \SHServ\Models\Keywords; class Creator { public function create_user(String $alias, String $email, String $password) { diff --git a/server/SHServ/Utils.php b/server/SHServ/Utils.php index 6d8fe4d..b2dca67 100644 --- a/server/SHServ/Utils.php +++ b/server/SHServ/Utils.php @@ -7,11 +7,6 @@ return header("Location: {$url}"); } - public function gen_alias_from_email(String $email) { - list($alias) = explode("@", $email); - return uniqid() . "-" . $alias; - } - public function table_row_is_exists(\Fury\Modules\ThinBuilder\ThinBuilder $tb_instance, String $tablename, String $field_name, String $value): Bool { return $tb_instance -> count($tablename, [ [$field_name, "=", $value] ]) ? true : false; } @@ -32,10 +27,6 @@ ]); } - public function get_msg_by_alias(String $alias){ - return FCONF['text_msgs'][$alias]; - } - public function compress_image(String $source, String $destination, Int $quality) { $info = getimagesize($source); @@ -70,35 +61,6 @@ \imagejpeg($dst, $output, $quality); } - public function transliterate_cyr_lat(String $str) { - $cyr = [ - 'Љ','Њ','Џ','џ','ш','ђ','ч','ћ','ж','љ','њ','Ш','Ђ','Ч','Ћ', - 'Ж','Ц','ц','а','б','в','г','д','е','ё','ж','з','и','й','к','л','м','н', - 'о','п', 'р','с','т','у','ф','х','ц','ч','ш','щ','ъ','ы','ь','э','ю','я', - 'А','Б','В','Г','Д','Е','Ё','Ж','З','И','Й','К','Л','М','Н','О','П','Р', - 'С','Т','У','Ф','Х','Ц','Ч','Ш','Щ','Ъ','Ы','Ь','Э','Ю','Я','Є','є', - 'Ї','ї','і' - ]; - - $lat = [ - 'Lj','Nj','Dž','dž','š','đ','č','ć','ž','lj','nj','Š','Đ','Č','Ć','Ž','C','c', - 'a','b','v','g','d','e','io','zh','z','i','y','k','l','m','n','o','p', 'r','s', - 't','u','f','h','ts','ch','sh','sht','a','i','y','e','yu','ya', 'A','B','V', - 'G','D','E','Io','Zh','Z','I','Y','K','L','M','N','O','P','R','S','T','U','F', - 'H','Ts','Ch','Sh','Sht','A','I','Y','e','Yu','Ya','Ye','ye','Yi','yi','i', - ]; - - return str_replace($cyr, $lat, $str); - } - - public function gen_from_text_alias(String $str) { - return str_replace( - [" ", ".", ",", "@", "!", "#", '$', "%", "^", "&", "?", "*", "(", ")", "+", "[", "]", "{", "}", ":", ";", "/", "<", ">", "\\"], - ["-", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""], - $this -> transliterate_cyr_lat(strtolower($str)) - ); - } - public function get_current_page_num(): Int { return max(1, intval(isset($_GET["pn"]) ? $_GET["pn"] : 0)); } @@ -109,37 +71,6 @@ return [$from, $per_page]; } - public function lang_mistake_flip(String $str) { - $str = str_replace( - ["{", "}", "!", "@", "#", '$', "%", "^", "&", "*", "(", ")"], - ["", "", "", "", "", '$', "", "", "", "", "", ""], - $str - ); - $vocabluary_lat = "`qwertyuiop[]asdfghjkl;'zxcvbnm,. {}<>-+_1234567890"; - $vocabluary_cyr = "ёйцукенгшщзхъфывапролджэячсмитьбю хъбю-+_1234567890"; - - $len = mb_strlen($str); - $new_str = ""; - for($i = 0; $i < $len; $i++) { - $in_lat = mb_strpos($vocabluary_lat, mb_substr($str, $i, 1)); - $in_cyr = mb_strpos($vocabluary_cyr, mb_substr($str, $i, 1)); - - if($in_lat !== false) { - $new_str .= mb_substr($vocabluary_cyr, $in_lat, 1); - continue; - } - - if($in_cyr !== false) { - $new_str .= mb_substr($vocabluary_lat, $in_cyr, 1); - continue; - } - - $new_str .= $str[$i]; - } - - return $new_str; - } - public function get_default_val_for_type(String $type) { $default_val = null; $types_default_vals = [ @@ -164,31 +95,6 @@ return date("d.m.Y", strtotime($timestamp)); } - public function get_delivery_method_map() { - return [ - 1 => "Новая почта", - 2 => "Укр почта", - 3 => "Самовивоз", - 4 => "Другое", - ]; - } - - public function convert_price_to_uah_from(String $currency, Float $price): Float { - if($currency == "UAH") { - return $price; - } - - $timestamp = date("Ymd"); - $api_request = "https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?valcode={$currency}&date={$timestamp}&json"; - $api_resp = file_get_contents($api_request); - if(!$api_resp) { - return 0; - } - - $resp = json_decode($api_resp, true); - return $resp[0]["rate"] * $price; - } - public function convert_png_to_jpg($png_data) { $png_image = imagecreatefromstring($png_data); $jpg_image = imagecreatetruecolor(imagesx($png_image), imagesy($png_image));