Skip to content

Commit

Permalink
Completed PHPDocs on admin core models
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCartpenter committed Jan 1, 2025
1 parent f57a367 commit d0cfe40
Show file tree
Hide file tree
Showing 60 changed files with 1,113 additions and 868 deletions.
28 changes: 16 additions & 12 deletions upload/admin/model/catalog/attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
/**
* Class Attribute
*
* @example $attribute_model = $this->model_catalog_attribute;
*
* Can be called from $this->load->model('catalog/attribute');
*
* @package Admin\Model\Catalog
*/
class ModelCatalogAttribute extends Model {
Expand All @@ -10,9 +14,9 @@ class ModelCatalogAttribute extends Model {
*
* Create a new attribute record in the database.
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data array of data
*
* @return int Returns the primary key of the new attribute record
* @return int returns the primary key of the new attribute record
*/
public function addAttribute(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute` SET `attribute_group_id` = '" . (int)$data['attribute_group_id'] . "', `sort_order` = '" . (int)$data['sort_order'] . "'");
Expand All @@ -31,8 +35,8 @@ public function addAttribute(array $data): int {
*
* Edit attribute record in the database.
*
* @param int $attribute_id Primary key of the attribute record to edit
* @param array<string, mixed> $data Array of data
* @param int $attribute_id primary key of the attribute record to edit
* @param array<string, mixed> $data array of data
*
* @return void
*/
Expand All @@ -51,7 +55,7 @@ public function editAttribute(int $attribute_id, array $data): void {
*
* Delete attribute record in the database.
*
* @param int $attribute_id Primary key of the attribute record to be deleted
* @param int $attribute_id primary key of the attribute record to be deleted
*
* @return void
*/
Expand All @@ -65,9 +69,9 @@ public function deleteAttribute(int $attribute_id): void {
*
* Get the record of the attribute record in the database.
*
* @param int $attribute_id Primary key of the attribute record to be fetched
* @param int $attribute_id primary key of the attribute record to be fetched
*
* @return array<string, mixed>
* @return array<string, mixed> attribute record that has attribute ID
*/
public function getAttribute(int $attribute_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute` `a` LEFT JOIN `" . DB_PREFIX . "attribute_description` `ad` ON (`a`.`attribute_id` = `ad`.`attribute_id`) WHERE `a`.`attribute_id` = '" . (int)$attribute_id . "' AND `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
Expand All @@ -82,7 +86,7 @@ public function getAttribute(int $attribute_id): array {
*
* @param array<string, mixed> $data array of filters
*
* @return array<int, array<string, mixed>>
* @return array<int, array<string, mixed>> attribute records
*/
public function getAttributes(array $data = []): array {
$sql = "SELECT *, (SELECT `agd`.`name` FROM `" . DB_PREFIX . "attribute_group_description` `agd` WHERE `agd`.`attribute_group_id` = `a`.`attribute_group_id` AND `agd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "') AS `attribute_group` FROM `" . DB_PREFIX . "attribute` `a` LEFT JOIN `" . DB_PREFIX . "attribute_description` `ad` ON (`a`.`attribute_id` = `ad`.`attribute_id`) WHERE `ad`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
Expand Down Expand Up @@ -135,9 +139,9 @@ public function getAttributes(array $data = []): array {
*
* Get the record of the attribute record in the database.
*
* @param int $attribute_id Primary key of the attribute record to be fetched
* @param int $attribute_id primary key of the attribute record to be fetched
*
* @return array<int, array<string, string>> Returns the descriptions sorted by language_id
* @return array<int, array<string, string>> rdescription records that have attribute ID
*/
public function getDescriptions(int $attribute_id): array {
$attribute_data = [];
Expand All @@ -156,7 +160,7 @@ public function getDescriptions(int $attribute_id): array {
*
* Get the total number of attribute records in the database.
*
* @return int Returns the total number of attribute records
* @return int total number of attribute records
*/
public function getTotalAttributes(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute`");
Expand All @@ -171,7 +175,7 @@ public function getTotalAttributes(): int {
*
* @param int $attribute_group_id Foreign key of the attribute record to be fetched
*
* @return int Returns the total number of attribute records that have attribute group ID
* @return int total number of attribute records that have attribute group ID
*/
public function getTotalAttributesByAttributeGroupId(int $attribute_group_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
Expand Down
28 changes: 16 additions & 12 deletions upload/admin/model/catalog/attribute_group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
/**
* Class Attribute Group
*
* @example $attribute_group_model = $this->model_catalog_attribute_group;
*
* Can be called from $this->load->model('catalog/attribute_group');
*
* @package Admin\Model\Catalog
*/
class ModelCatalogAttributeGroup extends Model {
/**
* Add Attribute Group
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data array of data
*
* @return int
* @return int returns the primary key of the new attribute group record
*/
public function addAttributeGroup(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_group` SET `sort_order` = '" . (int)$data['sort_order'] . "'");
Expand All @@ -27,8 +31,8 @@ public function addAttributeGroup(array $data): int {
/**
* Edit Attribute Group
*
* @param int $attribute_group_id
* @param array<string, mixed> $data
* @param int $attribute_group_id primary key of the attribute group record
* @param array<string, mixed> $data array of data
*
* @return void
*/
Expand All @@ -45,7 +49,7 @@ public function editAttributeGroup(int $attribute_group_id, array $data): void {
/**
* Delete Attribute Group
*
* @param int $attribute_group_id
* @param int $attribute_group_id primary key of the attribute group record
*
* @return void
*/
Expand All @@ -57,9 +61,9 @@ public function deleteAttributeGroup(int $attribute_group_id): void {
/**
* Get Attribute Group
*
* @param int $attribute_group_id
* @param int $attribute_group_id primary key of the attribute group record
*
* @return array<string, mixed>
* @return array<string, mixed> attribute group record that has attribute group ID
*/
public function getAttributeGroup(int $attribute_group_id): array {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "attribute_group` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
Expand All @@ -70,9 +74,9 @@ public function getAttributeGroup(int $attribute_group_id): array {
/**
* Get Attribute Groups
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data array of filters
*
* @return array<int, array<string, mixed>>
* @return array<int, array<string, mixed>> attribute group records
*/
public function getAttributeGroups(array $data = []): array {
$sql = "SELECT * FROM `" . DB_PREFIX . "attribute_group` `ag` LEFT JOIN `" . DB_PREFIX . "attribute_group_description` `agd` ON (`ag`.`attribute_group_id` = `agd`.`attribute_group_id`) WHERE `agd`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
Expand Down Expand Up @@ -114,9 +118,9 @@ public function getAttributeGroups(array $data = []): array {
/**
* Get Descriptions
*
* @param int $attribute_group_id
* @param int $attribute_group_id primary key of the attribute group record
*
* @return array<int, array<string, string>>
* @return array<int, array<string, string>> description records that have attribute group ID
*/
public function getDescriptions(int $attribute_group_id): array {
$attribute_group_data = [];
Expand All @@ -133,7 +137,7 @@ public function getDescriptions(int $attribute_group_id): array {
/**
* Get Total Attribute Groups
*
* @return int
* @return int total number of attribute group records
*/
public function getTotalAttributeGroups(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute_group`");
Expand Down
54 changes: 29 additions & 25 deletions upload/admin/model/catalog/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
/**
* Class Category
*
* @example $category_model = $this->model_catalog_category;
*
* Can be called from $this->load->model('catalog/category');
*
* @package Admin\Model\Catalog
*/
class ModelCatalogCategory extends Model {
/**
* Add Category
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data array of data
*
* @return int
* @return int returns the primary key of the new category record
*/
public function addCategory(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "category` SET `parent_id` = '" . (int)$data['parent_id'] . "', `top` = '" . (isset($data['top']) ? (int)$data['top'] : 0) . "', `column` = '" . (int)$data['column'] . "', `sort_order` = '" . (int)$data['sort_order'] . "', `status` = '" . (int)$data['status'] . "', `date_modified` = NOW(), `date_added` = NOW()");
Expand Down Expand Up @@ -75,8 +79,8 @@ public function addCategory(array $data): int {
/**
* Edit Category
*
* @param int $category_id
* @param array<string, mixed> $data
* @param int $category_id primary key of the category record
* @param array<string, mixed> $data array of data
*
* @return void
*/
Expand Down Expand Up @@ -187,7 +191,7 @@ public function editCategory(int $category_id, array $data): void {
/**
* Delete Category
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return void
*/
Expand Down Expand Up @@ -215,7 +219,7 @@ public function deleteCategory(int $category_id): void {
/**
* Repair Categories
*
* @param int $parent_id
* @param int $parent_id primary key of the parent category record
*
* @return void
*/
Expand Down Expand Up @@ -246,9 +250,9 @@ public function repairCategories(int $parent_id = 0): void {
/**
* Get Category
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return array<string, mixed>
* @return array<string, mixed> category record that has category ID
*/
public function getCategory(int $category_id): array {
$query = $this->db->query("SELECT DISTINCT *, (SELECT GROUP_CONCAT(`cd1`.`name` ORDER BY `level` SEPARATOR ' > ') FROM `" . DB_PREFIX . "category_path` `cp` LEFT JOIN `" . DB_PREFIX . "category_description` `cd1` ON (`cp`.`path_id` = `cd1`.`category_id` AND `cp`.`category_id` != `cp`.`path_id`) WHERE `cp`.`category_id` = `c`.`category_id` AND `cd1`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' GROUP BY `cp`.`category_id`) AS `path` FROM `" . DB_PREFIX . "category` `c` LEFT JOIN `" . DB_PREFIX . "category_description` `cd2` ON (`c`.`category_id` = `cd2`.`category_id`) WHERE `c`.`category_id` = '" . (int)$category_id . "' AND `cd2`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'");
Expand All @@ -259,9 +263,9 @@ public function getCategory(int $category_id): array {
/**
* Get Categories
*
* @param array<string, mixed> $data
* @param array<string, mixed> $data array of filters
*
* @return array<int, array<string, mixed>>
* @return array<int, array<string, mixed>> category records
*/
public function getCategories(array $data = []): array {
$sql = "SELECT `cp`.`category_id` AS `category_id`, GROUP_CONCAT(`cd1`.`name` ORDER BY `cp`.`level` SEPARATOR ' > ') AS `name`, `c1`.`parent_id`, `c1`.`sort_order` FROM `" . DB_PREFIX . "category_path` `cp` LEFT JOIN `" . DB_PREFIX . "category` `c1` ON (`cp`.`category_id` = `c1`.`category_id`) LEFT JOIN `" . DB_PREFIX . "category` `c2` ON (`cp`.`path_id` = `c2`.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_description` `cd1` ON (`cp`.`path_id` = `cd1`.`category_id`) LEFT JOIN `" . DB_PREFIX . "category_description` `cd2` ON (`cp`.`category_id` = `cd2`.`category_id`) WHERE `cd1`.`language_id` = '" . (int)$this->config->get('config_language_id') . "' AND `cd2`.`language_id` = '" . (int)$this->config->get('config_language_id') . "'";
Expand Down Expand Up @@ -309,9 +313,9 @@ public function getCategories(array $data = []): array {
/**
* Get Descriptions
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return array<int, array<string, string>>
* @return array<int, array<string, string>> category records that have category ID
*/
public function getDescriptions(int $category_id): array {
$category_description_data = [];
Expand All @@ -334,9 +338,9 @@ public function getDescriptions(int $category_id): array {
/**
* Get Path
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return array<int, array<string, mixed>>
* @return array<int, array<string, mixed>> category records that have category ID
*/
public function getPath(int $category_id): array {
$query = $this->db->query("SELECT `category_id`, `path_id`, `level` FROM `" . DB_PREFIX . "category_path` WHERE `category_id` = '" . (int)$category_id . "'");
Expand All @@ -347,9 +351,9 @@ public function getPath(int $category_id): array {
/**
* Get Filters
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return array<int, int>
* @return array<int, int> category records that have category ID
*/
public function getFilters(int $category_id): array {
$category_filter_data = [];
Expand All @@ -366,9 +370,9 @@ public function getFilters(int $category_id): array {
/**
* Get Category Stores
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return array<int, int>
* @return array<int, int> store records that have category ID
*/
public function getCategoryStores(int $category_id): array {
$category_store_data = [];
Expand All @@ -385,9 +389,9 @@ public function getCategoryStores(int $category_id): array {
/**
* Get Category Seo Urls
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return array<int, array<string, string>>
* @return array<int, array<string, string>> SEO URL records that have category ID
*/
public function getCategorySeoUrls(int $category_id): array {
$category_seo_url_data = [];
Expand All @@ -404,9 +408,9 @@ public function getCategorySeoUrls(int $category_id): array {
/**
* Get Category Layouts
*
* @param int $category_id
* @param int $category_id primary key of the category record
*
* @return array<int, array<string, string>>
* @return array<int, int> layout records that have category ID
*/
public function getCategoryLayouts(int $category_id): array {
$category_layout_data = [];
Expand All @@ -423,7 +427,7 @@ public function getCategoryLayouts(int $category_id): array {
/**
* Get Total Categories
*
* @return int
* @return int total number of category records
*/
public function getTotalCategories(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "category`");
Expand All @@ -434,9 +438,9 @@ public function getTotalCategories(): int {
/**
* Get Total Categories By LayoutId
*
* @param int $layout_id
* @param int $layout_id primary key of the layout record
*
* @return int
* @return int total number of layout records that have layout ID
*/
public function getTotalCategoriesByLayoutId(int $layout_id): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "category_to_layout` WHERE `layout_id` = '" . (int)$layout_id . "'");
Expand Down
Loading

0 comments on commit d0cfe40

Please sign in to comment.