/** * Tests JTableContenttype::store * * @return void * * @since 3.1 */ public function testStoreSucceedsWithCorrectDatay() { $this->object->type_title = 'Unit Test Item'; $this->object->type_alias = 'com_test.item'; $this->assertTrue($this->object->store()); }
/** * Check if a UCM content type exists for this resource, and * create it if it does not */ protected function checkContentType(&$table, $options) { $contentType = new JTableContenttype($table->getDbo()); $alias = $table->getContentType(); // Fetch the extension name $component = $options['component']; $component = JComponentHelper::getComponent($component); // Fetch the name using the menu item $query = $table->getDbo()->getQuery(true); $query->select('title')->from('#__menu')->where('component_id = ' . (int) $component->id); $table->getDbo()->setQuery($query); $component_name = JText::_($table->getDbo()->loadResult()); $name = $component_name . ' ' . ucfirst($options['view']); // Create a new content type for our resource if (!$contentType->load(array('type_alias' => $alias))) { $contentType->type_title = $name; $contentType->type_alias = $alias; $contentType->table = json_encode(array('special' => array('dbtable' => $table->getTableName(), 'key' => $table->getKeyName(), 'type' => $name, 'prefix' => $options['table_prefix'], 'config' => 'array()'), 'common' => array('dbtable' => '#__ucm_content', 'key' => 'ucm_id', 'type' => 'CoreContent', 'prefix' => 'JTable', 'config' => 'array()'))); $contentType->field_mappings = json_encode(array('common' => array(0 => array("core_content_item_id" => $table->getKeyName(), "core_title" => $this->getUcmCoreAlias($table, 'title'), "core_state" => $this->getUcmCoreAlias($table, 'enabled'), "core_alias" => $this->getUcmCoreAlias($table, 'alias'), "core_created_time" => $this->getUcmCoreAlias($table, 'created_on'), "core_modified_time" => $this->getUcmCoreAlias($table, 'created_by'), "core_body" => $this->getUcmCoreAlias($table, 'body'), "core_hits" => $this->getUcmCoreAlias($table, 'hits'), "core_publish_up" => $this->getUcmCoreAlias($table, 'publish_up'), "core_publish_down" => $this->getUcmCoreAlias($table, 'publish_down'), "core_access" => $this->getUcmCoreAlias($table, 'access'), "core_params" => $this->getUcmCoreAlias($table, 'params'), "core_featured" => $this->getUcmCoreAlias($table, 'featured'), "core_metadata" => $this->getUcmCoreAlias($table, 'metadata'), "core_language" => $this->getUcmCoreAlias($table, 'language'), "core_images" => $this->getUcmCoreAlias($table, 'images'), "core_urls" => $this->getUcmCoreAlias($table, 'urls'), "core_version" => $this->getUcmCoreAlias($table, 'version'), "core_ordering" => $this->getUcmCoreAlias($table, 'ordering'), "core_metakey" => $this->getUcmCoreAlias($table, 'metakey'), "core_metadesc" => $this->getUcmCoreAlias($table, 'metadesc'), "core_catid" => $this->getUcmCoreAlias($table, 'cat_id'), "core_xreference" => $this->getUcmCoreAlias($table, 'xreference'), "asset_id" => $this->getUcmCoreAlias($table, 'asset_id'))), 'special' => array(0 => array()))); $contentType->router = ''; $contentType->store(); } }
/** * Check if a UCM content type exists for this resource, and * create it if it does not * * @param string $alias The content type alias (optional) * * @return null */ public function checkContentType($alias = null) { $contentType = new JTableContenttype($this->getDbo()); if (!$alias) { $alias = $this->getContentType(); } $aliasParts = explode('.', $alias); // Fetch the extension name $component = $aliasParts[0]; $component = JComponentHelper::getComponent($component); // Fetch the name using the menu item $query = $this->getDbo()->getQuery(true); $query->select('title')->from('#__menu')->where('component_id = ' . (int) $component->id); $this->getDbo()->setQuery($query); $component_name = JText::_($this->getDbo()->loadResult()); $name = $component_name . ' ' . ucfirst($aliasParts[1]); // Create a new content type for our resource if (!$contentType->load(array('type_alias' => $alias))) { $contentType->type_title = $name; $contentType->type_alias = $alias; $contentType->table = json_encode(array('special' => array('dbtable' => $this->getTableName(), 'key' => $this->getKeyName(), 'type' => $name, 'prefix' => $this->_tablePrefix, 'class' => 'FOFTable', 'config' => 'array()'), 'common' => array('dbtable' => '#__ucm_content', 'key' => 'ucm_id', 'type' => 'CoreContent', 'prefix' => 'JTable', 'config' => 'array()'))); $contentType->field_mappings = json_encode(array('common' => array(0 => array("core_content_item_id" => $this->getKeyName(), "core_title" => $this->getUcmCoreAlias('title'), "core_state" => $this->getUcmCoreAlias('enabled'), "core_alias" => $this->getUcmCoreAlias('alias'), "core_created_time" => $this->getUcmCoreAlias('created_on'), "core_modified_time" => $this->getUcmCoreAlias('created_by'), "core_body" => $this->getUcmCoreAlias('body'), "core_hits" => $this->getUcmCoreAlias('hits'), "core_publish_up" => $this->getUcmCoreAlias('publish_up'), "core_publish_down" => $this->getUcmCoreAlias('publish_down'), "core_access" => $this->getUcmCoreAlias('access'), "core_params" => $this->getUcmCoreAlias('params'), "core_featured" => $this->getUcmCoreAlias('featured'), "core_metadata" => $this->getUcmCoreAlias('metadata'), "core_language" => $this->getUcmCoreAlias('language'), "core_images" => $this->getUcmCoreAlias('images'), "core_urls" => $this->getUcmCoreAlias('urls'), "core_version" => $this->getUcmCoreAlias('version'), "core_ordering" => $this->getUcmCoreAlias('ordering'), "core_metakey" => $this->getUcmCoreAlias('metakey'), "core_metadesc" => $this->getUcmCoreAlias('metadesc'), "core_catid" => $this->getUcmCoreAlias('cat_id'), "core_xreference" => $this->getUcmCoreAlias('xreference'), "asset_id" => $this->getUcmCoreAlias('asset_id'))), 'special' => array(0 => array()))); $ignoreFields = array($this->getUcmCoreAlias('modified_on', null), $this->getUcmCoreAlias('modified_by', null), $this->getUcmCoreAlias('locked_by', null), $this->getUcmCoreAlias('locked_on', null), $this->getUcmCoreAlias('hits', null), $this->getUcmCoreAlias('version', null)); $contentType->content_history_options = json_encode(array("ignoreChanges" => array_filter($ignoreFields, 'strlen'))); $contentType->router = ''; $contentType->store(); } }
function initTags() { if (!$this->_isCompatible) { return; } $db = JFactory::getDBO(); $mapping_keys = array('core_content_item_id', 'core_title', 'core_state', 'core_alias', 'core_created_time', 'core_modified_time', 'core_body', 'core_hits', 'core_publish_up', 'core_publish_down', 'core_access', 'core_params', 'core_featured', 'core_metadata', 'core_language', 'core_images', 'core_urls', 'core_version', 'core_ordering', 'core_metakey', 'core_metadesc', 'core_catid', 'core_xreference', 'asset_id'); foreach ($this->structure as $structure) { $component = 'hikashop'; if (!empty($structure['component'])) { $component = $structure['component']; } $name = ucfirst($component) . ' ' . JText::_($structure['name']); $alias = 'com_' . $component . '.' . $structure['table']; $contentType = new JTableContenttype($db); if ($contentType->load(array('type_alias' => $alias))) { continue; } if (substr($structure['table'], 0, 1) == '#') { $table = $structure['table']; } else { $table = hikashop_table($structure['table']); } $contentType->type_title = $name; $contentType->type_alias = $alias; $contentType->table = json_encode(array('special' => array('dbtable' => $table, 'key' => $structure['id'], 'type' => $name, 'prefix' => 'JTable', 'config' => 'array()'), 'common' => array('dbtable' => '#__ucm_content', 'key' => 'ucm_id', 'type' => 'CoreContent', 'prefix' => 'JTable', 'config' => 'array()'))); $mapping_data = array('common' => array(), 'special' => array()); foreach ($structure['mapping'] as $mapping) { $type = @$mapping['type']; if (empty($type) || !isset($mapping_data[$type])) { $type = 'common'; } unset($mapping['type']); $i = count($mapping_data[$type]); $mapping_data[$type][$i] = array(); foreach ($mapping_keys as $k) { $mapping_data[$type][$i][$k] = 'null'; } foreach ($mapping as $key => $value) { if (isset($mapping_data[$type][$i][$key])) { $mapping_data[$type][$i][$key] = $value; } } } if (empty($mapping_data['special'])) { $mapping_data['special'][0] = array(); } if (empty($mapping_data['common'])) { $mapping_data['common'][0] = array(); } $contentType->field_mappings = json_encode($mapping_data); $contentType->router = ''; if (!empty($structure['router'])) { $contentType->router = $structure['router']; } $contentType->store(); } }