From 20e53a721a730cb9e70c0619fdba2b2983fb091a Mon Sep 17 00:00:00 2001 From: rajnish_d Date: Sat, 4 Jan 2020 17:20:47 +0530 Subject: [PATCH 1/2] Task #155602 feat : Affiliate list view --- .../admin/controllers/affliates.php | 65 ++++++ src/com_tjvendors/admin/models/affliates.php | 189 ++++++++++++++++++ .../admin/views/affliates/index.html | 1 + .../admin/views/affliates/tmpl/default.php | 85 ++++++++ .../admin/views/affliates/tmpl/index.html | 1 + .../admin/views/affliates/view.html.php | 115 +++++++++++ 6 files changed, 456 insertions(+) create mode 100644 src/com_tjvendors/admin/controllers/affliates.php create mode 100644 src/com_tjvendors/admin/models/affliates.php create mode 100644 src/com_tjvendors/admin/views/affliates/index.html create mode 100644 src/com_tjvendors/admin/views/affliates/tmpl/default.php create mode 100644 src/com_tjvendors/admin/views/affliates/tmpl/index.html create mode 100644 src/com_tjvendors/admin/views/affliates/view.html.php diff --git a/src/com_tjvendors/admin/controllers/affliates.php b/src/com_tjvendors/admin/controllers/affliates.php new file mode 100644 index 00000000..dcf3ff85 --- /dev/null +++ b/src/com_tjvendors/admin/controllers/affliates.php @@ -0,0 +1,65 @@ + + * @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; + +jimport('joomla.application.component.controlleradmin'); + +/** + * Vendors list controller class. + * + * @since 1.6 + */ +class TjvendorsControllerAffliates extends JControllerAdmin +{ + /** + * Proxy for getModel. + * + * @param string $name Optional. Model name + * @param string $prefix Optional. Class prefix + * @param array $config Optional. Configuration array for model + * + * @return object The Model + * + * @since 1.6 + */ + public function getModel($name = 'Affliates', $prefix = 'TjvendorsModel', $config = array()) + { + $model = parent::getModel($name, $prefix, array('ignore_request' => true)); + + return $model; + } + + /** + * Method for delete affliates + * + * @return boolean + */ +/* + public function delete() + { + /* // Check for request forgeries + Session::checkToken() or jexit(JText::_('JINVALID_TOKEN')); + + $input = JFactory::getApplication()->input; + $client = $input->get('client', '', 'STRING'); + $cid = JFactory::getApplication()->input->get('cid', array(), 'array'); + $model = $this->getModel("affliates"); + + foreach ($cid as $affliate_id) + { + $model->deleteClientFromVendor($affliate_id, $client); + } + + $redirect = 'index.php?option=com_tjvendors&view=affliates&client=' . $client; + $this->setRedirect($redirect); + }*/ +} diff --git a/src/com_tjvendors/admin/models/affliates.php b/src/com_tjvendors/admin/models/affliates.php new file mode 100644 index 00000000..94306b00 --- /dev/null +++ b/src/com_tjvendors/admin/models/affliates.php @@ -0,0 +1,189 @@ + + * @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; + +jimport('joomla.application.component.modellist'); + +/** + * Methods supporting a list of Tjvendors records. + * + * @since 1.6 + */ +class TjvendorsModelAffliates extends JModelList +{ +/** + * Constructor. + * + * @param array $config An optional associative array of configuration settings. + * + * @see JController + * @since 1.0 + */ + public function __construct($config = array()) + { + if (empty($config['filter_fields'])) + { + $config['filter_fields'] = array( + 'id', + 'vendor_id', + 'name', + 'ordering', + 'state', + ); + } + + parent::__construct($config); + } + + /** + * Method to auto-populate the model state. + * + * Note. Calling getState in this method will result in recursion. + * + * @param string $ordering Elements order + * @param string $direction Order direction + * + * @return void + * + * @throws Exception + */ + protected function populateState($ordering = 'id', $direction = 'asc') + { + // Initialise variables. + $app = JFactory::getApplication('administrator'); + + // Set ordering. + $orderCol = $app->getUserStateFromRequest($this->context . '.filter_order', 'filter_order'); + + if (!in_array($orderCol, $this->filter_fields)) + { + $orderCol = 'id'; + } + + $this->setState('list.ordering', $orderCol); + + // Load the filter state. + $search = $app->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); + $this->setState('filter.search', $search); + + $published = $app->getUserStateFromRequest($this->context . '.filter.state', 'filter_published', '', 'string'); + $this->setState('filter.state', $published); + + // Load the parameters. + $params = JComponentHelper::getParams('com_tjvendors'); + $this->setState('params', $params); + + // List state information. + parent::populateState($ordering, $direction); + } + + /** + * Method to get a list of affliates. + * Overridden to add a check for access levels. + * + * @return mixed An array of data items on success, false on failure. + * + * @since 2.3.0 + */ + public function getItems() + { + $items = parent::getItems(); + + return $items; + } + + /** + * Build an SQL query to load the list data. + * + * @return JDatabaseQuery + * + * @since 1.0 + */ + protected function getListQuery() + { + // Get client + $input = JFactory::getApplication()->input; + $client = $input->get('client', '', 'STRING'); + + // Create a new query object. + $db = $this->getDbo(); + $query = $db->getQuery(true); + + // Create the base select statement. + $query->select('a.*'); + $query->from($db->quoteName('#__affliates', 'a')); + + // Filter by search in title + $search = $this->getState('filter.search'); + + if (!empty($search)) + { + if (stripos($search, 'id:') === 0) + { + $query->where($db->quoteName('a.id') . ' = ' . (int) substr($search, 3)); + } + else + { + $search = $db->Quote('%' . $db->escape(trim($search), true) . '%'); + $query->where('( a.name LIKE ' . $search . + ' )'); + } + } + + // Add the list ordering clause. + $orderCol = $this->state->get('list.ordering'); + $orderDirn = $this->state->get('list.direction'); + + if (!in_array(strtoupper($orderDirn), array('ASC', 'DESC'))) + { + $orderDirn = 'DESC'; + } + + $query->order($db->escape($orderCol . ' ' . $orderDirn)); + + return $query; + } + + /** + * Delete individuals and organization_contacts. + * + * @param array $indID individuals id array. + * + * @return boolean + * + * @since 2.3 + */ +/* public function delete($indID) + { + $db = JFactory::getDbo(); + + $query = $db->getQuery(true); + $query->delete($db->quoteName('#__affliates')); + $query->where($db->quoteName('#__affliates.id') . ' IN (' . implode(',', $indID) . ')'); + $db->setQuery($query); + + if (!$db->execute()) + { + $this->setError($db->getErrorMsg()); + + return false; + } + + foreach ($indID as $id) + { + $individualModel = BaseDatabaseModel::getInstance('Affliate', 'TjvendorsModel', array('ignore_request' => true)); + $individualModel->delete($id); + } + + return true; + }*/ +} diff --git a/src/com_tjvendors/admin/views/affliates/index.html b/src/com_tjvendors/admin/views/affliates/index.html new file mode 100644 index 00000000..42682b47 --- /dev/null +++ b/src/com_tjvendors/admin/views/affliates/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/com_tjvendors/admin/views/affliates/tmpl/default.php b/src/com_tjvendors/admin/views/affliates/tmpl/default.php new file mode 100644 index 00000000..de96d063 --- /dev/null +++ b/src/com_tjvendors/admin/views/affliates/tmpl/default.php @@ -0,0 +1,85 @@ + + * @copyright Copyright 2009-2017 TechJoomla. All rights reserved. + * @license GNU General Public License version 2 or later. + */ +// No direct access +defined('_JEXEC') or die; + +JHtml::_('bootstrap.tooltip'); +JHtml::_('formbehavior.chosen', 'select'); +JHtml::_('behavior.multiselect'); +JHTML::_('behavior.modal', 'a.modal'); + +$listOrder = $this->state->get('list.ordering'); +$listDirn = $this->state->get('list.direction'); +?> +
+ + $this)); + ?> +
+ items)) + { + ?> +
 
+
+ +
+
+ + + + + + + + + + + + + + + + items)) : ?> + items as $i => $row) : + $link = JRoute::_('index.php?option=com_tjvendors&task=affliate.edit&id=' . $row->id); + ?> + + + + + + + + +
+ + + + + +
+ pagination->getListFooter(); ?> +
+ id, ENT_COMPAT, 'UTF-8'); ?> + + name, ENT_COMPAT, 'UTF-8'); ?> + + code, ENT_COMPAT, 'UTF-8'); ?> +
+ + + diff --git a/src/com_tjvendors/admin/views/affliates/tmpl/index.html b/src/com_tjvendors/admin/views/affliates/tmpl/index.html new file mode 100644 index 00000000..42682b47 --- /dev/null +++ b/src/com_tjvendors/admin/views/affliates/tmpl/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/com_tjvendors/admin/views/affliates/view.html.php b/src/com_tjvendors/admin/views/affliates/view.html.php new file mode 100644 index 00000000..b0a70ca0 --- /dev/null +++ b/src/com_tjvendors/admin/views/affliates/view.html.php @@ -0,0 +1,115 @@ + + * @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; + +jimport('joomla.application.component.view'); +JLoader::import('com_tjvendors.helpers.fronthelper', JPATH_SITE . '/components'); + +/** + * View class for a list of Tjvendors. + * + * @since 1.6 + */ +class TjvendorsViewAffliates extends JViewLegacy +{ + public $state; + + public $items; + + public $pagination; + + public $sidebar; + + public $filterForm; + + public $activeFilters; + + /** + * Function to display. + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths + * + * @return boolean + * + * @since 2.3.0 + */ + public function display($tpl = null) + { + $mainframe = JFactory::getApplication(); + $user = JFactory::getUser(); + + if (!JFactory::getUser($user->id)->authorise('core.manage', 'com_tjvendors')) + { + $mainframe->enqueueMessage(JText::_('COM_TJVENDORS_AUTH_ERROR'), 'error'); + + return false; + } + + // Load submenu + TjvendorsHelper::addSubmenu('affliates'); + + // Get state + $this->state = $this->get('State'); + + // Get data from the model + $this->items = $this->get('Items'); + + $this->pagination = $this->get('Pagination'); + + $this->filterForm = $this->get('FilterForm'); + $this->activeFilters = $this->get('ActiveFilters'); + + // Get the toolbar object instance + // JToolbarHelper::title(JText::_("COM_JGIVE") . ": " . JText::_('COM_JGIVE_INDIVIDUALS'), 'list'); + // JToolBarHelper::preferences('com_jgive'); + + // Set the toolbar + // $this->addToolBar(); + + $this->sidebar = JHtmlSidebar::render(); + + // Display the template + parent::display($tpl); + } + + /** + * Add the page title and toolbar. + * + * @return void + * + * @since 2.3.0 + */ +/* protected function addToolBar() + { + $user = JFactory::getUser(); + $canCreate = $user->authorise('core.create', 'com_tjvendors'); + $canEdit = $user->authorise('core.edit', 'com_tjvendors'); + $canDelete = $user->authorise('core.delete', 'com_tjvendors'); + + if ($canCreate) + { + // Add buttons on toolbar + //JToolBarHelper::addNew('individual.add'); + } + + if ($canEdit && !empty($this->items)) + { + //JToolBarHelper::editList('individual.edit'); + } + + if ($canDelete && !empty($this->items)) + { + // JToolBarHelper::deleteList('', 'affliates.delete'); + // JToolBarHelper::divider(); + } + }*/ +} From 5617268db397040b22e177f38081703a1c3927f3 Mon Sep 17 00:00:00 2001 From: rajnish_d Date: Sat, 4 Jan 2020 17:26:19 +0530 Subject: [PATCH 2/2] Task #155602 feat : Affiliate list view --- src/com_tjvendors/admin/models/affliates.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com_tjvendors/admin/models/affliates.php b/src/com_tjvendors/admin/models/affliates.php index 94306b00..d64c8207 100644 --- a/src/com_tjvendors/admin/models/affliates.php +++ b/src/com_tjvendors/admin/models/affliates.php @@ -162,7 +162,7 @@ protected function getListQuery() * * @since 2.3 */ -/* public function delete($indID) + public function delete($indID) { $db = JFactory::getDbo(); @@ -185,5 +185,5 @@ protected function getListQuery() } return true; - }*/ + } }