[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\UCM; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\Helper\ContentHelper; 14 use Joomla\CMS\Table\Table; 15 use Joomla\CMS\Table\TableInterface; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('JPATH_PLATFORM') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Base class for implementing UCM 23 * 24 * @since 3.1 25 */ 26 class UCMBase implements UCM 27 { 28 /** 29 * The UCM type object 30 * 31 * @var UCMType 32 * @since 3.1 33 */ 34 protected $type; 35 36 /** 37 * The alias for the content table 38 * 39 * @var string 40 * @since 3.1 41 */ 42 protected $alias; 43 44 /** 45 * Instantiate the UCMBase. 46 * 47 * @param string $alias The alias string 48 * @param UCMType $type The type object 49 * 50 * @since 3.1 51 */ 52 public function __construct($alias = null, UCMType $type = null) 53 { 54 // Setup dependencies. 55 $input = Factory::getApplication()->input; 56 $this->alias = $alias ?: $input->get('option') . '.' . $input->get('view'); 57 58 $this->type = $type ?: $this->getType(); 59 } 60 61 /** 62 * Store data to the appropriate table 63 * 64 * @param array $data Data to be stored 65 * @param TableInterface $table Table Object 66 * @param string $primaryKey The primary key name 67 * 68 * @return boolean True on success 69 * 70 * @since 3.1 71 * @throws \Exception 72 */ 73 protected function store($data, TableInterface $table = null, $primaryKey = null) 74 { 75 if (!$table) { 76 $table = Table::getInstance('Ucm'); 77 } 78 79 $ucmId = $data['ucm_id'] ?? null; 80 $primaryKey = $primaryKey ?: $ucmId; 81 82 if (isset($primaryKey)) { 83 $table->load($primaryKey); 84 } 85 86 try { 87 $table->bind($data); 88 } catch (\RuntimeException $e) { 89 throw new \Exception($e->getMessage(), 500, $e); 90 } 91 92 try { 93 $table->store(); 94 } catch (\RuntimeException $e) { 95 throw new \Exception($e->getMessage(), 500, $e); 96 } 97 98 return true; 99 } 100 101 /** 102 * Get the UCM Content type. 103 * 104 * @return UCMType The UCM content type 105 * 106 * @since 3.1 107 */ 108 public function getType() 109 { 110 if (!$this->type) { 111 $this->type = new UCMType($this->alias); 112 } 113 114 return $this->type; 115 } 116 117 /** 118 * Method to map the base ucm fields 119 * 120 * @param array $original Data array 121 * @param UCMType $type UCM Content Type 122 * 123 * @return array Data array of UCM mappings 124 * 125 * @since 3.1 126 */ 127 public function mapBase($original, UCMType $type = null) 128 { 129 $type = $type ?: $this->type; 130 131 $data = array( 132 'ucm_type_id' => $type->id, 133 'ucm_item_id' => $original[$type->primary_key], 134 'ucm_language_id' => ContentHelper::getLanguageId($original['language']), 135 ); 136 137 return $data; 138 } 139 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |