Hello-World-Component/site/models/greetings.php

135 lines
4.1 KiB
PHP
Raw Permalink Normal View History

2018-05-05 01:23:14 +00:00
<?php
2022-03-03 03:59:15 +00:00
/*----------------------------------------------------------------------------------| www.vdm.io |----/
VDM
/-------------------------------------------------------------------------------------------------------/
2022-05-27 05:45:20 +00:00
@version 1.1.0
@build 27th May, 2022
2022-03-03 03:59:15 +00:00
@created 20th September, 2017
@package Hello World
@subpackage greetings.php
@author Llewellyn <https://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
____ _____ _____ __ __ __ __ ___ _____ __ __ ____ _____ _ _ ____ _ _ ____
(_ _)( _ )( _ )( \/ )( ) /__\ / __)( _ )( \/ )( _ \( _ )( \( )( ___)( \( )(_ _)
.-_)( )(_)( )(_)( ) ( )(__ /(__)\ ( (__ )(_)( ) ( )___/ )(_)( ) ( )__) ) ( )(
\____) (_____)(_____)(_/\/\_)(____)(__)(__) \___)(_____)(_/\/\_)(__) (_____)(_)\_)(____)(_)\_) (__)
/------------------------------------------------------------------------------------------------------*/
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
2022-05-27 05:45:20 +00:00
use Joomla\CMS\MVC\Model\ListModel;
2022-03-03 03:59:15 +00:00
use Joomla\Utilities\ArrayHelper;
/**
2022-05-27 05:45:20 +00:00
* Hello_world List Model for Greetings
2022-03-03 03:59:15 +00:00
*/
2022-05-27 05:45:20 +00:00
class Hello_worldModelGreetings extends ListModel
2022-03-03 03:59:15 +00:00
{
/**
* Model user data.
*
* @var strings
*/
protected $user;
protected $userId;
protected $guest;
protected $groups;
protected $levels;
protected $app;
protected $input;
protected $uikitComp;
/**
* Method to build an SQL query to load the list data.
*
* @return string An SQL query
*/
protected function getListQuery()
{
// Get the current user for authorisation checks
$this->user = JFactory::getUser();
$this->userId = $this->user->get('id');
$this->guest = $this->user->get('guest');
$this->groups = $this->user->get('groups');
$this->authorisedGroups = $this->user->getAuthorisedGroups();
$this->levels = $this->user->getAuthorisedViewLevels();
$this->app = JFactory::getApplication();
$this->input = $this->app->input;
2018-05-05 01:23:14 +00:00
$this->initSet = true;
// Make sure all records load, since no pagination allowed.
$this->setState('list.limit', 0);
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Get from #__hello_world_greeting as a
$query->select($db->quoteName(
array('a.id','a.asset_id','a.greeting','a.published','a.created_by','a.modified_by','a.created','a.modified','a.version','a.hits','a.ordering'),
array('id','asset_id','greeting','published','created_by','modified_by','created','modified','version','hits','ordering')));
$query->from($db->quoteName('#__hello_world_greeting', 'a'));
// Get where a.published is 1
$query->where('a.published = 1');
// return the query object
2022-03-03 03:59:15 +00:00
return $query;
}
/**
* Method to get an array of data items.
*
* @return mixed An array of data items on success, false on failure.
*/
public function getItems()
{
2018-05-05 01:23:14 +00:00
$user = JFactory::getUser();
// check if this user has permission to access item
if (!$user->authorise('site.greetings.access', 'com_hello_world'))
{
$app = JFactory::getApplication();
$app->enqueueMessage(JText::_('COM_HELLO_WORLD_NOT_AUTHORISED_TO_VIEW_GREETINGS'), 'error');
// redirect away to the home page if no access allowed.
$app->redirect(JURI::root());
return false;
2022-03-03 03:59:15 +00:00
}
// load parent items
$items = parent::getItems();
// Get the global params
2018-05-05 01:23:14 +00:00
$globalParams = JComponentHelper::getParams('com_hello_world', true);
// Insure all item fields are adapted where needed.
if (Hello_worldHelper::checkArray($items))
{
foreach ($items as $nr => &$item)
{
// Always create a slug for sef URL's
$item->slug = (isset($item->alias) && isset($item->id)) ? $item->id.':'.$item->alias : $item->id;
}
2022-03-03 03:59:15 +00:00
}
// return items
return $items;
2019-06-12 20:54:25 +00:00
}
2018-05-05 01:23:14 +00:00
/**
2019-06-12 20:54:25 +00:00
* Get the uikit needed components
*
* @return mixed An array of objects on success.
*
*/
2018-05-05 01:23:14 +00:00
public function getUikitComp()
{
if (isset($this->uikitComp) && Hello_worldHelper::checkArray($this->uikitComp))
{
return $this->uikitComp;
}
return false;
2022-03-03 03:59:15 +00:00
}
}