Spade
Mini Shell
Article.php000064400000002513151165736540006656 0ustar00<?php
/**
* @version 4.3.0
* @package Joomla
* @subpackage Helpdesk Pro
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2013 - 2021 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
namespace OSSolution\HelpdeskPro\Site\Model;
use OSL\Model\Model;
use OSL\Utils\Database as DatabaseUtils;
use Ossolution\HelpdeskPro\Site\Helper\Helper as HelpdeskproHelper;
defined('_JEXEC') or die;
class Article extends Model
{
/**
* Initialize the model, add new states
*/
protected function initialize()
{
$this->state->insert('id', 'int', 0);
}
/**
*
*/
public function getData()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('*')
->from('#__helpdeskpro_articles')
->where('id = ' . $this->state->id)
->where('published = 1');
if ($fieldSuffix = HelpdeskproHelper::getFieldSuffix())
{
DatabaseUtils::getMultilingualFields($query, array('title',
'text'), $fieldSuffix);
}
$db->setQuery($query);
return $db->loadObject();
}
public function hits()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->update('#__helpdeskpro_articles')
->set('hits = hits + 1')
->where('id = ' . $this->state->id);
$db->setQuery($query);
$db->execute();
}
}Articles.php000064400000003352151165736540007043 0ustar00<?php
/**
* @version 4.3.0
* @package Joomla
* @subpackage Helpdesk Pro
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2013 - 2021 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
namespace OSSolution\HelpdeskPro\Site\Model;
use OSL\Container\Container;
use OSL\Model\ListModel;
use OSL\Utils\Database as DatabaseUtils;
use OSSolution\HelpdeskPro\Site\Helper\Helper as HelpdeskProHelper;
defined('_JEXEC') or die;
class Articles extends ListModel
{
protected $clearJoin = false;
/**
* Constructor.
*
* @param Container $container
* @param array $options
*/
public function __construct(Container $container, $options = [])
{
$options['search_fields'] = ['tbl.id',
'tbl.title', 'tbl.text'];
$options['remember_states'] = true;
parent::__construct($container, $options);
}
/**
* Initialize the model, add new states
*/
protected function initialize()
{
$this->state->insert('id', 'int', 0);
}
/**
* Build the query object which is used to get list of records from
database
*
* @return \JDatabaseQuery
*/
protected function buildListQuery()
{
$query = parent::buildListQuery();
if ($fieldSuffix = HelpdeskProHelper::getFieldSuffix())
{
DatabaseUtils::getMultilingualFields($query, ['tbl.title'],
$fieldSuffix);
}
$query->innerJoin('#__helpdeskpro_categories AS c ON
tbl.category_id = c.id')
->where('tbl.published = 1')
->where('c.published = 1')
->where('c.access IN (' . implode(',',
$this->container->user->getAuthorisedViewLevels()) .
')');
if ($this->state->id)
{
$query->where('tbl.category_id = ' .
$this->state->id);
}
return $query;
}
}Categories.php000064400000004021151165736540007354 0ustar00<?php
/**
* @version 4.3.0
* @package Joomla
* @subpackage Helpdesk Pro
* @author Tuan Pham Ngoc
* @copyright Copyright (C) 2013 - 2021 Ossolution Team
* @license GNU/GPL, see LICENSE.php
*/
namespace OSSolution\HelpdeskPro\Site\Model;
use OSL\Model\ListModel;
use OSL\Utils\Database as DatabaseUtils;
use Ossolution\HelpdeskPro\Site\Helper\Helper as HelpdeskproHelper;
defined('_JEXEC') or die;
class Categories extends ListModel
{
/**
* Clear join clause for getTotal method
*
* @var bool
*/
protected $clearJoin = false;
/**
* Build the query object which is used to get list of records from
database
*
* @return \JDatabaseQuery
*/
protected function buildListQuery()
{
$query = parent::buildListQuery();
$user = $this->container->user;
$query->select('COUNT(b.id) AS total_articles')
->innerJoin('#__helpdeskpro_articles AS b ON tbl.id =
b.category_id')
->where('tbl.published = 1')
->where('tbl.access IN (' . implode(',',
$user->getAuthorisedViewLevels()) . ')')
->where('b.published = 1')
->group('tbl.id');
if ($fieldSuffix = HelpdeskproHelper::getFieldSuffix())
{
DatabaseUtils::getMultilingualFields($query, ['tbl.title'],
$fieldSuffix);
}
return $query;
}
/**
* Get list of articles belong to each category, max 10 articles per
category
*
* @param array $rows
*/
protected function beforeReturnData($rows)
{
$db = $this->getDbo();
$query = $db->getQuery(true);
$fieldSuffix = HelpdeskproHelper::getFieldSuffix();
$query->select('id, title')
->from('#__helpdeskpro_articles')
->order('ordering');
if ($fieldSuffix)
{
DatabaseUtils::getMultilingualFields($query, ['title'],
$fieldSuffix);
}
foreach ($rows as $row)
{
$query->where('category_id = ' . $row->id)
->where('published = 1');
$db->setQuery($query, 0, 10);
$row->articles = $db->loadObjectList();
$query->clear('where');
}
}
}