| Current Path : /home/digilove/www/41423/ |
| Current File : /home/digilove/www/41423/datasets.php.tar |
home/digilove/public_html/administrator/components/com_jmap/tables/datasets.php 0000644 00000007114 15235300646 0024234 0 ustar 00 <?php
// namespace administrator\components\com_jmap\tables;
/**
*
* @package JMAP::DATASETS::administrator::components::com_jmap
* @subpackage tables
* @author Joomla! Extensions Store
* @copyright (C) 2021 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
// no direct access
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
* ORM Table for Datasets
*
* @package JMAP::DATASETS::administrator::components::com_jmap
* @subpackage tables
* @since 2.0
*/
class TableDatasets extends JTable {
/**
*
* @var int
*/
public $id;
/**
*
* @var string
*/
public $name;
/**
*
* @var string
*/
public $description;
/**
*
* @var int
*/
public $checked_out = 0;
/**
*
* @var datetime
*/
public $checked_out_time = 0;
/**
* @var int
*/
public $published = 1;
/**
*
* @var string
*/
public $sources = '[]';
/**
* Check Table override
* @override
*
* @see JTable::check()
*/
public function check() {
// Title required
if (! $this->name) {
$this->setError ( JText::_ ( 'COM_JMAP_VALIDATION_ERROR' ) );
return false;
}
return true;
}
/**
* Store Table override
* @override
*
* @see JTable::store()
*/
public function store($updateNulls = false) {
$result = parent::store($updateNulls);
// If store sucessful go on to popuplate relations table for sources/datasets
if($result) {
// Clear table from previous records
$queryDelete = "DELETE" .
"\n FROM " . $this->_db->quoteName('#__jmap_dss_relations') .
"\n WHERE" .
"\n " . $this->_db->quoteName('datasetid') . " = " .
"\n " . (int)$this->id;
if(!$this->_db->setQuery($queryDelete)->execute()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
// Manage multiple tuples to be inserted using single query
$selectedSources = json_decode($this->sources);
if(count($selectedSources)) {
$insertTuples = array();
foreach ($selectedSources as $source) {
$insertTuples[] = '(' . (int)$this->id . ',' . $source . ')';
}
$insertTuples = implode(',', $insertTuples);
$queryMultipleInsert = "INSERT" .
"\n INTO " . $this->_db->quoteName('#__jmap_dss_relations') .
"\n (" .
$this->_db->quoteName('datasetid') . "," .
$this->_db->quoteName('datasourceid') . ")" .
"\n VALUES " . $insertTuples;
if(!$this->_db->setQuery($queryMultipleInsert)->execute()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
}
}
return $result;
}
/**
* Delete Table override
* @override
*
* @see JTable::delete()
*/
public function delete($pk = null) {
$result = parent::delete($pk);
// If store sucessful go on to popuplate relations table for sources/datasets
if($result) {
// Clear table from previous records
$queryDelete = "DELETE" .
"\n FROM " . $this->_db->quoteName('#__jmap_dss_relations') .
"\n WHERE" .
"\n " . $this->_db->quoteName('datasetid') . " = " .
"\n " . (int)$this->id;
if(!$this->_db->setQuery($queryDelete)->execute()) {
$this->setError($this->_db->getErrorMsg());
return false;
}
}
return $result;
}
/**
* Class constructor
*
* @param Object& $_db
* return Object&
*/
public function __construct(&$_db) {
parent::__construct ( '#__jmap_datasets', 'id', $_db );
}
} home/digilove/public_html/administrator/components/com_jmap/models/datasets.php 0000644 00000007712 15235317236 0024254 0 ustar 00 <?php
// namespace administrator\components\com_jmap\models;
/**
* @package JMAP::DATASETS::administrator::components::com_jmap
* @subpackage models
* @author Joomla! Extensions Store
* @copyright (C) 2021 - Joomla! Extensions Store
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
*/
defined ( '_JEXEC' ) or die ( 'Restricted access' );
/**
* Datasets links model concrete implementation <<testable_behavior>>
*
* @package JMAP::DATASETS::administrator::components::com_jmap
* @subpackage models
* @since 2.0
*/
class JMapModelDatasets extends JMapModel {
/**
* Build list entities query
*
* @access protected
* @return string
*/
protected function buildListQuery() {
// WHERE
$where = array ();
$whereString = null;
$orderString = null;
// STATE FILTER
if ($filter_state = $this->state->get ( 'state' )) {
if ($filter_state == 'P') {
$where [] = 's.published = 1';
} else if ($filter_state == 'U') {
$where [] = 's.published = 0';
}
}
// TEXT FILTER
if ($this->state->get ( 'searchword' )) {
$where [] = "(s.name LIKE " . $this->_db->quote("%" . $this->state->get ( 'searchword' ) . "%") . ")";
}
if (count ( $where )) {
$whereString = "\n WHERE " . implode ( "\n AND ", $where );
}
// ORDERBY
if ($this->state->get ( 'order' )) {
$orderString = "\n ORDER BY " . $this->state->get ( 'order' ) . " ";
}
// ORDERDIR
if ($this->state->get ( 'order_dir' )) {
$orderString .= $this->state->get ( 'order_dir' );
}
$query = "SELECT s.*, u.name AS editor" .
"\n FROM #__jmap_datasets AS s" .
"\n LEFT JOIN #__users AS u" .
"\n ON s.checked_out = u.id" .
$whereString . $orderString;
return $query;
}
/**
* Main get data methods
*
* @access public
* @return Object[]
*/
public function getData() {
// Build query
$query = $this->buildListQuery ();
$this->_db->setQuery ( $query, $this->getState ( 'limitstart' ), $this->getState ( 'limit' ) );
try {
$result = $this->_db->loadObjectList ();
if($this->_db->getErrorNum()) {
throw new JMapException(JText::_('COM_JMAP_ERROR_RETRIEVING_DATASETS') . $this->_db->getErrorMsg(), 'error');
}
// Attach names for included data sources
if(count($result)) {
foreach ($result as &$row) {
$subQuery = "SELECT" .
"\n " . $this->_db->quoteName('name') .
"\n FROM " . $this->_db->quoteName('#__jmap') .
"\n WHERE " . $this->_db->quoteName('id') . ' IN ( ' . preg_replace('/\[|\]/i', '', $row->sources) . ' )';
$subQueryResults = $this->_db->setQuery($subQuery)->loadColumn();
$row->sourcesNames = $subQueryResults;
if($this->_db->getErrorNum()) {
throw new JMapException(JText::_('COM_JMAP_ERROR_RETRIEVING_DATASETS') . $this->_db->getErrorMsg(), 'error');
}
}
}
} catch (JMapException $e) {
$this->app->enqueueMessage($e->getMessage(), $e->getErrorLevel());
$result = array();
} catch (Exception $e) {
$jmapException = new JMapException($e->getMessage(), 'error');
$this->app->enqueueMessage($jmapException->getMessage(), $jmapException->getErrorLevel());
$result = array();
}
return $result;
}
/**
* Return select lists used as filter for editEntity
*
* @access public
* @param Object $record
* @return array
*/
public function getLists($record = null) {
$lists = parent::getLists($record);
$lists['sources'] = array();
// Select all published data sources
$query = $this->_db->getQuery(true);
$query->select($this->_db->quoteName('id'));
$query->select($this->_db->quoteName('name'));
$query->from($this->_db->quoteName('#__jmap'));
$query->where($this->_db->quoteName('published') . ' = 1');
$query->order($this->_db->quoteName('ordering'));
$this->_db->setQuery($query);
$lists['sources'] = $this->_db->loadObjectList();
return $lists;
}
}