diff --git a/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini b/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini index 85784c2f..e3551e5d 100644 --- a/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini +++ b/src/components/com_tjcertificate/administrator/languages/en-GB/en-GB.com_tjcertificate.ini @@ -405,3 +405,10 @@ COM_TJCERTIFICATE_FORM_VALIDATATION_FAILED="Form Validation Failed" COM_TJCERTIFICATE_PAGE_ADD_TRAINING_RECORDS="Training Records" COM_TJCERTIFICATE_TOTAL_RECORDS_ADDED="Records added for %s user(s)" COM_TJCERTIFICATE_RECORDS_ADDED_TO_QUEUE_SUCCESSFULLY="Records added in queue" +COM_TJCERTIFICATE_CERTIFICATE_EVENTS_FIELD="- Select Event -" +COM_TJCERTIFICATE_CERTIFICATE_COURSES_FIELD="- Select Course -" +COM_TJCERTIFICATE_CERTIFICATE_FILTER_SELECT_COURSE="Course" +COM_TJCERTIFICATE_CERTIFICATE_FILTER_SELECT_COURSE_DESC="Course" +COM_TJCERTIFICATE_CERTIFICATE_FILTER_TITLE_LABEL="Event" +COM_TJCERTIFICATE_CERTIFICATE_FILTER_TITLE_DESC="Event" + diff --git a/src/components/com_tjcertificate/administrator/models/certificates.php b/src/components/com_tjcertificate/administrator/models/certificates.php index 8d978bf1..0b6ae4c5 100644 --- a/src/components/com_tjcertificate/administrator/models/certificates.php +++ b/src/components/com_tjcertificate/administrator/models/certificates.php @@ -74,6 +74,12 @@ protected function populateState($ordering = 'ci.id', $direction = 'desc') $client = $app->getUserStateFromRequest($this->context . '.filter.client', 'client'); $this->setState('filter.client', $client); + $courses = $app->getUserStateFromRequest($this->context . '.filter.courses', 'courses'); + $this->setState('filter.courses', $courses); + + $events = $app->getUserStateFromRequest($this->context . '.filter.events', 'events'); + $this->setState('filter.events', $events); + parent::populateState($ordering, $direction); } @@ -174,10 +180,16 @@ protected function getListQuery() // Filter by client id $clientId = $this->getState('filter.client_id'); + $courses = $this->getState('filter.courses'); + $events = $this->getState('filter.events'); + + $courseORevent = !empty($courses) ? $courses : $events; + + $clientIdVal = !empty($courseORevent) ? $courseORevent : $clientId; - if (!empty($clientId)) + if (!empty($clientIdVal)) { - $query->where($db->quoteName('ci.client_id') . ' = ' . $db->quote($clientId)); + $query->where($db->quoteName('ci.client_id') . ' = ' . $db->quote($clientIdVal)); } // Filter by user id diff --git a/src/components/com_tjcertificate/administrator/models/fields/courses.php b/src/components/com_tjcertificate/administrator/models/fields/courses.php new file mode 100644 index 00000000..5cbe75df --- /dev/null +++ b/src/components/com_tjcertificate/administrator/models/fields/courses.php @@ -0,0 +1,77 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +// No direct access. +defined('_JEXEC') or die(); +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Form\FormHelper; +use Joomla\CMS\HTML\HTMLHelper; + +FormHelper::loadFieldClass('list'); + +/** + * Supports an HTML select list of courses + * + * @since __DEPLOY_VERSION__ + */ +class JFormFieldCourses extends JFormFieldList +{ + /** + * The form field type. + * + * @var string + * @since __DEPLOY_VERSION__ + */ + protected $type = 'courses'; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + * + * @since __DEPLOY_VERSION__ + */ + protected function getOptions() + { + $db = Factory::getDbo(); + $user = Factory::getUser(); + $query = $db->getQuery(true); + + // Select the required fields from the table. + $query->select('c.id, c.title'); + $query->from($db->qn('#__tjlms_courses', 'c')); + $query->join('LEFT', $db->qn('#__categories', 'cat') . ' ON (' . $db->qn('cat.id') . ' = ' . $db->qn('c.catid') . ')'); + $query->where($db->qn('c.state') . '= 1'); + $query->where($db->qn('cat.published') . '= 1'); + + $nullDate = $db->quote($db->getNullDate()); + $nowDate = $db->quote(Factory::getDate()->toSql()); + $query->where('(c.start_date = ' . $nullDate . ' OR c.start_date <= ' . $nowDate . ')'); + + $query->order($db->escape('c.title ASC')); + + $db->setQuery($query); + + // Get all courses. + $allcourses = $db->loadObjectList(); + + $options = array(); + + $options[] = HTMLHelper::_('select.option', '', Text::_('COM_TJCERTIFICATE_CERTIFICATE_COURSES_FIELD')); + + foreach ($allcourses as $c) + { + $options[] = HTMLHelper::_('select.option', $c->id, $c->title); + } + + return $options; + } +} diff --git a/src/components/com_tjcertificate/administrator/models/fields/eventslist.php b/src/components/com_tjcertificate/administrator/models/fields/eventslist.php new file mode 100644 index 00000000..cf0c9c5c --- /dev/null +++ b/src/components/com_tjcertificate/administrator/models/fields/eventslist.php @@ -0,0 +1,67 @@ + + * @copyright Copyright (C) 2009 - 2019 Techjoomla. All rights reserved. + * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL + */ + +// No direct access. +defined('_JEXEC') or die(); + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Form\FormHelper; +use Joomla\CMS\HTML\HTMLHelper; + +jimport('joomla.form.helper'); +FormHelper::loadFieldClass('list'); + +/** + * Supports an HTML select list of events + * + * @since __DEPLOY_VERSION__ + */ +class JFormFieldEventsList extends JFormFieldList +{ + /** + * The form field type. + * + * @var string + * @since __DEPLOY_VERSION__ + */ + protected $type = 'eventslist'; + + /** + * Method to get a list of options for a list input. + * + * @return array An array of JHtml options. + * + * @since __DEPLOY_VERSION__ + */ + protected function getOptions() + { + $options = array(); + $eventsModel = JT::model('events', array('ignore_request' => true)); + + // Get all events options + $eventList = $eventsModel->getItems(); + + $options[] = HTMLHelper::_('select.option', '', Text::_('COM_TJCERTIFICATE_CERTIFICATE_EVENTS_FIELD')); + + if (!empty($eventList)) + { + foreach ($eventList as $key => $event) + { + $eventId = (int) $event->id; + $eventName = htmlspecialchars($event->title); + + $options[] = HTMLHelper::_('select.option', $eventId, $eventName); + } + } + + return $options; + } +} diff --git a/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml b/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml index 25258277..89fd5b51 100644 --- a/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml +++ b/src/components/com_tjcertificate/administrator/models/forms/filter_certificates.xml @@ -30,6 +30,26 @@ clientByUser="0" onchange="this.form.submit();" /> + + + + + +