Support-Groups/admin/models/supportgroups.php

252 lines
16 KiB
PHP
Raw Normal View History

2016-03-06 00:50:22 +00:00
<?php
/*--------------------------------------------------------------------------------------------------------| www.vdm.io |------/
__ __ _ _____ _ _ __ __ _ _ _
\ \ / / | | | __ \ | | | | | \/ | | | | | | |
\ \ / /_ _ ___| |_ | | | | _____ _____| | ___ _ __ _ __ ___ ___ _ __ | |_ | \ / | ___| |_| |__ ___ __| |
\ \/ / _` / __| __| | | | |/ _ \ \ / / _ \ |/ _ \| '_ \| '_ ` _ \ / _ \ '_ \| __| | |\/| |/ _ \ __| '_ \ / _ \ / _` |
\ / (_| \__ \ |_ | |__| | __/\ V / __/ | (_) | |_) | | | | | | __/ | | | |_ | | | | __/ |_| | | | (_) | (_| |
\/ \__,_|___/\__| |_____/ \___| \_/ \___|_|\___/| .__/|_| |_| |_|\___|_| |_|\__| |_| |_|\___|\__|_| |_|\___/ \__,_|
| |
|_|
/-------------------------------------------------------------------------------------------------------------------------------/
@version 1.0.3
@build 6th March, 2016
@created 24th February, 2016
@package Support Groups
@subpackage supportgroups.php
@author Llewellyn van der Merwe <http://www.vdm.io>
@copyright Copyright (C) 2015. All Rights Reserved
@license GNU/GPL Version 2 or later - http://www.gnu.org/licenses/gpl-2.0.html
Support Groups
/-----------------------------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
jimport('joomla.application.component.helper');
/**
* Supportgroups Model
*/
class SupportgroupsModelSupportgroups extends JModelList
{
public function getIcons()
{
// load user for access menus
$user = JFactory::getUser();
// reset icon array
$icons = array();
// view groups array
$viewGroups = array(
'main' => array('png.support_group.add', 'png.support_groups', 'png.payment.add', 'png.payments', 'png.clinics', 'png.locations', 'png.regions', 'png.countries', 'png.currencies', 'png.help_documents')
2016-03-06 00:50:22 +00:00
);
// view access array
$viewAccess = array(
'support_group.create' => 'support_group.create',
'support_groups.access' => 'support_group.access',
'support_group.access' => 'support_group.access',
2016-03-06 00:50:22 +00:00
'support_groups.submenu' => 'support_group.submenu',
'support_groups.dashboard_list' => 'support_group.dashboard_list',
'support_group.dashboard_add' => 'support_group.dashboard_add',
'payment.create' => 'payment.create',
'payments.access' => 'payment.access',
'payment.access' => 'payment.access',
'payments.submenu' => 'payment.submenu',
'payments.dashboard_list' => 'payment.dashboard_list',
'payment.dashboard_add' => 'payment.dashboard_add',
'clinic.create' => 'clinic.create',
'clinics.access' => 'clinic.access',
'clinic.access' => 'clinic.access',
'clinics.submenu' => 'clinic.submenu',
'clinics.dashboard_list' => 'clinic.dashboard_list',
'location.create' => 'location.create',
'locations.access' => 'location.access',
'location.access' => 'location.access',
2016-03-06 00:50:22 +00:00
'locations.submenu' => 'location.submenu',
'locations.dashboard_list' => 'location.dashboard_list',
'region.create' => 'region.create',
'regions.access' => 'region.access',
'region.access' => 'region.access',
2016-03-06 00:50:22 +00:00
'regions.submenu' => 'region.submenu',
'regions.dashboard_list' => 'region.dashboard_list',
'country.create' => 'country.create',
'countries.access' => 'country.access',
'country.access' => 'country.access',
'countries.submenu' => 'country.submenu',
'countries.dashboard_list' => 'country.dashboard_list',
2016-03-06 00:50:22 +00:00
'currency.create' => 'currency.create',
'currencies.access' => 'currency.access',
'currency.access' => 'currency.access',
'currencies.submenu' => 'currency.submenu',
'currencies.dashboard_list' => 'currency.dashboard_list',
'help_document.create' => 'help_document.create',
'help_documents.access' => 'help_document.access',
'help_document.access' => 'help_document.access',
'help_documents.submenu' => 'help_document.submenu',
'help_documents.dashboard_list' => 'help_document.dashboard_list');
2016-03-06 00:50:22 +00:00
foreach($viewGroups as $group => $views)
{
$i = 0;
if (SupportgroupsHelper::checkArray($views))
{
foreach($views as $view)
{
$add = false;
if (strpos($view,'.') !== false)
{
$dwd = explode('.', $view);
if (count($dwd) == 3)
{
list($type, $name, $action) = $dwd;
}
elseif (count($dwd) == 2)
{
list($type, $name) = $dwd;
$action = false;
}
if ($action)
{
$viewName = $name;
switch($action)
{
case 'add':
$url ='index.php?option=com_supportgroups&view='.$name.'&layout=edit';
$image = $name.'_'.$action.'.'.$type;
$alt = $name.'&nbsp;'.$action;
$name = 'COM_SUPPORTGROUPS_DASHBOARD_'.SupportgroupsHelper::safeString($name,'U').'_ADD';
$add = true;
break;
default:
$url = 'index.php?option=com_categories&view=categories&extension=com_supportgroups.'.$name;
$image = $name.'_'.$action.'.'.$type;
$alt = $name.'&nbsp;'.$action;
$name = 'COM_SUPPORTGROUPS_DASHBOARD_'.SupportgroupsHelper::safeString($name,'U').'_'.SupportgroupsHelper::safeString($action,'U');
break;
}
}
else
{
$viewName = $name;
$alt = $name;
$url = 'index.php?option=com_supportgroups&view='.$name;
$image = $name.'.'.$type;
$name = 'COM_SUPPORTGROUPS_DASHBOARD_'.SupportgroupsHelper::safeString($name,'U');
$hover = false;
}
}
else
{
$viewName = $view;
$alt = $view;
$url = 'index.php?option=com_supportgroups&view='.$view;
$image = $view.'.png';
$name = ucwords($view).'<br /><br />';
$hover = false;
}
// first make sure the view access is set
if (SupportgroupsHelper::checkArray($viewAccess))
{
// setup some defaults
$dashboard_add = false;
$dashboard_list = false;
$accessTo = '';
$accessAdd = '';
// acces checking start
$accessCreate = (isset($viewAccess[$viewName.'.create'])) ? SupportgroupsHelper::checkString($viewAccess[$viewName.'.create']):false;
$accessAccess = (isset($viewAccess[$viewName.'.access'])) ? SupportgroupsHelper::checkString($viewAccess[$viewName.'.access']):false;
// set main controllers
$accessDashboard_add = (isset($viewAccess[$viewName.'.dashboard_add'])) ? SupportgroupsHelper::checkString($viewAccess[$viewName.'.dashboard_add']):false;
$accessDashboard_list = (isset($viewAccess[$viewName.'.dashboard_list'])) ? SupportgroupsHelper::checkString($viewAccess[$viewName.'.dashboard_list']):false;
// check for adding access
if ($add && $accessCreate)
{
$accessAdd = $viewAccess[$viewName.'.create'];
}
elseif ($add)
{
$accessAdd = 'core.create';
}
// check if acces to view is set
if ($accessAccess)
{
$accessTo = $viewAccess[$viewName.'.access'];
}
// set main access controllers
if ($accessDashboard_add)
{
$dashboard_add = $user->authorise($viewAccess[$viewName.'.dashboard_add'], 'com_supportgroups');
}
if ($accessDashboard_list)
{
$dashboard_list = $user->authorise($viewAccess[$viewName.'.dashboard_list'], 'com_supportgroups');
}
if (SupportgroupsHelper::checkString($accessAdd) && SupportgroupsHelper::checkString($accessTo))
{
// check access
if($user->authorise($accessAdd, 'com_supportgroups') && $user->authorise($accessTo, 'com_supportgroups') && $dashboard_add)
{
$icons[$group][$i] = new StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
elseif (SupportgroupsHelper::checkString($accessTo))
{
// check access
if($user->authorise($accessTo, 'com_supportgroups') && $dashboard_list)
{
$icons[$group][$i] = new StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
elseif (SupportgroupsHelper::checkString($accessAdd))
{
// check access
if($user->authorise($accessAdd, 'com_supportgroups') && $dashboard_add)
{
$icons[$group][$i] = new StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
else
{
$icons[$group][$i] = new StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
else
{
$icons[$group][$i] = new StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
$i++;
}
}
else
{
$icons[$group][$i] = false;
}
}
return $icons;
}
}