Commit e91645f2 authored by philippepary's avatar philippepary
Browse files

Added a auto-creatation of composition category if none exists on composition creation

parent 91d1ab1f
......@@ -129,6 +129,10 @@ class CategoriesService {
}
}
static function create($cat, $image = null) {
CategoriesService::createCat($cat,$image);
}
static function createCat($cat, $image = null) {
$pdo = PDOBuilder::getPDO();
$id = md5(time() . rand());
......
......@@ -43,6 +43,20 @@ class CompositionsService {
return $compo;
}
/** Check if a composition category exists
Create it if not */
static function checkCategory() {
if(CategoriesService::get(CompositionsService::CAT_ID) === null) {
$compositionsCategory = \Pasteque\Category::__build(CompositionsService::CAT_ID,
"COMPOSITIONS", "", "Compositions", false, 99);
if(!CategoriesService::create($compositionsCategory)) {
return true;
}
}
return true;
}
/** Return an array of composition */
static function getAll() {
$compos = array();
......@@ -105,6 +119,7 @@ class CompositionsService {
}
static function update($composition, $img = "", $groupImgs) {
CompositionsService::checkCategory();
if ($composition->id === null) {
return false;
}
......@@ -143,6 +158,7 @@ class CompositionsService {
}
static function create($composition, $img, $groupImgs) {
CompositionsService::checkCategory();
$pdo = PDOBuilder::getPDO();
$newTransaction = !$pdo->inTransaction();
if ($newTransaction) {
......
......@@ -183,7 +183,7 @@ $row .= "<select id=\"listSubGr\" onchange=\"showSubgroup();\"></select>\n";
$displayData = \Pasteque\row($row);
$content .= \Pasteque\form_fieldset($legend,$displayData);
$content .= \Pasteque\form_text("edit-sgName",null,\i18n("Subgroup.label"),null,"javascript:editSubgroup();");
$content .= \Pasteque\form_number("edit-sgOrder",null,\i18n("Subgroup.dispOrder"),1,0);
$content .= \Pasteque\form_number("edit-sgOrder",0,\i18n("Subgroup.dispOrder"),1,0);
$buttons = \Pasteque\jsAddButton(\i18n("Add subgroup", PLUGIN_NAME),"newSubgroup();");
$buttons .= \Pasteque\jsDeleteButton(\i18n("Delete subgroup", PLUGIN_NAME), "delSubgroup();");
$content .= \Pasteque\buttonGroup($buttons);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment