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 70b9ee5e..3cb8f7ea 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
@@ -276,3 +276,10 @@ COM_TJCERTIFICATE_CERTIFICATE_FILTER_CERTIFICATE_TYPE_SELECT="- Select Type -"
COM_TJCERTIFICATE_CLIENT_COM_TJLMS_COURSE="Course"
COM_TJCERTIFICATE_CLIENT_COM_JTICKETING_EVENT="Event"
COM_TJCERTIFICATE_CERTIFICATE_LIST_VIEW_TYPE="Type"
+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 78ce5435..b9af9aa2 100644
--- a/src/components/com_tjcertificate/administrator/models/certificates.php
+++ b/src/components/com_tjcertificate/administrator/models/certificates.php
@@ -66,6 +66,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);
}
@@ -123,10 +129,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 f5b6dcbd..cbd1323f 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();" />
+
+
+
+
+
+