diff --git a/Web/Models/Entities/Audio.php b/Web/Models/Entities/Audio.php deleted file mode 100644 index f27e7fc2..00000000 --- a/Web/Models/Entities/Audio.php +++ /dev/null @@ -1,65 +0,0 @@ -analyze($filename); - if(isset($meta["error"])) - throw new ISE(implode(", ", $meta["error"])); - - $this->setPerformer("Неизвестно"); - $this->setName("Без названия"); - } catch(\Exception $ex) { - exit("Хакеры? Интересно..."); - } - - return rename($filename, OPENVK_ROOT . "/storage/" . substr($hash, 0, 2) . "/$hash.mpeg3"); - } - - function getName(): string - { - return $this->getRecord()->name; - } - - function getPerformer(): string - { - return $this->getRecord()->performer; - } - - function getGenre(): string - { - return $this->getRecord()->genre; - } - - function getLyrics(): ?string - { - return $this->getRecord()->lyrics; - } - - function getCanonicalName(): string - { - return $this->getRecord()->performer . " — " . $this->getRecord()->name; - } - - function wire(): void - { - \Chandler\Database\DatabaseConnection::i()->getContext()->table("audio_relations")->insert([ - "user" => $this->getRecord()->owner, - "audio" => $this->getId(), - ]); - } -} diff --git a/Web/Models/Repositories/Audios.php b/Web/Models/Repositories/Audios.php deleted file mode 100644 index 8cf305b0..00000000 --- a/Web/Models/Repositories/Audios.php +++ /dev/null @@ -1,38 +0,0 @@ -context = DatabaseConnection::i()->getContext(); - $this->audios = $this->context->table("audios"); - $this->rels = $this->context->table("audio_relations"); - } - - function get(int $id): ?Video - { - $videos = $this->videos->get($id); - if(!$videos) return NULL; - - return new Audio($videos); - } - - function getByUser(User $user, int $page = 1, ?int $perPage = NULL): \Traversable - { - $perPage = $perPage ?? OPENVK_DEFAULT_PER_PAGE; - foreach($this->rels->where("user", $user->getId())->page($page, $perPage) as $rel) - yield $this->get($rel->audio); - } - - function getUserAudiosCount(User $user): int - { - return sizeof($this->rels->where("user", $user->getId())); - } -} diff --git a/Web/Presenters/AudiosPresenter.php b/Web/Presenters/AudiosPresenter.php deleted file mode 100644 index 1538841e..00000000 --- a/Web/Presenters/AudiosPresenter.php +++ /dev/null @@ -1,118 +0,0 @@ -music = $music; - - parent::__construct(); - } - - function renderApp(int $user = 0): void - { - $this->assertUserLoggedIn(); - - $user = (new Users)->get($user === 0 ? $this->user->id : $user); - if(!$user) - $this->notFound(); - - $this->template->user = $user; - } - - function renderUpload(): void - { - $this->assertUserLoggedIn(); - $this->willExecuteWriteAction(); - - if($_SERVER["REQUEST_METHOD"] === "POST") { - if(!isset($_FILES["blob"])) - $this->flashFail("err", "Нету файла", "Выберите файл."); - - try { - $audio = new Audio; - $audio->setFile($_FILES["blob"]); - $audio->setOwner($this->user->id); - $audio->setCreated(time()); - if(!empty($this->postParam("name"))) - $audio->setName($this->postParam("name")); - if(!empty($this->postParam("performer"))) - $audio->setPerformer($this->postParam("performer")); - if(!empty($this->postParam("lyrics"))) - $audio->setLyrics($this->postParam("lyrics")); - if(!empty($this->postParam("genre"))) - $audio->setGenre($this->postParam("genre")); - } catch(ISE $ex) { - $this->flashFaile("err", "Произшла ошибка", "Файл повреждён или имеет неверный формат."); - } - - $audio->save(); - $audio->wire(); - - $this->redirect("/audios" . $this->user->id, static::REDIRECT_TEMPORARY); - } - } - - function renderApiList(int $user, int $page = 1): void - { - $this->assertUserLoggedIn(); - - header("Content-Type: application/json"); - - $owner = (new Users)->get($user); - if(!$owner) { - header("HTTP/1.1 404 Not Found"); - exit(json_encode([ - "result" => "error", - "response" => [ - "error" => [ - "code" => 2 << 4, - "desc" => "No user with id = $user", - ], - ], - ])); - } - - $music = []; - foreach($this->music->getByUser($owner, $page) as $audio) { - $music[] = [ - "id" => $audio->getId(), - "name" => [ - "actual" => $audio->getName(), - "full" => $audio->getCanonicalName(), - ], - "performer" => $audio->getPerformer(), - "genre" => $audio->getGenre(), - "lyrics" => $audio->getLyrics(), - "meta" => [ - "available_formats" => ["mp3"], - "user_unique_id" => $audio->getVirtualId(), - "created" => (string) $audio->getPublicationTime(), - ], - "files" => [ - [ - "format" => "mp3", - "url" => $audio->getURL(), - ], - ], - ]; - } - - exit(json_encode([ - "result" => "success", - "method" => "list", - "response" => [ - "count" => $this->music->getUserAudiosCount($owner), - "music" => $music, - "page" => $page, - ], - ])); - } -} diff --git a/Web/Presenters/templates/Audios/App.xml b/Web/Presenters/templates/Audios/App.xml deleted file mode 100644 index c9481cfd..00000000 --- a/Web/Presenters/templates/Audios/App.xml +++ /dev/null @@ -1,52 +0,0 @@ -{extends "../@layout.xml"} -{block title}Аудиопроигрыватель{/block} - -{block header} - {$user->getCanonicalName()} - » - Аудиозаписи -{/block} - - - -{block content} -