Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task #207301 Fix: In Certificate => In Issued Certificate => Add two filters course and event #158

Open
wants to merge 1 commit into
base: dev-joomla4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* @package TJCertificate
* @subpackage com_tjcertificate
*
* @author Techjoomla <[email protected]>
* @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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* @package TJCertificate
* @subpackage com_tjcertificate
*
* @author Techjoomla <[email protected]>
* @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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@
clientByUser="0"
onchange="this.form.submit();" />

<field
name="courses"
type="courses"
label="COM_TJCERTIFICATE_CERTIFICATE_FILTER_SELECT_COURSE"
description="COM_TJCERTIFICATE_CERTIFICATE_FILTER_SELECT_COURSE_DESC"
onchange="this.form.submit();"
showon="client:com_tjlms.course"
>
</field>

<field
name="events"
type="eventslist"
label="COM_TJCERTIFICATE_CERTIFICATE_FILTER_TITLE_LABEL"
description="COM_TJCERTIFICATE_CERTIFICATE_FILTER_TITLE_DESC"
onchange="this.form.submit();"
showon="client:com_jticketing.event"
>
</field>

<!-- <field
name="user_id"
type="sql"
Expand Down