primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,122 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_checkin
*
* @copyright (C) 2008 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Checkin\Administrator\Controller;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Response\JsonResponse;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Checkin Controller
*
* @since 1.6
*/
class DisplayController extends BaseController
{
/**
* The default view.
*
* @var string
* @since 1.6
*/
protected $default_view = 'checkin';
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe URL parameters and their variable types.
* @see \Joomla\CMS\Filter\InputFilter::clean() for valid values.
*
* @return static A \JControllerLegacy object to support chaining.
*/
public function display($cachable = false, $urlparams = [])
{
return parent::display();
}
/**
* Check in a list of items.
*
* @return void
*/
public function checkin()
{
// Check for request forgeries
$this->checkToken();
$ids = (array) $this->input->get('cid', [], 'string');
if (empty($ids)) {
$this->app->enqueueMessage(Text::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'), 'warning');
} else {
// Get the model.
/** @var \Joomla\Component\Checkin\Administrator\Model\CheckinModel $model */
$model = $this->getModel('Checkin');
// Checked in the items.
$this->setMessage(Text::plural('COM_CHECKIN_N_ITEMS_CHECKED_IN', $model->checkin($ids)));
}
$this->setRedirect('index.php?option=com_checkin');
}
/**
* Provide the data for a badge in a menu item via JSON
*
* @return void
*
* @since 4.0.0
* @throws \Exception
*/
public function getMenuBadgeData()
{
if (!$this->app->getIdentity()->authorise('core.manage', 'com_checkin')) {
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}
$model = $this->getModel('Checkin');
$amount = (int) \count($model->getItems());
echo new JsonResponse($amount);
}
/**
* Method to get the number of locked icons
*
* @return void
*
* @since 4.0.0
* @throws \Exception
*/
public function getQuickiconContent()
{
if (!$this->app->getIdentity()->authorise('core.manage', 'com_checkin')) {
throw new \Exception(Text::_('JGLOBAL_AUTH_ACCESS_DENIED'));
}
$model = $this->getModel('Checkin');
$amount = (int) \count($model->getItems());
$result = [];
$result['amount'] = $amount;
$result['sronly'] = Text::plural('COM_CHECKIN_N_QUICKICON_SRONLY', $amount);
echo new JsonResponse($result);
}
}

View File

@ -0,0 +1,238 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_checkin
*
* @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Checkin\Administrator\Model;
use Joomla\CMS\Event\Checkin\AfterCheckinEvent;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\MVC\Model\ListModel;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Checkin Model
*
* @since 1.6
*/
class CheckinModel extends ListModel
{
/**
* Count of the total items checked out
*
* @var integer
*/
protected $total;
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* @param ?MVCFactoryInterface $factory The factory.
*
* @see \Joomla\CMS\MVC\Model\BaseDatabaseModel
* @since 3.2
*/
public function __construct($config = [], ?MVCFactoryInterface $factory = null)
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = [
'table',
'count',
];
}
parent::__construct($config, $factory);
}
/**
* Method to auto-populate the model state.
*
* Note: Calling getState in this method will result in recursion.
*
* @param string $ordering An optional ordering field.
* @param string $direction An optional direction (asc|desc).
*
* @return void
*
* @since 1.6
*/
protected function populateState($ordering = 'table', $direction = 'asc')
{
// List state information.
parent::populateState($ordering, $direction);
}
/**
* Checks in requested tables
*
* @param array $ids An array of table names. Optional.
*
* @return mixed The database results or 0
*
* @since 1.6
*/
public function checkin($ids = [])
{
$db = $this->getDatabase();
if (!\is_array($ids)) {
return 0;
}
// This int will hold the checked item count.
$results = 0;
$app = Factory::getApplication();
foreach ($ids as $tn) {
// Make sure we get the right tables based on prefix.
if (stripos($tn, $app->get('dbprefix')) !== 0) {
continue;
}
$fields = $db->getTableColumns($tn, false);
if (!(isset($fields['checked_out']) && isset($fields['checked_out_time']))) {
continue;
}
$query = $db->getQuery(true)
->update($db->quoteName($tn))
->set($db->quoteName('checked_out') . ' = DEFAULT');
if ($fields['checked_out_time']->Null === 'YES') {
$query->set($db->quoteName('checked_out_time') . ' = NULL');
} else {
$nullDate = $db->getNullDate();
$query->set($db->quoteName('checked_out_time') . ' = :checkouttime')
->bind(':checkouttime', $nullDate);
}
if ($fields['checked_out']->Null === 'YES') {
$query->where($db->quoteName('checked_out') . ' IS NOT NULL');
} else {
$query->where($db->quoteName('checked_out') . ' > 0');
}
$db->setQuery($query);
if ($db->execute()) {
$results += $db->getAffectedRows();
$this->getDispatcher()->dispatch('onAfterCheckin', new AfterCheckinEvent('onAfterCheckin', [
'subject' => $tn,
]));
}
}
return $results;
}
/**
* Get total of tables
*
* @return integer Total to check-in tables
*
* @since 1.6
*/
public function getTotal()
{
if (!isset($this->total)) {
$this->getItems();
}
return $this->total;
}
/**
* Get tables
*
* @return array Checked in table names as keys and checked in item count as values.
*
* @since 1.6
*/
public function getItems()
{
if (!isset($this->items)) {
$db = $this->getDatabase();
$tables = $db->getTableList();
$prefix = Factory::getApplication()->get('dbprefix');
// This array will hold table name as key and checked in item count as value.
$results = [];
foreach ($tables as $tn) {
// Make sure we get the right tables based on prefix.
if (stripos($tn, $prefix) !== 0) {
continue;
}
if ($this->getState('filter.search') && stripos($tn, $this->getState('filter.search')) === false) {
continue;
}
$fields = $db->getTableColumns($tn, false);
if (!(isset($fields['checked_out']) && isset($fields['checked_out_time']))) {
continue;
}
$query = $db->getQuery(true)
->select('COUNT(*)')
->from($db->quoteName($tn));
if ($fields['checked_out']->Null === 'YES') {
$query->where($db->quoteName('checked_out') . ' IS NOT NULL');
} else {
$query->where($db->quoteName('checked_out') . ' > 0');
}
$db->setQuery($query);
$count = $db->loadResult();
if ($count) {
$results[$tn] = $count;
}
}
$this->total = \count($results);
// Order items by table
if ($this->getState('list.ordering') == 'table') {
if (strtolower($this->getState('list.direction')) == 'asc') {
ksort($results);
} else {
krsort($results);
}
} else {
// Order items by number of items
if (strtolower($this->getState('list.direction')) == 'asc') {
asort($results);
} else {
arsort($results);
}
}
// Pagination
$limit = (int) $this->getState('list.limit');
if ($limit !== 0) {
$this->items = \array_slice($results, $this->getState('list.start'), $limit);
} else {
$this->items = $results;
}
}
return $this->items;
}
}

