Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #42 from DainWs/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
DainWs authored Jun 12, 2022
2 parents 43265b5 + 4b6887b commit 3bf8f4f
Show file tree
Hide file tree
Showing 49 changed files with 916 additions and 397 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ void-eye-games-client/src/assets/css/App.css.map
.crt/
.crt/server.key
.crt/server.csr
docs/StyleManual.docx
docs/VoidEyeGame-Documentation.docx
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 1 addition & 4 deletions sql/SQLQueries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,4 @@ SELECT * FROM categories_games;

USE void_eye_games;
SELECT * FROM plataforms;
SELECT * FROM plataforms_games;


SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = 'void_eye_games';
SELECT * FROM plataforms_games;
34 changes: 29 additions & 5 deletions void-eye-games-api/src/classes/Category/CategoryRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ class CategoryRecord extends Record
{
use CategoryFields;

public function addCategoryGame(Array $categoriesGames, Atlas $atlas) {
/**
* Adds a category relationship to this CategoryRecord.
* @param Array $categoriesGames a list of properties from CategoriesGames objects.
* @param Atlas $atlas the atlas instance.
*/
public function addCategoryGame(Array $categoriesGames, Atlas $atlas): void
{
if (!$this->categories_games) $this->categories_games = $atlas->newRecordSet(CategoriesGame::class);

$categoriesGames['categoriesId'] = $this->id;
Expand All @@ -29,22 +35,40 @@ public function addCategoryGame(Array $categoriesGames, Atlas $atlas) {
$this->categories_games->appendNew($categoriesGames);
}

public function update(Array $updatedCategory, Atlas $atlas)
/**
* Updates a category with other Category array representation object.
* @param Array $updatedCategory a list of properties from Category objects.
* @param Atlas $atlas the atlas instance.
* @throws AppException if already exists a category with that name
*/
public function update(Array $updatedCategory, Atlas $atlas): void
{
$this->updateName($updatedCategory['name'] ?? null, $atlas);
$this->updateCategoriesGames($updatedCategory['categories_games'] ?? null, $atlas);
}

public function updateName(?string $name, Atlas $atlas)
/**
* Updates the category name.
* @param ?String $name the new name.
* @param Atlas $atlas the atlas instance.
* @throws AppException if already exists a category with that name
*/
public function updateName(?string $name, Atlas $atlas): void
{
if (!$name || empty($name)) return;
$searchedCategory = $atlas->select(Category::class, ['name' => $name])->where('id !=', $this->id)->fetchRecord();
if ($searchedCategory) throw new AppException('There is already a category with this name.');
$this->name = $name;
}

public function updateCategoriesGames(?Array $categoriesGames, Atlas $atlas) {
if (!$categoriesGames) return;
/**
* Updates the category relationships.
* @param ?Array $categoriesGames array of the current new categories relationships, if a relationship is not found here, it means that was deleted.
* @param Atlas $atlas the atlas instance.
*/
public function updateCategoriesGames(?Array $categoriesGames, Atlas $atlas): void
{
if ($categoriesGames == null) return;
if (!$this->categories_games) $this->categories_games = $atlas->newRecordSet(CategoriesGame::class);

$this->categories_games->setDelete();
Expand Down
92 changes: 77 additions & 15 deletions void-eye-games-api/src/classes/Game/GameRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ class GameRecord extends Record
{
use GameFields;

public function addMedia(array $mediaArray, Atlas $atlas)
/**
* Adds a media relationship to this GameRecord.
* @param Array $mediaArray a list of properties from Media objects.
* @param Atlas $atlas the atlas instance.
*/
public function addMedia(Array $mediaArray, Atlas $atlas): void
{
if (!$this->medias) $this->medias = $atlas->newRecordSet(Media::class);

Expand All @@ -43,7 +48,13 @@ public function addMedia(array $mediaArray, Atlas $atlas)
$this->uploadMedia($src, $mediaRecord, $atlas);
}

private function uploadMedia($base64_string, MediaRecord $media)
/**
* Upload a media to the assets/images folder.
* @param mixed $base64_string the fileBytes
* @param MediaRecord $media the media record object.
* @uses AssetsManager
*/
private function uploadMedia($base64_string, MediaRecord $media): void
{
$data = explode(',', $base64_string);
$filename = $this->id . '-' . $media->id;
Expand All @@ -53,13 +64,22 @@ private function uploadMedia($base64_string, MediaRecord $media)
AssetsManager::getInstance()->writeAssets($path, $mediaFilename, base64_decode($data[1]));
}

/**
* Returns the mediaType file extension.
* @param mixed $mediaType the media type, example: "images/png"
*/
private function getExtension($mediaType)
{
preg_match('/.*(?:image|video)\/(?<extension>[^;]+).*/', $mediaType, $matches);
return $matches['extension'];
}

public function addCategoriesGames(array $categoriesGames, Atlas $atlas)
/**
* Adds a category relationship to this GameRecord.
* @param Array $categoriesGames a list of properties from CategoriesGames objects.
* @param Atlas $atlas the atlas instance.
*/
public function addCategoriesGames(Array $categoriesGames, Atlas $atlas): void
{
if (!$this->categories_games) $this->categories_games = $atlas->newRecordSet(CategoriesGame::class);
$categoriesGames['gamesId'] = $this->id;
Expand All @@ -68,7 +88,12 @@ public function addCategoriesGames(array $categoriesGames, Atlas $atlas)
$this->categories_games->appendNew($categoriesGames);
}

public function addPlataformsGames(array $gamePlataform, Atlas $atlas)
/**
* Adds a plataform relationship to this GameRecord.
* @param Array $gamePlataform a list of properties from PlataformsGames objects.
* @param Atlas $atlas the atlas instance.
*/
public function addPlataformsGames(Array $gamePlataform, Atlas $atlas): void
{
if (!$this->plataforms_games) $this->plataforms_games = $atlas->newRecordSet(PlataformsGame::class);
$gamePlataform['gamesId'] = $this->id;
Expand All @@ -77,31 +102,52 @@ public function addPlataformsGames(array $gamePlataform, Atlas $atlas)
$this->plataforms_games->appendNew($gamePlataform);
}

public function update(array $updatedGame, Atlas $atlas): void
/**
* Updates a game with other Game object as array representation.
* @param Array $updatedGame a list of properties from Game objects.
* @param Atlas $atlas the atlas instance.
* @throws AppException if already exists a game with that name
*/
public function update(Array $updatedGame, Atlas $atlas): void
{
$this->updateName($updatedGame['name'] ?? null, $atlas);
$this->updateDescripcion($updatedGame['descripcion'] ?? null, $atlas);
$this->updateMedias($updatedGame['medias'] ?? null, $atlas);
$this->updateCategoriesGames($updatedGame['categories_games'] ?? null, $atlas);
}

public function updateName(?string $name, Atlas $atlas): void
/**
* Updates the game name.
* @param ?String $name the new name.
* @param Atlas $atlas the atlas instance.
* @throws AppException if already exists a game with that name
*/
public function updateName(?String $name, Atlas $atlas): void
{
if (!$name || empty($name)) return;
$searchedGame = $atlas->select(Game::class, ['name' => $name])->where('id !=', $this->id)->fetchRecord();
if ($searchedGame) throw new AppException('There is already a game with this name.');
$this->name = $name;
}

public function updateDescripcion(?string $descripcion): void
/**
* Updates the game description.
* @param ?String $descripcion the new description.
*/
public function updateDescripcion(?String $descripcion): void
{
if (!$descripcion) return;
$this->descripcion = $descripcion;
}

public function updateMedias(?array $medias, Atlas $atlas)
/**
* Updates the medias relationships.
* @param ?Array $medias array of the current new medias relationships, if a relationship is not found here, it means that was deleted.
* @param Atlas $atlas the atlas instance.
*/
public function updateMedias(?Array $medias, Atlas $atlas): void
{
if (!$medias) return;
if ($medias == null) return;
if (!$this->medias) $this->medias = $atlas->newRecordSet(Media::class);

$this->medias->setDelete();
Expand All @@ -116,9 +162,14 @@ public function updateMedias(?array $medias, Atlas $atlas)
}
}

public function updateCategoriesGames(?array $updatedCategoriesGames, Atlas $atlas)
/**
* Updates the categories relationships.
* @param ?Array $updatedCategoriesGames array of the current new categories relationships, if a relationship is not found here, it means that was deleted.
* @param Atlas $atlas the atlas instance.
*/
public function updateCategoriesGames(?Array $updatedCategoriesGames, Atlas $atlas): void
{
if (!$updatedCategoriesGames) return;
if ($updatedCategoriesGames == null) return;
if (!$this->categories_games) $this->categories_games = $atlas->newRecordSet(CategoriesGame::class);

$this->categories_games->setDelete();
Expand All @@ -129,9 +180,14 @@ public function updateCategoriesGames(?array $updatedCategoriesGames, Atlas $atl
}
}

public function updatePlataformsGames(array $updatedPlataformGames, Atlas $atlas)
/**
* Updates the plataforms relationships.
* @param ?Array $updatedPlataformGames array of the current new plataforms relationships, if a relationship is not found here, it means that was deleted.
* @param Atlas $atlas the atlas instance.
*/
public function updatePlataformsGames(Array $updatedPlataformGames, Atlas $atlas): void
{
if (!$updatedPlataformGames) return;
if ($updatedPlataformGames == null) return;
if (!$this->plataforms_games) $this->plataforms_games = $atlas->newRecordSet(PlataformsGame::class);

$this->plataforms_games->setDelete();
Expand All @@ -146,14 +202,20 @@ public function updatePlataformsGames(array $updatedPlataformGames, Atlas $atlas
}
}

public function disable()
/**
* Disbled the game in all plataforms relationships, its the same as delete.
*/
public function disable(): void
{
foreach ($this->plataforms_games as $value) {
$value->isEnabled = false;
}
}

public function enable()
/**
* Enable the game in all plataforms relationships.
*/
public function enable(): void
{
foreach ($this->plataforms_games as $value) {
$value->isEnabled = true;
Expand Down
16 changes: 14 additions & 2 deletions void-eye-games-api/src/classes/Media/MediaRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,30 @@ class MediaRecord extends Record
{
use MediaFields;

/**
* Updates a media with other Media object as array representation.
* @param Array $updatedMedia a list of properties from Media objects.
*/
public function update(Array $updatedMedia)
{
$this->updateName($updatedMedia['name'] ?? null);
$this->updateName($updatedMedia['mediaType'] ?? null);
}

public function updateName(?string $name): void {
/**
* Updates a media name.
* @param ?String $name the new media name.
*/
public function updateName(?String $name): void {
if (!$name || empty($name)) return;
$this->name = $name;
}

public function updateMediaTypes(?string $mediaType): void {
/**
* Updates a media type.
* @param ?String $mediaType the new media type.
*/
public function updateMediaTypes(?String $mediaType): void {
if (!$mediaType || empty($mediaType)) return;
$this->mediaType = $mediaType;
}
Expand Down
38 changes: 33 additions & 5 deletions void-eye-games-api/src/classes/Plataform/PlataformRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ class PlataformRecord extends Record
{
use PlataformFields;

public function addPlataformGame(Array $plataformGame, Atlas $atlas): void {
/**
* Adds a plataform relationship to this PlataformRecord.
* @param Array $plataformGame a list of properties from PlataformsGames objects.
* @param Atlas $atlas the atlas instance.
*/
public function addPlataformGame(Array $plataformGame, Atlas $atlas): void
{
if (!$this->plataforms_games) $this->plataforms_games = $atlas->newRecordSet(PlataformsGame::class);

$plataformGame['plataformsId'] = $this->id;
Expand All @@ -36,29 +42,51 @@ public function addPlataformGame(Array $plataformGame, Atlas $atlas): void {
$this->plataforms_games->appendNew($plataformGame);
}

/**
* Updates a plataform with other Plataform object as array representation.
* @param Array $updatedPlataform a list of properties from Plataform objects.
* @param Atlas $atlas the atlas instance.
* @throws AppException if already exists a plataform with that name
*/
public function update(Array $updatedPlataform, Atlas $atlas): void
{
$this->updateName($updatedPlataform['name'] ?? null, $atlas);
$this->updateUrl($updatedPlataform['url'] ?? null, $atlas);
$this->updatePlataformsGames($updatedPlataform['plataforms_games'] ?? null, $atlas);
}

public function updateName(?string $name, Atlas $atlas): void
/**
* Updates the plataform name.
* @param ?String $name the new name.
* @param Atlas $atlas the atlas instance.
* @throws AppException if already exists a plataform with that name
*/
public function updateName(?String $name, Atlas $atlas): void
{
if (!$name || empty($name)) return;
$searchedPlataform = $atlas->select(Plataform::class, ['name' => $name])->where('id !=', $this->id)->fetchRecord();
if ($searchedPlataform) throw new AppException('There is already a plataform with this name.');
$this->name = $name;
}

public function updateUrl(?string $url): void
/**
* Updates the plataform url.
* @param ?String $url the new url.
*/
public function updateUrl(?String $url): void
{
if (!$url) return;
$this->url = $url;
}

public function updatePlataformsGames(?Array $plataformGames, Atlas $atlas): void {
if (!$plataformGames) return;
/**
* Updates the plataforms relationships.
* @param ?Array $plataformGames array of the current new plataforms relationships, if a relationship is not found here, it means that was deleted.
* @param Atlas $atlas the atlas instance.
*/
public function updatePlataformsGames(?Array $plataformGames, Atlas $atlas): void
{
if ($plataformGames == null) return;
if (!$this->plataforms_games) $this->plataforms_games = $atlas->newRecordSet(PlataformsGame::class);

$this->plataforms_games->setDelete();
Expand Down
Loading

0 comments on commit 3bf8f4f

Please sign in to comment.