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

#63 Affiliate list view #64

Open
wants to merge 2 commits into
base: release-1.5.0
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
65 changes: 65 additions & 0 deletions src/com_tjvendors/admin/controllers/affliates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @package TJVendors
* @subpackage com_tjvendors
*
* @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;

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);
}*/
}
189 changes: 189 additions & 0 deletions src/com_tjvendors/admin/models/affliates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
<?php
/**
* @package TJVendors
* @subpackage com_tjvendors
*
* @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;

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;
}
}
1 change: 1 addition & 0 deletions src/com_tjvendors/admin/views/affliates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
85 changes: 85 additions & 0 deletions src/com_tjvendors/admin/views/affliates/tmpl/default.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php
/**
* @version SVN:
* @package Com_Tjvendors
* @author Techjoomla <[email protected]>
* @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');
?>
<form action="index.php?option=com_tjvendors&view=affliates" name="adminForm" id="adminForm" class="form-validate" method="post">

<?php
// Sorting and Searching Options
// echo JLayoutHelper::render('joomla.searchtools.default', array('view' => $this));
?>
<div class="clearfix"> </div>
<?php
if (empty($this->items))
{
?>
<div class="clearfix">&nbsp;</div>
<div class="alert alert-no-items">
<?php echo JText::_('NO_MATCHING_RESULTS'); ?>
</div>
<div id="j-main-container" class="span10">
<?php
}
else
{
?>
<table class='table table-striped'>
<thead>
<tr>
<th width="40%">
<?php echo JText::_('ID')?>
</th>
<th width="50%">
<?php echo JText::_('NAME');?>
</th>
<th width="50%">
<?php echo JText::_('CODE');?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3">
<?php echo $this->pagination->getListFooter(); ?>
</td>
</tr>
</tfoot>
<tbody>
<?php if (!empty($this->items)) : ?>
<?php foreach ($this->items as $i => $row) :
$link = JRoute::_('index.php?option=com_tjvendors&task=affliate.edit&id=' . $row->id);
?>
<tr>
<td>
<?php echo htmlspecialchars($row->id, ENT_COMPAT, 'UTF-8'); ?>
</td>
<td>
<?php echo htmlspecialchars($row->name, ENT_COMPAT, 'UTF-8'); ?>
</td>
<td>
<?php echo htmlspecialchars($row->code, ENT_COMPAT, 'UTF-8'); ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php
}?>
<?php echo JHtml::_('form.token'); ?>
</form>
1 change: 1 addition & 0 deletions src/com_tjvendors/admin/views/affliates/tmpl/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><body></body></html>
Loading