diff --git a/src/components/com_tjcertificate/administrator/libraries/certificate.php b/src/components/com_tjcertificate/administrator/libraries/certificate.php index 4b4bd579..5a162233 100644 --- a/src/components/com_tjcertificate/administrator/libraries/certificate.php +++ b/src/components/com_tjcertificate/administrator/libraries/certificate.php @@ -41,6 +41,10 @@ class TjCertificateCertificate extends CMSObject private $client_id = 0; + private $client_issued_to = 0; + + private $client_issued_to_name = ""; + private $user_id = 0; public $state = 1; @@ -148,6 +152,58 @@ public function getClientId() return $this->client_id; } + /** + * Set client issued to + * + * @param integer $value Value to set client issued to. + * + * @return void. + * + * @since __DEPLOY_VERSION__ + */ + public function setClientIssuedTo($value = 0) + { + $this->client_issued_to = $value; + } + + /** + * Get client issued to + * + * @return string Client issued to. + * + * @since __DEPLOY_VERSION__ + */ + public function getClientIssuedTo() + { + return $this->client_issued_to; + } + + /** + * Set client issued to name + * + * @param string $value Value to set client issued to name. + * + * @return void. + * + * @since __DEPLOY_VERSION__ + */ + public function setClientIssuedToName($value = "") + { + $this->client_issued_to_name = $value; + } + + /** + * Get client issued to name + * + * @return string Client issued to name. + * + * @since __DEPLOY_VERSION__ + */ + public function getClientIssuedToName() + { + return $this->client_issued_to_name; + } + /** * Set User Id * @@ -432,21 +488,28 @@ public function bind(&$array) /** * Method to get issued certificate list * - * @param string $client Client e.g. com_tjlms.course + * @param string $client Client e.g. com_tjlms.course * - * @param integer $clientId Specific client id + * @param integer $clientId Specific client id * - * @param integer $userId User Id + * @param integer $userId User Id * - * @param boolean $expired Get expired certificates + * @param boolean $expired Get expired certificates + * + * @param boolean $clientIssuedTo Client issued to * * @return boolean|array Issued certificate array * * @since 1.0 */ - public static function getIssued($client, $clientId, $userId, $expired = false) + public static function getIssued($client, $clientId, $userId = 0, $expired = false, $clientIssuedTo = 0) { - if (empty($client) || empty($clientId) || empty($userId)) + if (empty($client) || empty($clientId)) + { + return false; + } + + if (empty($userId) && empty($clientIssuedTo)) { return false; } @@ -455,7 +518,16 @@ public static function getIssued($client, $clientId, $userId, $expired = false) $model->setState('filter.client', $client); $model->setState('filter.client_id', $clientId); - $model->setState('filter.user_id', $userId); + + if (!empty($userId)) + { + $model->setState('filter.user_id', $userId); + } + + if ($clientIssuedTo) + { + $model->setState('filter.client_issued_to', $clientIssuedTo); + } if ($expired) { diff --git a/src/components/com_tjcertificate/administrator/models/certificates.php b/src/components/com_tjcertificate/administrator/models/certificates.php index 96a099d1..6039421a 100644 --- a/src/components/com_tjcertificate/administrator/models/certificates.php +++ b/src/components/com_tjcertificate/administrator/models/certificates.php @@ -137,6 +137,14 @@ protected function getListQuery() $query->where($db->quoteName('ci.user_id') . ' = ' . (int) $userId); } + // Filter by client issued to + $clientIssuedTo = $this->getState('filter.client_issued_to'); + + if (!empty($clientIssuedTo)) + { + $query->where($db->quoteName('ci.client_issued_to') . ' = ' . (int) $clientIssuedTo); + } + // Filter by search in title. $search = $this->getState('filter.search'); diff --git a/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql b/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql index 28345089..d5b51fee 100644 --- a/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql +++ b/src/components/com_tjcertificate/administrator/sql/install.mysql.utf8.sql @@ -26,6 +26,8 @@ CREATE TABLE IF NOT EXISTS `#__tj_certificate_issue` ( `generated_body` text NOT NULL, `client` varchar(100) NOT NULL, `client_id` int(11) NOT NULL, + `client_issued_to` int(11) NOT NULL, + `client_issued_to_name` varchar(400) COLLATE utf8mb4_unicode_ci NOT NULL, `user_id` int(11) NOT NULL, `comment` text NULL, `state` tinyint(3) NOT NULL, diff --git a/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.1.sql b/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.1.sql new file mode 100644 index 00000000..6e41e6d6 --- /dev/null +++ b/src/components/com_tjcertificate/administrator/sql/updates/mysql/1.0.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE `#__tj_certificate_issue` ADD `client_issued_to` int(11) NOT NULL AFTER `user_id`; +ALTER TABLE `#__tj_certificate_issue` ADD `client_issued_to_name` varchar(400) COLLATE 'utf8mb4_unicode_ci' NOT NULL AFTER `client_issued_to`; diff --git a/src/components/com_tjcertificate/tjcertificate.xml b/src/components/com_tjcertificate/tjcertificate.xml index f2d48836..3bb56f17 100644 --- a/src/components/com_tjcertificate/tjcertificate.xml +++ b/src/components/com_tjcertificate/tjcertificate.xml @@ -8,7 +8,7 @@ extensions@techjoomla.com http://techjoomla.com - 1.0.0 + 1.0.1