View File

@ -0,0 +1,139 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_checkin
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Checkin\Administrator\View\Checkin;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\ToolbarHelper;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* HTML View class for the Checkin component
*
* @since 1.0
*/
class HtmlView extends BaseHtmlView
{
/**
* An array of items
*
* @var array
*/
protected $items;
/**
* Total number of items
*
* @var integer
*/
protected $total = 0;
/**
* The pagination object
*
* @var \Joomla\CMS\Pagination\Pagination
*/
protected $pagination;
/**
* The model state
*
* @var \Joomla\Registry\Registry
*/
protected $state;
/**
* Form object for search filters
*
* @var \Joomla\CMS\Form\Form
*
* @since 4.0.0
*/
public $filterForm;
/**
* The active search filters
*
* @var array
*
* @since 4.0.0
*/
public $activeFilters;
/**
* Is this view an Empty State
*
* @var boolean
*
* @since 4.0.0
*/
private $isEmptyState = false;
/**
* Execute and display a template script.
*
* @param string $tpl The name of the template file to parse; automatically searches through the template paths.
*
* @return void
*/
public function display($tpl = null)
{
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->state = $this->get('State');
$this->total = $this->get('Total');
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
if (!\count($this->items)) {
$this->isEmptyState = true;
$this->setLayout('emptystate');
}
// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}
$this->addToolbar();
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @return void
*
* @since 1.6
*/
protected function addToolbar()
{
ToolbarHelper::title(Text::_('COM_CHECKIN_GLOBAL_CHECK_IN'), 'check-square');
$toolbar = $this->getDocument()->getToolbar();
if (!$this->isEmptyState) {
$toolbar->checkin('checkin');
}
if ($this->getCurrentUser()->authorise('core.admin', 'com_checkin')) {
$toolbar->divider();
$toolbar->preferences('com_checkin');
$toolbar->divider();
}
$toolbar->help('Maintenance:_Global_Check-in');
}
}