Skip to content

Commit

Permalink
More PHPDocs examples work in admin models
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCartpenter committed Jan 5, 2025
1 parent 2c4a672 commit 80d1218
Show file tree
Hide file tree
Showing 60 changed files with 2,351 additions and 182 deletions.
92 changes: 61 additions & 31 deletions upload/admin/model/catalog/attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
/**
* 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 {
/**
* Add Attribute
* Add Attribute
*
* Create a new attribute record in the database.
* Create a new attribute record in the database.
*
* @param array<string, mixed> $data array of data
*
* @return int returns the primary key of the new attribute record
*
* @example
*
* $attribute_id = $this->model_catalog_attribute->addAttribute($data);
*/
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,14 +33,18 @@ public function addAttribute(array $data): int {
}

/**
* Edit Attribute
* Edit Attribute
*
* Edit attribute record in the database.
* Edit attribute record in the database.
*
* @param int $attribute_id primary key of the attribute record to edit
* @param int $attribute_id primary key of the attribute record
* @param array<string, mixed> $data array of data
*
* @return void
*
* @example
*
* $this->model_catalog_attribute->editAttribute($attribute_id, $data);
*/
public function editAttribute(int $attribute_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "attribute` SET `attribute_group_id` = '" . (int)$data['attribute_group_id'] . "', `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `attribute_id` = '" . (int)$attribute_id . "'");
Expand All @@ -51,27 +57,35 @@ public function editAttribute(int $attribute_id, array $data): void {
}

/**
* Delete Attribute
* Delete Attribute
*
* Delete attribute record in the database.
* 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
*
* @return void
*
* @example
*
* $this->model_catalog_attribute->deleteAttribute($attribute_id);
*/
public function deleteAttribute(int $attribute_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute` WHERE `attribute_id` = '" . (int)$attribute_id . "'");
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_description` WHERE `attribute_id` = '" . (int)$attribute_id . "'");
}

/**
* Get Attribute
* Get Attribute
*
* Get the record of the attribute record in the database.
* 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
*
* @return array<string, mixed> attribute record that has attribute ID
*
* @example
*
* $attribute_info = $this->model_catalog_attribute->getAttribute($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 @@ -80,13 +94,17 @@ public function getAttribute(int $attribute_id): array {
}

/**
* Get Attributes
* Get Attributes
*
* Get the record of the attribute record in the database.
* Get the record of the attribute record in the database.
*
* @param array<string, mixed> $data array of filters
*
* @return array<int, array<string, mixed>> attribute records
*
* @example
*
* $results = $this->model_catalog_attribute->getAttributes();
*/
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,13 +153,17 @@ public function getAttributes(array $data = []): array {
}

/**
* Get Descriptions
* Get Descriptions
*
* Get the record of the attribute record in the database.
*
* Get the record of the attribute record in the database.
* @param int $attribute_id primary key of the attribute record
*
* @param int $attribute_id primary key of the attribute record to be fetched
* @return array<int, array<string, string>> description records that have attribute ID
*
* @return array<int, array<string, string>> rdescription records that have attribute ID
* @example
*
* $attribute_description = $this->model_catalog_attribute->getDescriptions($attribute_id);
*/
public function getDescriptions(int $attribute_id): array {
$attribute_data = [];
Expand All @@ -156,11 +178,15 @@ public function getDescriptions(int $attribute_id): array {
}

/**
* Get Total Attributes
*
* Get the total number of attribute records in the database.
*
* @return int total number of attribute records
* Get Total Attributes
*
* Get the total number of attribute records in the database.
*
* @return int
*
* @example
*
* $attribute_total = $this->model_catalog_attribute->getTotalAttributes();
*/
public function getTotalAttributes(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute`");
Expand All @@ -169,13 +195,17 @@ public function getTotalAttributes(): int {
}

/**
* Get Total Attributes By Attribute Group ID
*
* Get the total number of attribute records with group ID in the database.
*
* @param int $attribute_group_id Foreign key of the attribute record to be fetched
*
* @return int total number of attribute records that have attribute group ID
* Get Total Attributes By Attribute Group ID
*
* Get the total number of attribute records with group ID in the database.
*
* @param int $attribute_group_id
*
* @return int
*
* @example
*
* $attribute_total = $this->model_catalog_attribute->getTotalAttributesByAttributeGroupId($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
30 changes: 28 additions & 2 deletions upload/admin/model/catalog/attribute_group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
/**
* 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
Expand All @@ -15,6 +13,10 @@ class ModelCatalogAttributeGroup extends Model {
* @param array<string, mixed> $data array of data
*
* @return int returns the primary key of the new attribute group record
*
* @example
*
* $attribute_group_id = $this->model_catalog_attribute_group->addAttributeGroup($data);
*/
public function addAttributeGroup(array $data): int {
$this->db->query("INSERT INTO `" . DB_PREFIX . "attribute_group` SET `sort_order` = '" . (int)$data['sort_order'] . "'");
Expand All @@ -35,6 +37,10 @@ public function addAttributeGroup(array $data): int {
* @param array<string, mixed> $data array of data
*
* @return void
*
* @example
*
* $this->model_catalog_attribute_group->editAttributeGroup($attribute_group_id, $data);
*/
public function editAttributeGroup(int $attribute_group_id, array $data): void {
$this->db->query("UPDATE `" . DB_PREFIX . "attribute_group` SET `sort_order` = '" . (int)$data['sort_order'] . "' WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
Expand All @@ -52,6 +58,10 @@ public function editAttributeGroup(int $attribute_group_id, array $data): void {
* @param int $attribute_group_id primary key of the attribute group record
*
* @return void
*
* @example
*
* $this->model_catalog_attribute_group->deleteAttributeGroup($attribute_group_id);
*/
public function deleteAttributeGroup(int $attribute_group_id): void {
$this->db->query("DELETE FROM `" . DB_PREFIX . "attribute_group` WHERE `attribute_group_id` = '" . (int)$attribute_group_id . "'");
Expand All @@ -64,6 +74,10 @@ public function deleteAttributeGroup(int $attribute_group_id): void {
* @param int $attribute_group_id primary key of the attribute group record
*
* @return array<string, mixed> attribute group record that has attribute group ID
*
* @example
*
* $attribute_group_info = $this->model_catalog_attribute_group->getAttributeGroup($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 @@ -77,6 +91,10 @@ public function getAttributeGroup(int $attribute_group_id): array {
* @param array<string, mixed> $data array of filters
*
* @return array<int, array<string, mixed>> attribute group records
*
* @example
*
* $attribute_groups = $this->model_catalog_attribute_group->getAttributeGroups();
*/
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 @@ -121,6 +139,10 @@ public function getAttributeGroups(array $data = []): array {
* @param int $attribute_group_id primary key of the attribute group record
*
* @return array<int, array<string, string>> description records that have attribute group ID
*
* @example
*
* $attribute_group_description = $this->model_catalog_attribute_group->getDescriptions($attribute_group_id);
*/
public function getDescriptions(int $attribute_group_id): array {
$attribute_group_data = [];
Expand All @@ -138,6 +160,10 @@ public function getDescriptions(int $attribute_group_id): array {
* Get Total Attribute Groups
*
* @return int total number of attribute group records
*
* @example
*
* $attribute_group_total = $this->model_catalog_attribute_group->getTotalAttributeGroups();
*/
public function getTotalAttributeGroups(): int {
$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "attribute_group`");
Expand Down
Loading

0 comments on commit 80d1218

Please sign in to comment.