| Current Path : /home/zieirix/www/administrator/components/com_faqbookpro/models/ |
| Current File : /home/zieirix/www/administrator/components/com_faqbookpro/models/section.php |
<?php
/**
* @title Minitek FAQ Book
* @copyright Copyright (C) 2011-2020 Minitek, All rights reserved.
* @license GNU General Public License version 3 or later.
* @author url https://www.minitek.gr/
* @developers Minitek.gr
*/
defined('_JEXEC') or die;
require_once JPATH_COMPONENT_ADMINISTRATOR . '/helpers/faqbookpro.php';
class FAQBookProModelSection extends JModelAdmin
{
protected $text_prefix = 'COM_FAQBOOKPRO';
protected function canDelete($record)
{
if (!empty($record->id))
{
if ($record->state != -2)
{
return;
}
$user = JFactory::getUser();
return $user->authorise('core.delete', 'com_faqbookpro.section.' . (int) $record->id);
}
}
protected function canEditState($record)
{
$user = JFactory::getUser();
// Check for existing article.
if (!empty($record->id))
{
return $user->authorise('core.edit.state', 'com_faqbookpro.section.' . (int) $record->id);
}
// Default to component settings if section unknown.
else
{
return parent::canEditState('com_faqbookpro');
}
}
public function getTable($type = 'Section', $prefix = 'FAQBookProTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
public function getItem($pk = null)
{
if ($item = parent::getItem($pk))
{
// Convert the metadata field to an array.
$registry = new JRegistry;
$registry->loadString($item->metadata);
$item->metadata = $registry->toArray();
// Convert the params field to an array.
$registry = new JRegistry;
$registry->loadString($item->attribs);
$item->attribs = $registry->toArray();
}
return $item;
}
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_faqbookpro.section', 'section', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
$jinput = JFactory::getApplication()->input;
// The front end calls this model and uses a_id to avoid id clashes so we need to check for that first.
if ($jinput->get('a_id'))
{
$id = $jinput->get('a_id', 0);
}
// The back end uses id so we use that the rest of the time and set it to 0 by default.
else
{
$id = $jinput->get('id', 0);
}
// Determine correct permissions to check.
if ($this->getState('section.id'))
{
$id = $this->getState('section.id');
}
$user = JFactory::getUser();
// Check for existing section.
// Modify the form based on Edit State access controls.
if ($id != 0 && (!$user->authorise('core.edit.state', 'com_faqbookpro.section.' . (int) $id))
|| ($id == 0 && !$user->authorise('core.edit.state', 'com_faqbookpro'))
)
{
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('state', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is an article you can edit.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('state', 'filter', 'unset');
}
return $form;
}
protected function loadFormData()
{
// Check the session for previously entered form data.
$app = JFactory::getApplication();
$data = $app->getUserState('com_faqbookpro.edit.section.data', array());
if (empty($data))
{
$data = $this->getItem();
}
// If there are params fieldsets in the form it will fail with a registry object
if (isset($data->params) && $data->params instanceof Registry)
{
$data->params = $data->params->toArray();
}
$this->preprocessData('com_faqbookpro.section', $data);
return $data;
}
public function save($data)
{
$app = JFactory::getApplication();
if (parent::save($data))
{
if (isset($data['featured']))
{
$this->featured($this->getState($this->getName() . '.id'), $data['featured']);
}
return true;
}
return false;
}
protected function getReorderConditions($table)
{
$condition = array();
return $condition;
}
protected function preprocessForm(JForm $form, $data, $group = 'faqbookpro')
{
// Set the access control rules field component value.
$form->setFieldAttribute('rules', 'component', 'com_faqbookpro');
$form->setFieldAttribute('rules', 'section', 'section');
// Trigger the default form events.
parent::preprocessForm($form, $data, $group);
}
protected function cleanCache($group = null, $client_id = 0)
{
parent::cleanCache('com_faqbookpro');
}
}