| Current Path : /var/www/components/com_contactpush/models/ |
| Current File : /var/www/components/com_contactpush/models/pushuid.php |
<?php
/** ______________________________________________
* o O | |
* ((((( o < Generated with Cook Self Service V3.1 |
* ( o o ) |______________________________________________|
* --------oOOO-----(_)-----OOOo---------------------------------- www.j-cook.pro --- +
* @version 1.0.0
* @package Contact Push
* @subpackage Push UIDs
* @copyright Netamity 2017
* @author Andy Hickey - www.netamity.com - andy@netamity.com
* @license GPL V2+
*
* .oooO Oooo.
* ( ) ( )
* -------------\ (----) /----------------------------------------------------------- +
* \_) (_/
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
/**
* Contactpush Item Model
*
* @package Contactpush
* @subpackage Classes
*/
class ContactpushCkModelPushuid extends ContactpushClassModelItem
{
/**
* View list alias
*
* @var string
*/
protected $view_item = 'pushuid';
/**
* View list alias
*
* @var string
*/
protected $view_list = 'pushuids';
/**
* Constructor
*
* @access public
* @param array $config An optional associative array of configuration settings.
*
* @return void
*/
public function __construct($config = array())
{
parent::__construct();
}
/**
* Method to delete item(s).
*
* @access public
* @param array &$pks Ids of the items to delete.
*
* @return boolean True on success.
*/
public function delete(&$pks)
{
if (!count( $pks ))
return true;
if (!parent::delete($pks))
return false;
return true;
}
/**
* Method to get the layout (including default).
*
* @access public
*
* @return string The layout alias.
*/
public function getLayout()
{
$jinput = JFactory::getApplication()->input;
return $jinput->get('layout', 'pushreg', 'STRING');
}
/**
* Returns a Table object, always creating it.
*
* @access public
* @param string $type The table type to instantiate.
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
*
* @since 1.6
*
* @return JTable A database object
*/
public function getTable($type = 'pushuid', $prefix = 'ContactpushTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to increment hits (check session and layout)
*
* @access public
* @param array $layouts List of authorized layouts for hitting the object.
*
*
* @since 11.1
*
* @return boolean Null if skipped. True when incremented. False if error.
*/
public function hit($layouts = null)
{
return parent::hit(array());
}
/**
* Method to get the data that should be injected in the form.
*
* @access protected
*
* @return mixed The data for the form.
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_contactpush.edit.pushuid.data', array());
if (empty($data)) {
//Default values shown in the form for new item creation
$data = $this->getItem();
// Prime some default values.
if ($this->getState('pushuid.id') == 0)
{
$jinput = JFactory::getApplication()->input;
$data->id = 0;
$data->push_user_id = null;
$data->user = $jinput->get('filter_user', $this->getState('filter.user'), 'INT');
$data->creation_date = null;
$data->access = $jinput->get('filter_access', $this->getState('filter.access'), 'INT');
$data->published = null;
}
}
return $data;
}
/**
* Method to auto-populate the model state.
*
* This method should only be called once per instantiation and is designed to
* be called on the first call to the getState() method unless the model
* configuration flag to ignore the request is set.
*
* Note. Calling getState in this method will result in recursion.
*
* @access protected
*
*
* @since 11.1
*
* @return void
*/
protected function populateState()
{
$app = JFactory::getApplication();
$session = JFactory::getSession();
$acl = ContactpushHelper::getActions();
parent::populateState();
//Only show the published items
if (!$acl->get('core.admin') && !$acl->get('core.edit.state'))
$this->setState('filter.published', 1);
}
/**
* Preparation of the item query.
*
* @access protected
* @param object &$query returns a filled query object.
* @param integer $pk The primary id key of the pushuid
*
* @return void
*/
protected function prepareQuery(&$query, $pk)
{
//FROM : Main table
$query->from('#__contactpush_pushuids AS a');
// Primary Key is always required
$this->addSelect('a.id');
switch($this->getState('context', 'all'))
{
case 'layout.pushreg':
$this->orm->select(array(
'access',
'access.title',
'creation_date',
'push_user_id',
'user',
'user.name'
));
// Item search : Based on Primary Key
$query->where('a.id = ' . (int) $pk);
break;
case 'all':
//SELECT : raw complete query without joins
$this->addSelect('a.*');
// Disable the pagination
$this->setState('list.limit', null);
$this->setState('list.start', null);
// Item search : Based on Primary Key
$query->where('a.id = ' . (int) $pk);
break;
}
$this->orm->select(array(
'access',
'published'
));
$this->orm->access('a', array(
'access' => 'access',
'publish' => 'published'
));
// ORDERING
$orderCol = $this->getState('list.ordering');
$orderDir = $this->getState('list.direction', 'ASC');
if ($orderCol)
$this->addOrder($orderCol . ' ' . $orderDir);
// Apply all SQL directives to the query
$this->applySqlStates($query);
}
/**
* Prepare and sanitise the table prior to saving.
*
* @access protected
* @param JTable $table A JTable object.
*
*
* @since 1.6
*
* @return void
*/
protected function prepareTable($table)
{
$date = JFactory::getDate();
if (empty($table->id))
{
//Creation date
if (empty($table->creation_date))
$table->creation_date = JFactory::getDate()->toSql();
}
else
{
}
}
/**
* Save an item.
*
* @access public
* @param array $data The post values.
*
* @return boolean True on success.
*/
public function save($data)
{
//Convert from a non-SQL formated date (creation_date)
$data['creation_date'] = ContactpushHelperDates::getSqlDate($data['creation_date'], array('Y-m-d H:i:s'), true, 'USER_UTC');
//Some security checks
$acl = ContactpushHelper::getActions();
//Secure the access key if not allowed to change
if (isset($data['access']) && !$acl->get('core.edit'))
unset($data['access']);
//Secure the published tag if not allowed to change
if (isset($data['published']) && !$acl->get('core.edit.state'))
unset($data['published']);
if (parent::save($data)) {
return true;
}
return false;
}
}
// Load the fork
ContactpushHelper::loadFork(__FILE__);
// Fallback if no fork has been found
if (!class_exists('ContactpushModelPushuid')){ class ContactpushModelPushuid extends ContactpushCkModelPushuid{} }