-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#67 Рефакторинг PHP
- Loading branch information
Showing
5 changed files
with
121 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
class Anekdot { | ||
/** Список всех анекдотов | ||
* @returns {Array[id, number, caption, anekdot]} | ||
*/ | ||
public static function all() { | ||
return Api::select('id, number, title', 'anekdot', ['hide' => 0]); | ||
} | ||
|
||
/** Добавление нового анекдота | ||
* @param caption {string} название анекдота (@todo - сделать необязательным) | ||
* @param number {number?} номер добавляемого анекдота | ||
* @param text {string} первая версия текста анекдота | ||
* @param name {string} название первой версии текста анекдота | ||
* @returns {Array} anekdot.all | ||
*/ | ||
public static function add($caption, $number, $text, $name = '') { | ||
$anekdot = Api::insert('anekdot', ['title' => $caption, 'number' => $number]); | ||
$version = Anekdot::upd($anekdot, $text, $name); | ||
/** @todo проверка успешности добавления */ | ||
return Anekdot::all(); | ||
} | ||
|
||
/** Полная информация об анекдоте | ||
* @param id {natural} идентификатор анекдота | ||
* @returns {Anekdot} | ||
*/ | ||
public static function get($id) { | ||
$anekdot = Api::select('id, number, title', 'anekdot', ['anekdot.hide' => 0, 'anekdot.id' => $id])[0]; | ||
$anekdot['version'] = Anekdot::versions($anekdot['id']); | ||
$anekdot['tag'] = Anekdot::tags ($anekdot['id']); | ||
return $anekdot; | ||
} | ||
|
||
/** Список тегов анекдота | ||
* @param anekdot {natural} идентификатор анекдота | ||
* @returns {Array} of Tag | ||
*/ | ||
public static function tags($anekdot) { | ||
return Api::select('tag.id, tag.title', 'link, tag', ['link.anekdot' => $anekdot, 'link.hide' => 0, 'tag.hide' => 0], ['link.tag' => 'tag.id']); | ||
} | ||
|
||
/** Список версий текста анекдота | ||
* @param anekdot {natural} идентификатор анекдота | ||
* @returns {Array} of Tag | ||
*/ | ||
public static function versions($anekdot) { | ||
return Api::select('title, text', 'version', ['anekdot' => $anekdot, 'hide' => 0]); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
class Ratio { | ||
/** Добавление анекдоту номера | ||
* @param anekdot {natural} идентификатор анекдота | ||
* @param number {natural} добавляемый номер | ||
* @returns {Anekdot} anekdot.get | ||
*/ | ||
public static function attach($anekdot, $number) { | ||
// @todo unique | ||
Api::update('anekdot', ['number' => $number], $anekdot); | ||
return Anekdot::get($anekdot); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
class Tag { | ||
/** Список всех тегов | ||
* @returns {Array} of Tag | ||
*/ | ||
public static function all() { // вернуть список всех тегов | ||
return Api::select('*', 'tag', ['hide' => 0]); | ||
} | ||
|
||
/** Добавление тега | ||
* @param name {string} название добавляемого тега | ||
* @returns {Array} tag.all | ||
*/ | ||
public static function add($name) { // Добавить новый тег и вернуть список всех | ||
$result = Api::insert('tag', ['title' => $name]); // в фон (@todo?) | ||
return Tag::all(); | ||
} | ||
|
||
/** Список всех анекдотов с выбранным тегом | ||
* @param tag {natural} идентификатор тега | ||
* @returns {Array} | ||
*/ | ||
public static function get($tag) { | ||
return Api::select('anekdot', 'link', ['tag' => $tag]); | ||
} | ||
|
||
/** Добавление тега анекдоту | ||
* @param anekdot {natural} идентификатор анекдота | ||
* @param tag {natural} идентификатор тега | ||
* @returns {Anekdot} anekdot.get | ||
*/ | ||
public static function attach($tag, $anekdot) { | ||
Api::insert('link', ['anekdot' => $anekdot, 'tag' => $tag]); | ||
return Anekdot::get($anekdot); | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
class Version { | ||
/** Добавление версии текста анекдота | ||
* @param anekdot {natural} идентификатор анекдота | ||
* @param text {string} текст добавляемой версии | ||
* @param name {string?} название добавляемой версии | ||
*/ | ||
public static function attach($anekdot, $text, $name) { | ||
Api::insert('version', ['anekdot' => $anekdot, 'text' => $text, 'title' => $name]); | ||
return Anekdot::versions($anekdot); | ||
} | ||
} | ||
?> |