NEW Can set tags/categories to website pages.
This commit is contained in:
parent
89e32d33a4
commit
f9f5beb064
@ -8523,8 +8523,68 @@ abstract class CommonObject
|
||||
}
|
||||
}
|
||||
|
||||
/* Part for categories/tags */
|
||||
|
||||
/**
|
||||
* copy related categories to another object
|
||||
* Sets object to given categories.
|
||||
*
|
||||
* Deletes object from existing categories not supplied.
|
||||
* Adds it to non existing supplied categories.
|
||||
* Existing categories are left untouch.
|
||||
*
|
||||
* @param int[]|int $categories Category ID or array of Categories IDs
|
||||
* @param string $type_categ Category type ('customer', 'supplier', 'website_page', ...)
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function setCategories($categories, $type_categ)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
|
||||
// Handle single category
|
||||
if (!is_array($categories)) {
|
||||
$categories = array($categories);
|
||||
}
|
||||
|
||||
// Get current categories
|
||||
$c = new Categorie($this->db);
|
||||
$existing = $c->containing($this->id, $type_categ, 'id');
|
||||
|
||||
// Diff
|
||||
if (is_array($existing)) {
|
||||
$to_del = array_diff($existing, $categories);
|
||||
$to_add = array_diff($categories, $existing);
|
||||
} else {
|
||||
$to_del = array(); // Nothing to delete
|
||||
$to_add = $categories;
|
||||
}
|
||||
|
||||
$error = 0;
|
||||
|
||||
// Process
|
||||
foreach ($to_del as $del) {
|
||||
if ($c->fetch($del) > 0) {
|
||||
$c->del_type($this, $type_categ);
|
||||
}
|
||||
}
|
||||
foreach ($to_add as $add) {
|
||||
if ($c->fetch($add) > 0)
|
||||
{
|
||||
$result = $c->add_type($this, $type_categ);
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
$this->error = $c->error;
|
||||
$this->errors = $c->errors;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $error ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy related categories to another object
|
||||
*
|
||||
* @param int $fromId Id object source
|
||||
* @param int $toId Id object cible
|
||||
|
||||
@ -4070,7 +4070,7 @@ class Form
|
||||
* Return list of categories having choosed type
|
||||
*
|
||||
* @param string|int $type Type of category ('customer', 'supplier', 'contact', 'product', 'member'). Old mode (0, 1, 2, ...) is deprecated.
|
||||
* @param string $selected Id of category preselected or 'auto' (autoselect category if there is only one element)
|
||||
* @param string $selected Id of category preselected or 'auto' (autoselect category if there is only one element). Not used if $outputmode = 1.
|
||||
* @param string $htmlname HTML field name
|
||||
* @param int $maxlength Maximum length for labels
|
||||
* @param int|string|array $markafterid Keep only or removed all categories including the leaf $markafterid in category tree (exclude) or Keep only of category is inside the leaf starting with this id.
|
||||
|
||||
@ -39,6 +39,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formwebsite.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/website/class/website.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/website/class/websitepage.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
|
||||
$langs->loadLangs(array("admin", "other", "website", "errors"));
|
||||
|
||||
@ -1558,6 +1559,17 @@ if ($action == 'updatemeta')
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
// Supplier categories association
|
||||
$categoriesarray = GETPOST('categories', 'array');
|
||||
$result = $objectpage->setCategories($categoriesarray, Categorie::TYPE_WEBSITE_PAGE);
|
||||
if ($result < 0)
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error)
|
||||
{
|
||||
$db->commit();
|
||||
@ -3235,20 +3247,6 @@ if ($action == 'editmeta' || $action == 'createcontainer')
|
||||
if (GETPOST('WEBSITE_LANG', 'aZ09')) $pagelang = GETPOST('WEBSITE_LANG', 'aZ09');
|
||||
if (GETPOST('htmlheader', 'none')) $pagehtmlheader = GETPOST('htmlheader', 'none');
|
||||
|
||||
// Title
|
||||
print '<tr><td class="fieldrequired">';
|
||||
print $langs->trans('WEBSITE_TITLE');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" id="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'" autofocus>';
|
||||
print '</td></tr>';
|
||||
|
||||
// Alias
|
||||
print '<tr><td class="titlefieldcreate fieldrequired">';
|
||||
print $langs->trans('WEBSITE_PAGENAME');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat minwidth300" name="WEBSITE_PAGENAME" id="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
// Type of container
|
||||
print '<tr><td class="titlefield fieldrequired">';
|
||||
print $langs->trans('WEBSITE_TYPE_CONTAINER');
|
||||
@ -3265,6 +3263,27 @@ if ($action == 'editmeta' || $action == 'createcontainer')
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// Title
|
||||
print '<tr><td class="fieldrequired">';
|
||||
print $langs->trans('WEBSITE_TITLE');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat quatrevingtpercent" name="WEBSITE_TITLE" id="WEBSITE_TITLE" value="'.dol_escape_htmltag($pagetitle).'" autofocus>';
|
||||
print '</td></tr>';
|
||||
|
||||
// Alias
|
||||
print '<tr><td class="titlefieldcreate fieldrequired">';
|
||||
print $langs->trans('WEBSITE_PAGENAME');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat minwidth300" name="WEBSITE_PAGENAME" id="WEBSITE_PAGENAME" value="'.dol_escape_htmltag($pageurl).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="titlefieldcreate">';
|
||||
$htmlhelp = $langs->trans("WEBSITE_ALIASALTDesc");
|
||||
print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'aliastooltip');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat minwidth500" name="WEBSITE_ALIASALT" value="'.dol_escape_htmltag($pagealiasalt).'">';
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td>';
|
||||
print $langs->trans('WEBSITE_DESCRIPTION');
|
||||
print '</td><td>';
|
||||
@ -3365,12 +3384,28 @@ if ($action == 'editmeta' || $action == 'createcontainer')
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
print '<tr><td class="titlefieldcreate">';
|
||||
$htmlhelp = $langs->trans("WEBSITE_ALIASALTDesc");
|
||||
print $form->textwithpicto($langs->trans('WEBSITE_ALIASALT'), $htmlhelp, 1, 'help', '', 0, 2, 'aliastooltip');
|
||||
print '</td><td>';
|
||||
print '<input type="text" class="flat minwidth300" name="WEBSITE_ALIASALT" value="'.dol_escape_htmltag($pagealiasalt).'">';
|
||||
print '</td></tr>';
|
||||
// Categories
|
||||
if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire))
|
||||
{
|
||||
$langs->load('categories');
|
||||
|
||||
if (! GETPOSTISSET('categories')) {
|
||||
$cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', null, null, null, 1);
|
||||
$c = new Categorie($db);
|
||||
$cats = $c->containing($objectpage->id, Categorie::TYPE_WEBSITE_PAGE);
|
||||
$arrayselected = array();
|
||||
foreach ($cats as $cat) {
|
||||
$arrayselected[] = $cat->id;
|
||||
}
|
||||
|
||||
$cate_arbo = $form->select_all_categories(Categorie::TYPE_WEBSITE_PAGE, '', 'parent', null, null, 1);
|
||||
}
|
||||
|
||||
print '<tr class="visibleifsupplier"><td class="toptd">'.$form->editfieldkey('Categories', 'categories', '', $objectpage, 0).'</td><td colspan="3">';
|
||||
print img_picto('', 'category', 'class="paddingright"').$form->multiselectarray('categories', $cate_arbo, (GETPOSTISSET('categories') ? GETPOST('categories', 'array') : $arrayselected), null, null, null, null, "90%");
|
||||
print "</td></tr>";
|
||||
}
|
||||
|
||||
|
||||
$fuser = new User($db);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user