本文整理汇总了PHP中CategoriesHelper::createCategory方法的典型用法代码示例。如果您正苦于以下问题:PHP CategoriesHelper::createCategory方法的具体用法?PHP CategoriesHelper::createCategory怎么用?PHP CategoriesHelper::createCategory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CategoriesHelper
的用法示例。
在下文中一共展示了CategoriesHelper::createCategory方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function save($data)
{
$input = JFactory::getApplication()->input;
$filter = JFilterInput::getInstance();
if (isset($data['metadata']) && isset($data['metadata']['author'])) {
$data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
}
if (isset($data['created_by_alias'])) {
$data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM');
}
if (isset($data['images']) && is_array($data['images'])) {
$registry = new Registry();
$registry->loadArray($data['images']);
$data['images'] = (string) $registry;
}
JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
// Check if New Category exists
if ($catid > 0) {
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_content');
}
// Save New Categoryg
if ($catid == 0 && $this->canCreateCategory()) {
$table = array();
$table['title'] = $data['catid'];
$table['parent_id'] = 1;
$table['extension'] = 'com_content';
$table['language'] = $data['language'];
$table['published'] = 1;
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
}
if (isset($data['urls']) && is_array($data['urls'])) {
$check = $input->post->get('jform', array(), 'array');
foreach ($data['urls'] as $i => $url) {
if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) {
if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) {
$data['urls'][$i] = $check['urls'][$i];
} else {
$data['urls'][$i] = JStringPunycode::urlToPunycode($url);
}
}
}
unset($check);
$registry = new Registry();
$registry->loadArray($data['urls']);
$data['urls'] = (string) $registry;
}
// Alter the title for save as copy
if ($input->get('task') == 'save2copy') {
$origTable = clone $this->getTable();
$origTable->load($input->getInt('id'));
if ($data['title'] == $origTable->title) {
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $title;
$data['alias'] = $alias;
} else {
if ($data['alias'] == $origTable->alias) {
$data['alias'] = '';
}
}
$data['state'] = 0;
}
// Automatic handling of alias for empty fields
if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) {
if ($data['alias'] == null) {
if (JFactory::getConfig()->get('unicodeslugs') == 1) {
$data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
} else {
$data['alias'] = JFilterOutput::stringURLSafe($data['title']);
}
$table = JTable::getInstance('Content', 'JTable');
if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
$msg = JText::_('COM_CONTENT_SAVE_WARNING');
}
list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['alias'] = $alias;
if (isset($msg)) {
JFactory::getApplication()->enqueueMessage($msg, 'warning');
}
}
}
if (parent::save($data)) {
if (isset($data['featured'])) {
$this->featured($this->getState($this->getName() . '.id'), $data['featured']);
}
return true;
}
return false;
}
示例2: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 3.1
*/
public function save($data)
{
$app = JFactory::getApplication();
JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
// Check if New Category exists
if ($catid > 0) {
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_weblinks');
}
// Save New Category
if ($catid == 0 && $this->canCreateCategory()) {
$table = array();
$table['title'] = $data['catid'];
$table['parent_id'] = 1;
$table['extension'] = 'com_weblinks';
$table['language'] = $data['language'];
$table['published'] = 1;
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
}
// Alter the title for save as copy
if ($app->input->get('task') == 'save2copy') {
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
$data['title'] = $name;
$data['alias'] = $alias;
$data['state'] = 0;
}
return parent::save($data);
}
示例3: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 3.0
*/
public function save($data)
{
$input = JFactory::getApplication()->input;
JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
// Check if New Category exists
if ($catid > 0) {
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_contact');
}
// Save New Category
if ($catid == 0 && $this->canCreateCategory()) {
$table = array();
$table['title'] = $data['catid'];
$table['parent_id'] = 1;
$table['extension'] = 'com_contact';
$table['language'] = $data['language'];
$table['published'] = 1;
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
}
// Alter the name for save as copy
if ($input->get('task') == 'save2copy') {
$origTable = clone $this->getTable();
$origTable->load($input->getInt('id'));
if ($data['name'] == $origTable->name) {
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
$data['name'] = $name;
$data['alias'] = $alias;
} else {
if ($data['alias'] == $origTable->alias) {
$data['alias'] = '';
}
}
$data['published'] = 0;
}
$links = array('linka', 'linkb', 'linkc', 'linkd', 'linke');
foreach ($links as $link) {
if ($data['params'][$link]) {
$data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]);
}
}
return parent::save($data);
}
示例4: save
/**
* Method to save the form data.
*
* @param array $data The form data.
*
* @return boolean True on success.
*
* @since 1.6
*/
public function save($data)
{
$input = JFactory::getApplication()->input;
JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php');
// Cast catid to integer for comparison
$catid = (int) $data['catid'];
// Check if New Category exists
if ($catid > 0) {
$catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_banners');
}
// Save New Category
if ($catid == 0) {
$table = array();
$table['title'] = $data['catid'];
$table['parent_id'] = 1;
$table['extension'] = 'com_banners';
$table['language'] = $data['language'];
$table['published'] = 1;
// Create new category and get catid back
$data['catid'] = CategoriesHelper::createCategory($table);
}
// Alter the name for save as copy
if ($input->get('task') == 'save2copy') {
/** @var BannersTableBanner $origTable */
$origTable = clone $this->getTable();
$origTable->load($input->getInt('id'));
if ($data['name'] == $origTable->name) {
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
$data['name'] = $name;
$data['alias'] = $alias;
} else {
if ($data['alias'] == $origTable->alias) {
$data['alias'] = '';
}
}
$data['state'] = 0;
}
return parent::save($data);
}