diff --git a/server/SHServ/Factory/Creator.php b/server/SHServ/Factory/Creator.php index 6997111..6e0c5bb 100644 --- a/server/SHServ/Factory/Creator.php +++ b/server/SHServ/Factory/Creator.php @@ -29,57 +29,6 @@ return $profile_id ? new Profile($profile_id) : null; } - public function create_image(Int $uid, Int $ent_id, String $assignment, String $alias, Int $sequence = 0) { - $image_id = app() -> thin_builder -> insert(Image::$table_name, [ - "uid" => $uid, - "ent_id" => $ent_id, - "assignment" => $assignment, - "alias" => $alias, - "sequence" => $sequence, - "create_at" => date("Y-m-d H:i:s") - ]); - - return $image_id ? new Image($image_id) : null; - } - - public function create_uadpost( - Int $uid, String $title, String $content, Int $condition, Int $exchange_flag, - Float $price, String $currency, Float $lat, Float $lng, String $country_en, - String $country_ru, String $region_en, String $region_ru, String $city_en, - String $city_ru, Int $images_number, String $state = "published" - ) { - $uadpost_id = app() -> thin_builder -> insert(UAdPost::$table_name, [ - "uid" => $uid, - "alias" => app() -> utils -> gen_from_text_alias(uniqid() . "-" . $title), - "title" => $title, - "content" => $content, - "condition_used" => $condition, - "exchange_flag" => $exchange_flag, - "state" => $state, - "price" => $price, - "single_price" => app() -> utils -> convert_price_to_uah_from($currency, $price), - "currency" => $currency, - "location_lat" => $lat, - "location_lng" => $lng, - "country_en" => $country_en, - "country_ru" => $country_ru, - "region_en" => $region_en, - "region_ru" => $region_ru, - "city_en" => $city_en, - "city_ru" => $city_ru, - "factor" => 1, - "rating" => 0, - "images_number" => intval($images_number), - "update_at" => date("Y-m-d H:i:s") - ]); - - $uadpost = $uadpost_id ? new UAdPost($uadpost_id) : null; - if($uadpost) { - $uadpost -> generate_keywords(); - } - return $uadpost; - } - public function create_meta(Int $ent_id, String $assignment, String $name, $value): Meta { $data = [ "ent_id" => $ent_id, diff --git a/server/SHServ/Factory/Getter.php b/server/SHServ/Factory/Getter.php index 59dff3d..027d9e1 100644 --- a/server/SHServ/Factory/Getter.php +++ b/server/SHServ/Factory/Getter.php @@ -4,17 +4,15 @@ use \SHServ\Entities\User; use \SHServ\Entities\Profile; -use \SHServ\Entities\Image; -use \SHServ\Entities\UAdPost; use \SHServ\Entities\Session; use \SHServ\Entities\Meta; -use \SHServ\Entities\Order; -use \SHServ\Containers\Registration\UAdPostsContainer; class Getter { public function get_user_by(String $field_name, $field_value): ?User { $result = app() -> thin_builder -> select( - User::$table_name, User::get_fields(), [ [$field_name, "=", $field_value] ] + User::$table_name, + User::get_fields(), + [ [$field_name, "=", $field_value] ] ); if(!$result) { @@ -40,52 +38,6 @@ return new Profile($result[0]["id"]); } - public function get_images_by_entity(Int $ent_id, String $assignment, Int $amount = 10) { - $result = app() -> thin_builder -> select( - Image::$table_name, - [], - [ ["ent_id", "=", $ent_id], "AND", ["assignment", "=", $assignment] ], - [ "sequence" ], - "ASC", - [0, $amount] - ); - - if(!$result) { - return []; - } - - $images = []; - foreach($result as $item) { - $images[] = new Image($item["id"], $item); - } - - return $images; - } - - public function get_uadposts_by(String $field_name, $field_value, Int $amount = 10): Array { - $result = app() -> thin_builder -> select( - UAdPost::$table_name, - ["id"], - [[ $field_name, is_array($field_value) ? "IN" : "=", $field_value ]], - [ "id" ], - "DESC", - [0, $amount] - ); - - if(!$result) { - return []; - } - - $uadposts = []; - foreach($result as $item) { - $uadposts[] = new UAdPost($item["id"]); - } - - UAdPostsContainer::fill(); - - return $uadposts; - } - public function get_session_by(String $field_name, $field_value): ?Session { $result = app() -> thin_builder -> select( Session::$table_name, @@ -124,28 +76,4 @@ return $meta; } - - public function get_orders_by(String $field_name, $field_value, Int $amount = 10) : Array { - $result = app() -> thin_builder -> select( - Order::$table_name, - Order::get_fields(), - [ - [ $field_name, is_array($field_value) ? "IN" : "=", $field_value ] - ], - [ "id" ], - "DESC", - [0, $amount] - ); - - if(!$result) { - return []; - } - - $orders = []; - foreach($result as $item) { - $orders[] = new Order($item["id"], $item); - } - - return $orders; - } } \ No newline at end of file diff --git a/server/SHServ/Helpers/Generator.php b/server/SHServ/Helpers/Generator.php deleted file mode 100644 index 50cfdda..0000000 --- a/server/SHServ/Helpers/Generator.php +++ /dev/null @@ -1,110 +0,0 @@ - lorem_ipsum = new LoremIpsum(); - } - - public function generate_random_users(Int $amount = 10) { - for($i = 0; $i < $amount; $i++) { - $email = $this -> lorem_ipsum -> get_email(); - $password = "1111"; - $user = (new Auth()) -> signup($email, $password); - $user -> profile() -> first_name = $this -> lorem_ipsum -> get_name(); - $user -> profile() -> second_name = $this -> lorem_ipsum -> get_surname(); - $user -> profile() -> phone_number = $this -> lorem_ipsum -> get_phone_number(); - $user -> profile() -> location_lat = rand(400000, 600000) / 10000; - $user -> profile() -> location_lng = rand(220000, 300000) / 10000; - $user -> profile() -> update(); - echo "\n#{$i} {$user -> profile() -> first_name} {$email} {$password}"; - } - - echo "\nDone"; - } - - public function generate_random_uadpost(Int $amount = 10) { - for($i = 0; $i < $amount; $i++) { - $rand_user = app() -> factory -> getter() -> get_user_by("id", rand(1, 9999)); - $title = $this -> lorem_ipsum -> gen_paragraph(1); - - $uadpost = app() -> factory -> creator() -> create_uadpost( - $rand_user -> id(), - $title, - "

" . implode("

", $this -> lorem_ipsum -> gen_paragraphs(rand(1, 8), 1, 20)) . "

", - rand(1, 2), - rand(0, 1), - rand(0, 10000), - "UAH", - rand(400000, 600000) / 10000, - rand(220000, 300000) / 10000, - "Ukraine", - "Украина", - "TestRegion", - "ТестРегион", - "TestCity", - "ТестГород", - 0 - ); - - echo "\n#{$i} {$title}"; - } - - echo "\nDone"; - } - - public function generate_uadpost_from_json($json_data) { - $uadpost_data = json_decode($json_data); - - $rand_user = app() -> factory -> getter() -> get_user_by("id", rand(1, 9999)); - - $images = new Images(); - if($uadpost_data -> image and strlen($uadpost_data -> image)) { - echo "Upload image " . $uadpost_data -> image . "\n"; - $img = @file_get_contents($uadpost_data -> image); - if($img) { - $img = (new Utils()) -> convert_png_to_jpg($img); - $img = "data:image/jpeg;base64," . base64_encode($img); - $img_upload_result = $images -> upload($img); - } - } - - echo "Creating UAdPost\n"; - $uadpost = app() -> factory -> creator() -> create_uadpost( - $rand_user -> id(), - $uadpost_data -> title, - $uadpost_data -> description, - rand(1, 2), - rand(0, 1), - $uadpost_data -> price, - $uadpost_data -> currency, - rand(400000, 600000) / 10000, - rand(220000, 300000) / 10000, - "Ukraine", - "Украина", - "TestRegion", - "ТестРегион", - "TestCity", - "ТестГород", - $img_upload_result ? 1 : 0 - ); - - if($uadpost and $img_upload_result) { - $images -> create_from_aliases( - [ $img_upload_result["alias"] ], - $uadpost, - $rand_user -> id() - ); - } - - echo "Was created \n"; - } -} \ No newline at end of file diff --git a/server/console.php b/server/console.php index 78e6806..44c0d06 100644 --- a/server/console.php +++ b/server/console.php @@ -3,21 +3,10 @@ include_once "Fury/fury.php"; $app = fury_init("SHServ"); -use \SHServ\Helpers\Generator; - function console() { global $argv; switch($argv[1]) { - case "generator.users": - (new Generator()) -> generate_random_users($argv[2]); - break; - case "generator.uadposts": - (new Generator()) -> generate_random_uadpost($argv[2]); - break; - case "create.uadpost": - (new Generator()) -> generate_uadpost_from_json($argv[2]); - break; case "get.config": echo json_encode(FCONF); break;