- md5
- fcfb688462397e4f4fdfd69422150e1f
- sha1
- 77860649f875d7b53e06908599f0fca1881275a4
- sha256
- efbf725bb91de536cbe1477b91b80fa881627268f9449805475c5e4b2962fe3a
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\UCM;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\ContentHelper;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\TableInterface;
// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Base class for implementing UCM
*
* @since 3.1
*/
class UCMBase implements UCM
{
/**
* The UCM type object
*
* @var UCMType
* @since 3.1
*/
protected $type;
/**
* The alias for the content table
*
* @var string
* @since 3.1
*/
protected $alias;
/**
* Instantiate the UCMBase.
*
* @param string $alias The alias string
* @param UCMType $type The type object
*
* @since 3.1
*/
public function __construct($alias = null, UCMType $type = null)
{
// Setup dependencies.
$input = Factory::getApplication()->input;
$this->alias = $alias ?: $input->get('option') . '.' . $input->get('view');
$this->type = $type ?: $this->getType();
}
/**
* Store data to the appropriate table
*
* @param array $data Data to be stored
* @param TableInterface $table Table Object
* @param string $primaryKey The primary key name
*
* @return boolean True on success
*
* @since 3.1
* @throws \Exception
*/
protected function store($data, TableInterface $table = null, $primaryKey = null)
{
if (!$table) {
$table = Table::getInstance('Ucm');
}
$ucmId = $data['ucm_id'] ?? null;
$primaryKey = $primaryKey ?: $ucmId;
if (isset($primaryKey)) {
$table->load($primaryKey);
}
try {
$table->bind($data);
} catch (\RuntimeException $e) {
throw new \Exception($e->getMessage(), 500, $e);
}
try {
$table->store();
} catch (\RuntimeException $e) {
throw new \Exception($e->getMessage(), 500, $e);
}
return true;
}
/**
* Get the UCM Content type.
*
* @return UCMType The UCM content type
*
* @since 3.1
*/
public function getType()
{
if (!$this->type) {
$this->type = new UCMType($this->alias);
}
return $this->type;
}
/**
* Method to map the base ucm fields
*
* @param array $original Data array
* @param UCMType $type UCM Content Type
*
* @return array Data array of UCM mappings
*
* @since 3.1
*/
public function mapBase($original, UCMType $type = null)
{
$type = $type ?: $this->type;
$data = array(
'ucm_type_id' => $type->id,
'ucm_item_id' => $original[$type->primary_key],
'ucm_language_id' => ContentHelper::getLanguageId($original['language']),
);
return $data;
}
}
The same content is in 9 releases, Joomla 4.2.1 to 4.2.6. See them all, or every version of this file.