26require_once DOL_DOCUMENT_ROOT .
'/core/lib/functions.lib.php';
27require_once DOL_DOCUMENT_ROOT .
'/modulebuilder/class/NamingContract.class.php';
28require_once DOL_DOCUMENT_ROOT .
'/modulebuilder/class/AccessPolicyConfig.class.php';
50 $identifier = $prefix.$module.
'_'.$table.
'_'.$key;
61 return $prefix.$module.
'_'.$table.
'_'.$key;
81 if (empty($objectname)) {
84 if (empty($readdir)) {
88 if (!empty($addfieldentry[
'arrayofkeyval']) && !is_array($addfieldentry[
'arrayofkeyval'])) {
89 dol_print_error(
null,
'Bad parameter addfieldentry with a property arrayofkeyval defined but that is not an array.');
96 if (is_array($addfieldentry) && count($addfieldentry) > 0) {
97 if (empty($addfieldentry[
'name'])) {
98 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Name")),
null,
'errors');
101 if (empty($addfieldentry[
'label'])) {
102 setEventMessages($langs->trans(
'ErrorFieldRequired', $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
105 if (!preg_match(
'/^(integer|price|sellist|varchar|double|text|html|duration|stars)/', $addfieldentry[
'type'])
106 && !preg_match(
'/^(boolean|smallint|real|date|datetime|timestamp|phone|email|url|ip|password)$/', $addfieldentry[
'type'])) {
107 setEventMessages($langs->trans(
'BadValueForType', $addfieldentry[
'type']),
null,
'errors');
112 if (preg_match(
'/^stars\((.+)\)$/', $addfieldentry[
'type'], $matches)) {
113 if (!preg_match(
'/^[0-9]+$/', $matches[1]) || $matches[1] < 1 || $matches[1] > 10) {
114 setEventMessages($langs->trans(
'BadValueForType', $addfieldentry[
'type']),
null,
'errors');
120 $pathoffiletoeditsrc = $readdir.
'/class/'.
dol_strtolower($objectname).
'.class.php';
121 $pathoffiletoedittarget = $destdir.
'/class/'.
dol_strtolower($objectname).
'.class.php'.($readdir != $destdir ?
'.new' :
'');
123 $langs->load(
"errors");
124 setEventMessages($langs->trans(
"ErrorFileNotFound", $pathoffiletoeditsrc),
null,
'errors');
132 include_once $pathoffiletoeditsrc;
133 if (class_exists($objectname)) {
134 $object =
new $objectname($db);
138 '@phan-var-force CommonObject $object';
141 dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.
'.back', $newmask, 1);
144 $contentclass = file_get_contents(
dol_osencode($pathoffiletoeditsrc));
148 if (is_array($addfieldentry) && count($addfieldentry)) {
149 $name = $addfieldentry[
'name'];
150 unset($addfieldentry[
'name']);
152 $object->fields[$name] = $addfieldentry;
154 if (!empty($delfieldentry)) {
155 $name = $delfieldentry;
163 $texttoinsert =
'// BEGIN MODULEBUILDER PROPERTIES'.
"\n";
164 $texttoinsert .=
"\t".
'
168 $texttoinsert .=
"\t".
'public $fields = array('.
"\n";
171 foreach (
$object->fields as $key => $val) {
173 $texttoinsert .=
"\t\t".
'"'.$key.
'" => array(';
174 $texttoinsert .=
'"type" => "'.dol_escape_php($val[
'type']).
'",';
175 $texttoinsert .=
' "label" => "'.dol_escape_php($val[
'label']).
'",';
176 if (!empty($val[
'picto'])) {
177 $texttoinsert .=
' "picto" => "'.dol_escape_php($val[
'picto']).
'",';
179 $texttoinsert .=
' "enabled" => "'.dol_escape_php($val[
'enabled'] !==
'' ? $val[
'enabled'] :
'1').
'",';
180 $texttoinsert .=
" 'position' => ".($val[
'position'] !==
'' ? (int) $val[
'position'] : 50).
",";
181 $texttoinsert .=
" 'notnull' => ".(empty($val[
'notnull']) ? 0 : (int) $val[
'notnull']).
",";
182 $texttoinsert .=
' "visible" => "'.dol_escape_php($val[
'visible'] !==
'' ? $val[
'visible'] :
'-1').
'",';
183 if (!empty($val[
'noteditable'])) {
184 $texttoinsert .=
' "noteditable" => "'.dol_escape_php((
string) $val[
'noteditable']).
'",';
186 if (!empty($val[
'alwayseditable'])) {
187 $texttoinsert .=
' "alwayseditable" => "'.dol_escape_php((
string) $val[
'alwayseditable']).
'",';
189 if (array_key_exists(
'default', $val) && (!empty($val[
'default']) || $val[
'default'] ===
'0')) {
190 $texttoinsert .=
' "default" => "'.dol_escape_php($val[
'default']).
'",';
192 if (!empty($val[
'index'])) {
193 $texttoinsert .=
' "index" => "'.(int) $val[
'index'].
'",';
195 if (!empty($val[
'foreignkey'])) {
196 $texttoinsert .=
' "foreignkey" => "'.dol_escape_php($val[
'foreignkey']).
'",';
198 if (!empty($val[
'searchall'])) {
199 $texttoinsert .=
' "searchall" => "'.(int) $val[
'searchall'].
'",';
201 if (!empty($val[
'isameasure'])) {
202 $texttoinsert .=
' "isameasure" => "'.(int) $val[
'isameasure'].
'",';
204 if (!empty($val[
'css'])) {
205 $texttoinsert .=
' "css" => "'.dol_escape_php($val[
'css']).
'",';
207 if (!empty($val[
'cssview'])) {
208 $texttoinsert .=
' "cssview" => "'.dol_escape_php($val[
'cssview']).
'",';
210 if (!empty($val[
'csslist'])) {
211 $texttoinsert .=
' "csslist" => "'.dol_escape_php($val[
'csslist']).
'",';
213 if (!empty($val[
'help'])) {
214 $texttoinsert .=
' "help" => "'.dol_escape_php($val[
'help']).
'",';
216 if (!empty($val[
'showoncombobox'])) {
217 $texttoinsert .=
' "showoncombobox" => "'.(int) $val[
'showoncombobox'].
'",';
219 if (!empty($val[
'disabled'])) {
220 $texttoinsert .=
' "disabled" => "'.(int) $val[
'disabled'].
'",';
222 if (!empty($val[
'autofocusoncreate'])) {
223 $texttoinsert .=
' "autofocusoncreate" => "'.(int) $val[
'autofocusoncreate'].
'",';
225 if (!empty($val[
'arrayofkeyval'])) {
226 $texttoinsert .=
' "arrayofkeyval" => array(';
228 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
230 $texttoinsert .=
", ";
232 $texttoinsert .=
'"'.dol_escape_php($key2).
'" => "'.
dol_escape_php($val2).
'"';
235 $texttoinsert .=
'),';
237 if (!empty($val[
'validate'])) {
238 $texttoinsert .=
' "validate" => "'.(int) $val[
'validate'].
'",';
240 if (!empty($val[
'comment'])) {
241 $texttoinsert .=
' "comment" => "'.dol_escape_php($val[
'comment']).
'"';
244 $texttoinsert .=
"),\n";
249 $texttoinsert .=
"\t".
');'.
"\n";
255 foreach (
$object->fields as $key => $val) {
258 $texttoinsert .=
"\t".
'public $'.$key.
";";
263 $texttoinsert .=
"\n";
267 $texttoinsert .=
"\t".
'// END MODULEBUILDER PROPERTIES';
271 $contentclass = preg_replace(
'/\/\/ BEGIN MODULEBUILDER PROPERTIES.*END MODULEBUILDER PROPERTIES/ims', $texttoinsert, $contentclass);
274 dol_mkdir(dirname($pathoffiletoedittarget));
277 $result = file_put_contents(
dol_osencode($pathoffiletoedittarget), $contentclass);
280 dolChmod($pathoffiletoedittarget, $newmask);
287 print $e->getMessage();
311 if (empty($objectname)) {
314 if (empty($readdir)) {
318 $pathoffiletoclasssrc = $readdir.
'/class/'.
dol_strtolower($objectname).
'.class.php';
321 if ($moduletype ==
'internal') {
322 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.dol_strtolower(
$module).
'_'.
dol_strtolower($objectname).
'.sql';
323 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
325 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
327 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
328 $pathoffiletoeditsrc =
'/../install/mysql/tables/llx_'.dol_strtolower(
$module).
'.sql';
334 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
336 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
338 if (!
dol_is_file($readdir.$pathoffiletoeditsrc)) {
339 $pathoffiletoeditsrc =
'/sql/llx_'.dol_strtolower(
$module).
'.sql';
346 $pathoffiletoedittarget = $destdir.$pathoffiletoeditsrc.($readdir != $destdir ?
'.new' :
'');
347 $pathoffiletoeditsrc = $readdir.$pathoffiletoeditsrc;
350 $langs->load(
"errors");
351 setEventMessages($langs->trans(
"ErrorFileNotFound", $pathoffiletoeditsrc),
null,
'errors');
358 include_once $pathoffiletoclasssrc;
359 if (class_exists($objectname)) {
360 $object =
new $objectname($db);
366 print $e->getMessage();
370 dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.
'.back', $newmask, 1);
372 $contentsqlfile = file_get_contents(
dol_osencode($pathoffiletoeditsrc));
375 $texttoinsert =
'-- BEGIN MODULEBUILDER FIELDS'.
"\n";
377 foreach (
$object->fields as $key => $val) {
380 $type = $val[
'type'];
381 $type = preg_replace(
'/:.*$/',
'', $type);
383 if ($type ==
'html') {
385 } elseif ($type ==
'price') {
387 } elseif (in_array($type, array(
'link',
'sellist',
'duration'))) {
389 } elseif ($type ==
'chkbxlst') {
390 $type =
'varchar(128)';
391 } elseif ($type ==
'mail' || $type ==
'email') {
392 $type =
'varchar(128)';
393 } elseif (strpos($type,
'stars(') === 0) {
395 } elseif ($type ==
'phone') {
396 $type =
'varchar(20)';
397 } elseif ($type ==
'ip') {
398 $type =
'varchar(32)';
399 } elseif ($type ==
'url') {
400 $type =
'varchar(255)';
403 $texttoinsert .=
"\t".$key.
" ".$type;
404 if ($key ==
'rowid') {
405 $texttoinsert .=
' AUTO_INCREMENT PRIMARY KEY';
406 } elseif ($type ==
'timestamp') {
407 $texttoinsert .=
' DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP';
409 if ($key ==
'entity') {
410 $texttoinsert .=
' DEFAULT 1';
412 if (!empty($val[
'default'])) {
413 if (preg_match(
'/^null$/i', $val[
'default'])) {
414 $texttoinsert .=
" DEFAULT NULL";
415 } elseif (preg_match(
'/varchar/', $type)) {
416 $texttoinsert .=
" DEFAULT '".$db->escape($val[
'default']).
"'";
418 $texttoinsert .= (($val[
'default'] > 0) ?
' DEFAULT '.$val[
'default'] :
'');
422 $texttoinsert .= ((!empty($val[
'notnull']) && $val[
'notnull'] > 0) ?
' NOT NULL' :
'');
423 if ($i < count(
$object->fields)) {
424 $texttoinsert .=
", ";
426 $texttoinsert .=
"\n";
429 $texttoinsert .=
"\t".
'-- END MODULEBUILDER FIELDS';
431 $contentsqlfile = preg_replace(
'/-- BEGIN MODULEBUILDER FIELDS.*END MODULEBUILDER FIELDS/ims', $texttoinsert, $contentsqlfile);
433 $result = file_put_contents($pathoffiletoedittarget, $contentsqlfile);
435 dolChmod($pathoffiletoedittarget, $newmask);
438 setEventMessages($langs->trans(
"ErrorFailToCreateFile", $pathoffiletoedittarget),
null,
'errors');
442 $pathoffiletoeditsrc = preg_replace(
'/\.sql$/',
'.key.sql', $pathoffiletoeditsrc);
443 $pathoffiletoedittarget = preg_replace(
'/\.sql$/',
'.key.sql', $pathoffiletoedittarget);
444 $pathoffiletoedittarget = preg_replace(
'/\.sql.new$/',
'.key.sql.new', $pathoffiletoedittarget);
446 $contentsqlfile = file_get_contents(
dol_osencode($pathoffiletoeditsrc));
449 $texttoinsert =
'-- BEGIN MODULEBUILDER INDEXES'.
"\n";
451 foreach (
$object->fields as $key => $val) {
453 if (!empty($val[
'index'])) {
455 $texttoinsert .=
"ALTER TABLE llx_".dol_strtolower(
$module).
'_'.
dol_strtolower($objectname).
" ADD ".($key ==
'ref' ?
"UNIQUE INDEX " :
"INDEX ").$indexname.
" (".$key.($key ==
'ref' && array_key_exists(
'entity',
$object->fields) ?
", entity" :
"").
");";
456 $texttoinsert .=
"\n";
458 if (!empty($val[
'foreignkey'])) {
459 $tmp = explode(
'.', $val[
'foreignkey']);
460 if (!empty($tmp[0]) && !empty($tmp[1])) {
462 $texttoinsert .=
"ALTER TABLE llx_".dol_strtolower(
$module).
'_'.
dol_strtolower($objectname).
" ADD CONSTRAINT ".$constraintname.
" FOREIGN KEY (".$key.
") REFERENCES llx_".preg_replace(
'/^llx_/',
'', $tmp[0]).
"(".$tmp[1].
");";
463 $texttoinsert .=
"\n";
468 $texttoinsert .=
'-- END MODULEBUILDER INDEXES';
470 $contentsqlfile = preg_replace(
'/-- BEGIN MODULEBUILDER INDEXES.*END MODULEBUILDER INDEXES/ims', $texttoinsert, $contentsqlfile);
472 dol_mkdir(dirname($pathoffiletoedittarget));
474 $result2 = file_put_contents($pathoffiletoedittarget, $contentsqlfile);
476 dolChmod($pathoffiletoedittarget, $newmask);
479 setEventMessages($langs->trans(
"ErrorFailToCreateFile", $pathoffiletoedittarget),
null,
'errors');
482 return $error ? -1 : 1;
494 $listofobject =
dol_dir_list($destdir.
'/class',
'files', 0,
'\.class\.php$');
495 foreach ($listofobject as $fileobj) {
496 if (preg_match(
'/^api_/', $fileobj[
'name'])) {
499 if (preg_match(
'/^actions_/', $fileobj[
'name'])) {
503 $tmpcontent = file_get_contents($fileobj[
'fullname']);
505 if (preg_match(
'/class\s+([^\s]*)\s+extends\s+CommonObject/ims', $tmpcontent, $reg)) {
506 $objectnameloop = $reg[1];
507 $objects[$fileobj[
'fullname']] = $objectnameloop;
510 if (count($objects) > 0) {
526 if (!file_exists($file)) {
530 $content = file_get_contents($file);
533 if (strpos($content,
'/* BEGIN MODULEBUILDER TOPMENU MYOBJECT */') !==
false
534 || strpos($content,
'/* BEGIN MODULEBUILDER TOPMENU */') !==
false) {
537 if (strpos($content,
'/* END MODULEBUILDER TOPMENU MYOBJECT */') !==
false
538 || strpos($content,
'/* END MODULEBUILDER TOPMENU */') !==
false) {
541 if (strpos($content,
'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */') !==
false) {
544 if (strpos($content,
'/* END MODULEBUILDER LEFTMENU MYOBJECT */') !==
false) {
551 } elseif ($number === 1) {
552 if (strpos($content,
'/* BEGIN MODULEBUILDER PERMISSIONS */') !==
false && strpos($content,
'/* END MODULEBUILDER PERMISSIONS */') !==
false) {
555 } elseif ($number == 2) {
556 if (strpos($content,
'/* BEGIN MODULEBUILDER DICTIONARIES */') !==
false && strpos($content,
'/* END MODULEBUILDER DICTIONARIES */') !==
false) {
570 require_once DOL_DOCUMENT_ROOT.
'/modulebuilder/class/PermissionsBlock.class.php';
574 }
catch (\RuntimeException $e) {
575 dol_syslog(
'deletePerms '.$e->getMessage(), LOG_WARNING);
579 return $block->write(
'') < 0 ? -1 : 1;
600 require_once DOL_DOCUMENT_ROOT.
'/modulebuilder/class/RightsSyncService.class.php';
603 $objectname = (string) $objectname;
604 $permissions = is_array($permissions) ? $permissions : array();
605 $right = is_array($right) ? $right : array();
610 $module = (string) preg_replace(
'/^mod|\.class\.php$/',
'', basename($file));
614 switch ((
int) $action) {
626 (
string) ($right[4] ??
''),
627 (
string) ($right[1] ??
''),
628 (
string) ($right[5] ??
'')
637 (
string) ($right[4] ??
''),
638 (
string) ($right[1] ??
''),
639 (
string) ($right[5] ??
'')
646 dol_syslog(
'reWriteAllPermissions got an unknown action: '.$action, LOG_WARNING);
649 }
catch (\InvalidArgumentException $e) {
650 dol_syslog(
'reWriteAllPermissions '.$e->getMessage(), LOG_WARNING);
657 if ($report->skipped > 0) {
661 return $report->toLegacyReturnCode();
672 $string = str_replace(
"'",
'', $string);
675 preg_match_all(
'/\s*([^\s=>]+)\s*=>\s*([^,]+),?/', $string, $matches, PREG_SET_ORDER);
676 $propertyArray = array();
678 foreach ($matches as $match) {
679 $key = trim($match[1]);
680 $value = trim($match[2]);
682 if (strpos($value,
'array(') === 0) {
685 $value = $nestedArray;
686 } elseif (strpos($value,
'"Id")') !==
false) {
687 $value = str_replace(
')',
'', $value);
689 if (is_numeric($value)) {
690 if (strpos($value,
'.') !==
false) {
691 $value = (float) $value;
693 $value = (int) $value;
696 if ($value ===
'true') {
698 } elseif ($value ===
'false') {
703 $propertyArray[$key] = $value;
706 return $propertyArray;
720 $attributesUnique = array(
'type',
'label',
'enabled',
'position',
'notnull',
'visible',
'noteditable',
'index',
'default' ,
'foreignkey',
'arrayofkeyval',
'alwayseditable',
'validate',
'searchall',
'comment',
'isameasure',
'css',
'cssview',
'csslist',
'help',
'showoncombobox',
'picto' );
722 $start =
"public \$fields = array(";
726 $lines = file($file);
728 foreach ($lines as $i => $line) {
729 if (strpos($line, $start) !==
false) {
731 while (isset($lines[++$i])) {
733 if (strpos($line, $end) !==
false) {
742 $table =
"== DATA SPECIFICATIONS\n";
743 $table .=
"=== Table of fields with properties for object *$objectname* : \n";
744 $table .=
"[options='header',grid=rows,frame=topbot,width=100%,caption=Organisation]\n";
748 foreach ($attributesUnique as $attUnique) {
749 $table .=
"|".$attUnique;
752 $valuesModif = array();
753 foreach ($keys as $string) {
754 $string = trim($string,
"'");
755 $string = rtrim($string,
",");
761 foreach ($array as $key => $value) {
762 if (is_array($value)) {
766 $array[$code][$key] = $value;
771 if (!is_array($array)) {
774 $field = array_keys($array);
775 if ($field[0] ===
'') {
778 $values = array_values($array)[0];
781 foreach ($attributesUnique as $attUnique) {
782 if ($attUnique ==
'type' && $field[0] ===
'label') {
783 $values[$attUnique] =
'varchar(255)';
785 if (!array_key_exists($attUnique, $values)) {
786 $valuesModif[$attUnique] =
'';
788 $valuesModif[$attUnique] = $values[$attUnique];
791 $table .=
"|*" . $field[0] .
"*|";
792 $table .= implode(
"|", $valuesModif) .
"\n";
797 $table .=
"__ end table for object $objectname\n";
800 $writeInFile =
dolReplaceInFile($destfile, array(
'== DATA SPECIFICATIONS' => $table));
801 if ($writeInFile < 0) {
818 $start =
"== Table of fields and their properties for object *".dol_ucfirst($objectname).
"* : ";
819 $end =
"__ end table for object ".dol_ucfirst($objectname);
821 $str = file_get_contents($file);
823 $search =
'/' . preg_quote($start,
'/') .
'(.*?)' . preg_quote($end,
'/') .
'/s';
824 $new_contents = preg_replace($search,
'', $str);
825 file_put_contents($file, $new_contents);
829 $perms =
"|*".dol_strtolower($objectname).
"*|";
830 $search_pattern_perms =
'/' . preg_quote($perms,
'/') .
'.*?\n/';
831 $new_contents = preg_replace($search_pattern_perms,
'', $new_contents);
832 file_put_contents($file, $new_contents);
849function getFromFile($file, $start, $end, $excludestart =
'', $includese = 0)
858 while ($line = fgets($fhandle)) {
859 if (strpos($line, $start) !==
false && (empty($excludestart) || strpos($line, $excludestart) ===
false)) {
864 while (($line = fgets($fhandle)) !==
false) {
865 if (strpos($line, $end) !==
false) {
879 $content = implode(
"", $keys);
893 $start =
'/* BEGIN MODULEBUILDER PERMISSIONS */';
894 $end =
'/* END MODULEBUILDER PERMISSIONS */';
896 if (empty($content)) {
900 $string =
"[options='header',grid=rows,width=60%,caption=Organisation]\n";
903 $header = array($langs->trans(
'Objects'),$langs->trans(
'Permission'));
904 foreach ($header as $h) {
909 $array = explode(
";", $content);
910 $permissions = array_filter($array);
912 $permissions = str_replace(
'$r++',
'1', $permissions);
915 foreach ($permissions as $i => $element) {
917 unset($permissions[$i]);
919 if (str_contains($element,
'$this->numero')) {
920 unset($permissions[$i]);
922 if (str_contains($element,
'$this->rights[$r][5]')) {
923 unset($permissions[$i]);
927 foreach ($permissions as $key => $element) {
928 $element = str_replace(
" '",
'', $element);
929 $element = trim($element,
"'");
930 $permsN[] =
dol_substr($element, strpos($element,
"=") + 1);
935 $final_array = array();
937 while ($index < count($permsN)) {
938 $temp_array = array($permsN[$index], $permsN[$index + 1]);
939 $final_array[] = $temp_array;
944 foreach ($final_array as $subarray) {
948 $result[$key][] = $subarray;
950 foreach ($result as $i => $pems) {
951 $string .=
"|*".$i.
"*|";
952 foreach ($pems as $tab) {
953 $string .= $tab[0].
" , ";
958 $string .=
"\n|===\n";
960 $write =
dolReplaceInFile($destfile, array(
'__DATA_PERMISSIONS__' => $string));
978 global $langs, $user;
980 if (!file_exists($file)) {
985 $content = file($file);
987 $includeClass =
"dol_include_once\(\'\/\w+\/class\/\w+\.class\.php\'\);";
988 $props =
'public\s+\$\w+;';
989 $varcommented =
'@var\s+\w+\s+\$\w+\s+{@type\s+\w+}';
990 $constructObj =
'\$this->\w+\s+=\s+new\s+\w+\(\$this->db\);';
993 foreach ($content as $lineNumber => &$lineContent) {
994 if (preg_match(
'/'.$varcommented.
'/', $lineContent)) {
996 foreach ($objects as $objectname) {
997 $lineContent .=
"\t * @var ".$objectname.
" \$".
dol_strtolower($objectname).
" {@type ".$objectname.
"}". PHP_EOL;
1000 } elseif (preg_match(
'/'.$props.
'/', $lineContent)) {
1002 foreach ($objects as $objectname) {
1003 $lineContent .=
"\t/*".PHP_EOL.
"\t * @var mixed TODO: set type".PHP_EOL.
"\t */".PHP_EOL.
"\tpublic \$".
dol_strtolower($objectname).
";". PHP_EOL;
1005 } elseif (preg_match(
'/'.$constructObj.
'/', $lineContent)) {
1007 foreach ($objects as $objectname) {
1008 $lineContent .=
"\t\t\$this->".dol_strtolower($objectname).
" = new ".$objectname.
"(\$this->db);". PHP_EOL;
1010 } elseif (preg_match(
'/'.$includeClass.
'/', $lineContent)) {
1012 foreach ($objects as $objectname) {
1013 $lineContent .=
"dol_include_once('/".dol_strtolower($modulename).
"/class/".
dol_strtolower($objectname).
".class.php');". PHP_EOL;
1018 $allContent = implode(
"", $content);
1019 file_put_contents($file, $allContent);
1023 $allContent =
getFromFile($srcfile,
'/* BEGIN MODULEBUILDER API MYOBJECT */',
'/* END MODULEBUILDER API MYOBJECT */');
1024 foreach ($objects as $objectname) {
1026 dol_syslog(
'addObjectsToApiFile: skipping object "' . $objectname .
'" — name collides with module "' . $modulename .
'"', LOG_WARNING);
1031 'htdocs/modulebuilder/template' => $nc->moduleNameLower,
1032 '---Replace with your own copyright and developer email---' =>
dol_print_date($now,
'%Y') .
' ' . $user->getFullName($langs) . ($user->email ?
' <' . $user->email .
'>' :
''),
1034 $fullMap = array_merge($nc->getSubstitutionMap(), $extraMap);
1035 $contentReplaced = str_replace(array_keys($fullMap), array_values($fullMap), $allContent);
1038 '/* BEGIN MODULEBUILDER API MYOBJECT */' =>
'/* BEGIN MODULEBUILDER API '.
dol_strtoupper($objectname).
' */'.$contentReplaced.
"\t".
'/* END MODULEBUILDER API '.dol_strtoupper($objectname).
' */'.
"\n\n\n\t".
'/* BEGIN MODULEBUILDER API MYOBJECT */'
1059 if (!file_exists($file)) {
1063 $content = file($file);
1065 $includeClass =
"dol_include_once\(\'\/\w+\/class\/".dol_strtolower($objectname).
"\.class\.php\'\);";
1066 $props =
'public\s+\$'.dol_strtolower($objectname);
1067 $varcommented =
'@var\s+\w+\s+\$'.dol_strtolower($objectname).
'\s+{@type\s+\w+}';
1068 $constructObj =
'\$this->'.dol_strtolower($objectname).
'\s+=\s+new\s+\w+\(\$this->db\);';
1071 foreach ($content as $lineNumber => &$lineContent) {
1072 if (preg_match(
'/'.$varcommented.
'/i', $lineContent)) {
1074 } elseif (preg_match(
'/'.$props.
'/i', $lineContent)) {
1076 } elseif (preg_match(
'/'.$constructObj.
'/i', $lineContent)) {
1078 } elseif (preg_match(
'/'.$includeClass.
'/i', $lineContent)) {
1083 $allContent = implode(
"", $content);
1084 file_put_contents($file, $allContent);
1088 $begin =
'/* BEGIN MODULEBUILDER API '.dol_strtoupper($objectname).
' */';
1089 $end =
'/* END MODULEBUILDER API '.dol_strtoupper($objectname).
' */';
1112 if (!file_exists($file)) {
1116 if ($action == 0 && !empty($key)) {
1118 array_splice($menus, array_search($menus[$key], $menus), 1);
1119 } elseif ($action == 1) {
1121 array_push($menus, $menuWantTo);
1122 } elseif ($action == 2 && !empty($key) && !empty($menuWantTo)) {
1126 foreach ($menus as $index => $menu) {
1127 if ($index !== $key) {
1128 if ($menu[
'type'] === $menuWantTo[
'type']) {
1129 if (strcasecmp(str_replace(
' ',
'', $menu[
'titre']), str_replace(
' ',
'', $menuWantTo[
'titre'])) === 0) {
1132 if (strcasecmp(str_replace(
' ',
'', $menu[
'url']), str_replace(
' ',
'', $menuWantTo[
'url'])) === 0) {
1138 if (!$counter && $urlCounter < 2) {
1139 $menus[$key] = $menuWantTo;
1143 } elseif ($action == -1 && !empty($menuWantTo) && is_string($menuWantTo)) {
1145 foreach ($menus as $index => $menu) {
1147 array_splice($menus, array_search($menu, $menus), 1);
1155 $beginMenu =
'/* BEGIN MODULEBUILDER LEFTMENU';
1156 $excludeBeginMenu =
'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT';
1157 $endMenu =
'/* END MODULEBUILDER LEFTMENU';
1159 while ($protection <= 1000 && $allMenus =
getFromFile($file, $beginMenu, $endMenu, $excludeBeginMenu, 1)) {
1166 foreach ($menus as $index => $menu) {
1167 $menu[
'position'] =
"1000 + \$r";
1168 if ($menu[
'type'] ===
'left') {
1169 $start =
"\t\t".
'/* BEGIN MODULEBUILDER LEFTMENU '.
dol_strtoupper(empty($menu[
'object']) ? $menu[
'titre'] : $menu[
'object']).
' */';
1170 $end =
"\t\t".
'/* END MODULEBUILDER LEFTMENU '.
dol_strtoupper(empty($menu[
'object']) ? $menu[
'titre'] : $menu[
'object']).
' */';
1172 $val_actuel = $menu;
1173 $next_val = empty($menus[$index + 1]) ? null : $menus[$index + 1];
1176 $str_menu .= $start.
"\n";
1177 $str_menu .=
"\t\t\$this->menu[\$r++] = array(\n";
1178 $str_menu .=
"\t\t\t'fk_menu' => '".dol_escape_php($menu[
'fk_menu'], 1).
"',\n";
1179 $str_menu .=
"\t\t\t'type' => '".dol_escape_php($menu[
'type'], 1).
"',\n";
1180 $str_menu .=
"\t\t\t'titre' => '".dol_escape_php($menu[
'titre'], 1).
"',\n";
1181 $str_menu .=
"\t\t\t'mainmenu' => '".dol_escape_php($menu[
'mainmenu'], 1).
"',\n";
1182 $str_menu .=
"\t\t\t'leftmenu' => '".dol_escape_php($menu[
'leftmenu'], 1).
"',\n";
1183 $str_menu .=
"\t\t\t'url' => '".dol_escape_php($menu[
'url'], 1).
"',\n";
1184 $str_menu .=
"\t\t\t'langs' => '".dol_escape_php($menu[
'langs'], 1).
"',\n";
1185 $str_menu .=
"\t\t\t'position' => ".((int) $menu[
'position']).
",\n";
1186 $str_menu .=
"\t\t\t'enabled' => '".dol_escape_php((
string) $menu[
'enabled'], 1).
"',\n";
1187 $str_menu .=
"\t\t\t'perms' => '".dol_escape_php($menu[
'perms'], 1).
"',\n";
1188 $str_menu .=
"\t\t\t'target' => '".dol_escape_php($menu[
'target'], 1).
"',\n";
1189 $str_menu .=
"\t\t\t'user' => ".((int) $menu[
'user']).
",\n";
1190 $str_menu .=
"\t\t\t'object' => '".dol_escape_php($menu[
'object'], 1).
"',\n";
1191 $str_menu .=
"\t\t);\n";
1193 if (is_null($next_val) || $val_actuel[
'leftmenu'] !== $next_val[
'leftmenu']) {
1194 $str_menu .= $end.
"\n";
1199 dolReplaceInFile($file, array(
'/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */' => $str_menu.
"\n\t\t/* BEGIN MODULEBUILDER LEFTMENU MYOBJECT */"));
1216 $dicData =
"\t\t\$this->dictionaries = array(\n";
1218 foreach ($dicts as $key => $value) {
1219 if (empty($value)) {
1221 $dicData =
"\t\t\$this->dictionaries = array();";
1225 $dicData .=
"\t\t\t'$key' => ";
1227 if ($key ===
'tabcond') {
1228 $conditions = array_map(
1233 static function ($val) use (
$module) {
1234 return is_bool($val) ?
"isModEnabled('$module')" : $val;
1238 $dicData .=
"array(" . implode(
", ", $conditions) .
")";
1239 } elseif ($key ===
'tabhelp') {
1240 $helpItems = array();
1241 foreach ($value as $helpValue) {
1242 $helpItems[] =
"array('code' => \$langs->trans('".$helpValue[
'code'].
"'), 'field2' => 'field2tooltip')";
1244 $dicData .=
"array(" . implode(
",", $helpItems) .
")";
1246 if (is_array($value)) {
1247 $dicData .=
"array(" . implode(
1254 static function ($val) {
1261 $dicData .=
"'$value'";
1266 $dicData .= (!$isEmpty ?
"\t\t);" :
'');
1268 $stringDic =
getFromFile($file,
'/* BEGIN MODULEBUILDER DICTIONARIES */',
'/* END MODULEBUILDER DICTIONARIES */');
1269 $writeInfile =
dolReplaceInFile($file, array($stringDic => $dicData.
"\n"));
1271 return $writeInfile;
1290 if (empty($namedic)) {
1291 setEventMessages($langs->trans(
"ErrorEmptyNameDic"),
null,
'errors');
1294 if (!file_exists($file)) {
1299 if (empty($dictionnaires)) {
1300 $dictionnaires = array(
'langs' =>
'',
'tabname' => array(),
'tablib' => array(),
'tabsql' => array(),
'tabsqlsort' => array(),
'tabfield' => array(),
'tabfieldvalue' => array(),
'tabfieldinsert' => array(),
'tabrowid' => array(),
'tabcond' => array(),
'tabhelp' => array());
1304 'rowid' => array(
'type' =>
'integer',
'value' => 11,
'extra' =>
'AUTO_INCREMENT'),
1305 'code' => array(
'type' =>
'varchar',
'value' => 255,
'null' =>
'NOT NULL'),
1306 'label' => array(
'type' =>
'varchar',
'value' => 255,
'null' =>
'NOT NULL'),
1307 'position' => array(
'type' =>
'integer',
'value' => 11,
'null' =>
'NULL'),
1308 'use_default' => array(
'type' =>
'varchar',
'value' => 11,
'default' =>
'1'),
1309 'active' => array(
'type' =>
'integer',
'value' => 3)
1312 $primaryKey =
'rowid';
1313 foreach ($columns as $key => $value) {
1314 if ($key ===
'rowid') {
1315 $primaryKey =
'rowid';
1318 if (!array_key_exists(
'rowid', $columns)) {
1319 $primaryKey = array_key_first($columns);
1325 $checkTable = $db->DDLDescTable(MAIN_DB_PREFIX.dol_strtolower($namedic));
1326 if ($checkTable && $db->num_rows($checkTable) > 0) {
1327 setEventMessages($langs->trans(
"ErrorTableExist", $namedic),
null,
'errors');
1330 $_results = $db->DDLCreateTable(MAIN_DB_PREFIX.dol_strtolower($namedic), $columns, $primaryKey,
"");
1331 if ($_results < 0) {
1332 dol_print_error($db);
1333 $langs->load(
"errors");
1334 setEventMessages($langs->trans(
"ErrorTableNotFound", $namedic),
null,
'errors');
1339 $dictionnaires[
'langs'] = $modulename.
'@'.$modulename;
1342 $dictionnaires[
'tabsql'][] =
'SELECT t.rowid as rowid, t.code, t.label, t.active FROM '.MAIN_DB_PREFIX.dol_strtolower($namedic).
' as t';
1343 $dictionnaires[
'tabsqlsort'][] = (array_key_exists(
'label', $columns) ?
'label ASC' :
'');
1344 $dictionnaires[
'tabfield'][] = (array_key_exists(
'code', $columns) && array_key_exists(
'label', $columns) ?
'code,label' :
'');
1345 $dictionnaires[
'tabfieldvalue'][] = (array_key_exists(
'code', $columns) && array_key_exists(
'label', $columns) ?
'code,label' :
'');
1346 $dictionnaires[
'tabfieldinsert'][] = (array_key_exists(
'code', $columns) && array_key_exists(
'label', $columns) ?
'code,label' :
'');
1347 $dictionnaires[
'tabrowid'][] = $primaryKey;
1348 $dictionnaires[
'tabcond'][] =
isModEnabled(
'$modulename');
1349 $dictionnaires[
'tabhelp'][] = (array_key_exists(
'code', $columns) ? array(
'code' => $langs->trans(
'CodeTooltipHelp'),
'field2' =>
'field2tooltip') :
'');
1353 if ($writeInfile > 0) {
1373 $string =
getFromFile($file_api,
'/*begin methods CRUD*/',
'/*end methods CRUD*/');
1374 $extractUrls = explode(
"\n", $string);
1377 $urlValues = array();
1378 foreach ($extractUrls as $key => $line) {
1379 $lineWithoutTabsSpaces = preg_replace(
'/^[\t\s]+/',
'', $line);
1380 if (strpos($lineWithoutTabsSpaces,
'* @url') === 0) {
1382 $urlValues[] = $urlValue;
1387 $str = $_SERVER[
'HTTP_HOST'].
'/api/index.php/';
1388 $groupedUrls = array();
1389 foreach ($urlValues as $url) {
1390 if (preg_match(
'/(?:GET|POST|PUT|DELETE) (\w+)s/', $url, $matches)) {
1391 $objectName = $matches[1];
1392 $url = $str.trim(strstr($url,
' '));
1393 $groupedUrls[$objectName][] = $url;
1396 if (empty($groupedUrls)) {
1402 $asciiDocTable =
"[options=\"header\"]\n|===\n|Object | URLs\n";
1403 foreach ($groupedUrls as $objectName => $urls) {
1404 $urlsList = implode(
" +\n*", $urls);
1405 $asciiDocTable .=
"|$objectName | \n*$urlsList +\n";
1407 $asciiDocTable .=
"|===\n";
1408 $file_write =
dolReplaceInFile($file_doc, array(
'__API_DOC__' =>
'__API_DOC__'.
"\n".$asciiDocTable));
1409 if ($file_write < 0) {
1430 $allFilesAndDirs = scandir($path);
1433 foreach ($allFilesAndDirs as $item) {
1434 if ($item !=
'.' && $item !=
'..') {
1435 if ($type == 1 &&
dol_is_file($path . DIRECTORY_SEPARATOR . $item) && strpos($item,
'.back') ===
false) {
1437 } elseif ($type == 2 &&
dol_is_dir($path . DIRECTORY_SEPARATOR . $item)) {
1455 'contact' => array(
'file' =>
'myobject_contact.php',
'var' =>
'showtabofpagecontact',
'marker' =>
'CONTACT',
'label' =>
'Contacts'),
1456 'note' => array(
'file' =>
'myobject_note.php',
'var' =>
'showtabofpagenote',
'marker' =>
'NOTE',
'label' =>
'Notes'),
1457 'document' => array(
'file' =>
'myobject_document.php',
'var' =>
'showtabofpagedocument',
'marker' =>
'DOCUMENT',
'label' =>
'Documents'),
1458 'agenda' => array(
'file' =>
'myobject_agenda.php',
'var' =>
'showtabofpageagenda',
'marker' =>
'AGENDA',
'label' =>
'Events'),
1476 'sendmail' => array(
'marker' =>
'SENDMAIL',
'label' =>
'SendMail',
'default' => 1,
'mode' =>
'remove'),
1477 'clone' => array(
'marker' =>
'CLONE',
'label' =>
'ToClone',
'default' => 1,
'mode' =>
'remove'),
1478 'validate' => array(
'marker' =>
'VALIDATE',
'label' =>
'Validate',
'default' => 1,
'mode' =>
'remove'),
1479 'setdraft' => array(
'marker' =>
'SETDRAFT',
'label' =>
'SetToDraft',
'default' => 1,
'mode' =>
'remove'),
1480 'statuschange' => array(
'marker' =>
'STATUSCHANGE',
'label' =>
'CancelAndReopen',
'default' => 0,
'mode' =>
'activate'),
1481 'delete' => array(
'marker' =>
'DELETE',
'label' =>
'Delete',
'default' => 1,
'mode' =>
'remove'),
1494 $defaults = array();
1495 foreach ($map as $key => $meta) {
1496 if (!isset($meta[
'default']) || !empty($meta[
'default'])) {
1513 $quotedmarker = preg_quote($marker,
'/');
1515 return '/\h*\/\/ BEGIN MODULEBUILDER ACTION '.$quotedmarker.
'.*?\/\/ END MODULEBUILDER ACTION '.$quotedmarker.
'\h*\R(?:\h*\R)?/s';
1527 $quotedmarker = preg_quote($marker,
'/');
1530 '/\h*\/\* BEGIN COMMENTED '.$quotedmarker.
'\h*\R/',
1531 '/\h*END COMMENTED '.$quotedmarker.
'\h*\*\/\h*\R/',
1545 return '/\/\/BEGIN MODULEBUILDER LINES.*?\/\/END MODULEBUILDER LINES\s*/s';
1559 if (!is_array($requested) || empty($requested)) {
1562 foreach (array_keys($map) as $key) {
1563 if (in_array($key, $requested,
true)) {
1595 if (!file_exists($file)) {
1598 $content = file_get_contents($file);
1599 if ($content ===
false) {
1604 $foundmarkers = array();
1605 preg_match_all(
'/\/\*\s*(?:BEGIN|END) MODULEBUILDER [^*]*\*\//', $content, $foundmarkers);
1606 $sentinels = array();
1607 foreach (array_values(array_unique($foundmarkers[0])) as $index => $marker) {
1608 $key =
"\0MODULEBUILDERMARKER".$index.
"\0";
1609 $sentinels[$key] = $marker;
1610 $content = str_replace($marker, $key, $content);
1613 $content = str_replace(array_keys($arrayreplacement), array_values($arrayreplacement), $content);
1616 if (!empty($sentinels)) {
1617 $content = strtr($content, $sentinels);
1620 if (file_put_contents($file, $content) ===
false) {
1633 $pages = array(
'myobject_card.php',
'myobject_list.php');
1635 $pages[] = $tabinfo[
'file'];
1649 return '/^\h*\/\/ BEGIN MODULEBUILDER ACCESSPOLICY\h*\R(.*?)^\h*\/\/ END MODULEBUILDER ACCESSPOLICY\h*\R/ms';
1661 $block =
"// Access policy defined with ModuleBuilder, see MyObject::\$accesspolicy\n";
1662 $block .=
"try {\n";
1663 $block .=
"\t\$permissiontoread = ".$policy->getExpression()->toPhp().
";\n";
1664 $block .=
"} catch (Throwable \$e) {\n";
1665 $block .=
"\tdol_syslog(__FILE__.': access policy evaluation failed, access denied: '.\$e->getMessage(), LOG_ERR);\n";
1666 $block .=
"\t\$permissiontoread = false;\n";
1670 $block .=
"if (!\$permissiontoread) {\n";
1671 $block .=
"\taccessforbidden('".$policy->getMessage().
"');\n";
1686 $property .=
"\t/**\n";
1687 $property .=
"\t * @var string Access policy of the object pages, serialized by ModuleBuilder (see AccessPolicyConfig)\n";
1688 $property .=
"\t */\n";
1689 $property .=
"\tpublic \$accesspolicy = ".var_export($policy->
toJson(),
true).
";\n";
1702 $content = file_exists($file) ? file_get_contents($file) :
false;
1703 if ($content ===
false) {
1704 throw new \InvalidArgumentException(
'Unable to read the object class '.$file);
1708 $nbpolicies = preg_match_all(
'/^\h*public \$accesspolicy = \'((?:[^\'\\\\]|\\\\.)*)\';\h*$/m', $content, $matches);
1709 if (empty($nbpolicies)) {
1712 if ($nbpolicies > 1) {
1713 throw new \InvalidArgumentException(
'The object class '.$file.
' stores several access policies');
1728 $content = file_exists($file) ? file_get_contents($file) :
false;
1729 if ($content ===
false) {
1730 dol_syslog(__FUNCTION__.
": unable to read ".$file, LOG_ERR);
1735 $nbblocks = preg_match_all($pattern, $content);
1736 if ($nbblocks !== 1) {
1737 dol_syslog(__FUNCTION__.
": expected one ACCESSPOLICY block in ".$file.
", found ".((
int) $nbblocks), LOG_ERR);
1741 $updated = preg_replace_callback(
1747 static function ($matches) use ($replacement) {
1748 return ($replacement ===
null) ? $matches[1] : $replacement;
1752 if ($updated ===
null || file_put_contents($file, $updated) ===
false) {
1753 dol_syslog(__FUNCTION__.
": unable to write ".$file, LOG_ERR);
if(! $sortfield) if(! $sortorder) $object
Immutable access policy of the pages generated by ModuleBuilder: a rule tree and a deny message.
static fromJson(string $json)
Load a serialized policy, as produced by toJson().
toJson()
Serialize the policy.
Syncs rights straight into the mod<Module>.class.php descriptor file.
Immutable value object holding all case variants of a module/object pair.
static fromFile(string $file)
Read a descriptor and locate its permissions block.
static forObjectDeletion(string $module, string $descriptorFile, array $permissions, string $objectName)
Drop every right attached to an object being deleted.
static forRightDeletion(string $module, string $descriptorFile, array $permissions, int $rightKey)
Remove one right, addressed by its index in the rights array.
static forRightUpdate(string $module, string $descriptorFile, array $permissions, int $rightKey, string $objectName, string $label, string $crud)
Replace one right, addressed by its index in the rights array.
static forRightAddition(string $module, string $descriptorFile, array $permissions, string $objectName, string $label, string $crud)
Append one right to the descriptor.
static forObjectCreation(string $module, string $descriptorFile, array $permissions, string $objectName)
Declare the three CRUD rights of a newly generated object.
if(! $sortfield) if(! $sortorder) $module
dol_copy($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=0)
Copy a file to another file.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_is_dir($folder)
Test if filename is a directory.
dolReplaceInFile($srcfile, $arrayreplacement, $destfile='', $newmask='0', $indexdatabase=0, $arrayreplacementisregex=0)
Make replacement of strings into a file.
dol_now($mode='gmt')
Return date for now.
dol_ucfirst($string, $encoding="UTF-8")
Convert first character of the first word of a string to upper.
dol_strtolower($string, $encoding="UTF-8")
Convert a string to lower.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dolChmod($filepath, $newmask='')
Change mod of a file.
dol_escape_php($stringtoescape, $stringforquotes=2)
Returns text escaped for inclusion into a php string, build with double quotes " or '.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
dol_strtoupper($string, $encoding="UTF-8")
Convert a string to upper.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
getModuleBuilderDefaultEnabledKeys($map)
Return the keys enabled by default in a ModuleBuilder generation map.
updateDictionaryInFile($module, $file, $dicts)
Updates a dictionary in a module descriptor file.
deletePropsAndPermsFromDoc($file, $objectname)
Delete property and permissions from documentation ascii file if we delete an object.
filterEnabledTabs($requested, $map)
Filter a list of requested tab keys against the known optional tabs map.
applyModuleBuilderAccessPolicyToPage(string $file, ?AccessPolicyConfig $policy)
Apply an access policy to a generated object page.
applyModuleBuilderAccessPolicyToClass(string $file, ?AccessPolicyConfig $policy)
Store an access policy in the generated object class.
getModuleBuilderCardActionUncommentPatterns($marker)
Build the regular expressions removing the comment fence of a card action generated in 'activate' mod...
getModuleBuilderAccessPolicyFromClassFile(string $file)
Load the access policy stored in a generated object class by renderModuleBuilderAccessPolicyProperty(...
createNewDictionnary($modulename, $file, $namedic, $dictionnaires=null)
Create a new dictionary table.
filterEnabledKeys($requested, $map)
Filter a list of requested keys against a known map of generable elements.
countItemsInDirectory($path, $type=1)
count directories or files in modulebuilder folder
getModuleBuilderCardActionBlockPattern($marker)
Build the regular expression matching every block of a card action in the object card template.
writePermsInAsciiDoc($file, $destfile)
Write all permissions of each object in AsciiDoc format.
reWriteAllMenus($file, $menus, $menuWantTo, $key, $action)
parsePropertyString($string)
Converts a formatted properties string into an associative array.
renderModuleBuilderAccessPolicyBlock(AccessPolicyConfig $policy)
Render the block that computes $permissiontoread from an access policy in a generated page.
rebuildObjectSql($destdir, $module, $objectname, $newmask, $readdir='', $object=null, $moduletype='external')
Save data into a memory area shared by all users, all sessions on server.
writeApiUrlsInDoc($file_api, $file_doc)
Generate Urls and add them to documentation module.
getFromFile($file, $start, $end, $excludestart='', $includese=0)
Search a string and return all lines needed from file.
dolGetListOfObjectClasses($destdir)
Get list of existing objects from a directory.
deletePerms($file)
Delete all permissions declared in the permissions section of a module descriptor.
getModuleBuilderLinesBlockPattern()
Return the regular expression matching a block of object lines code in the templates,...
writePropsInAsciiDoc($file, $objectname, $destfile)
Write all properties of the object in AsciiDoc format.
renderModuleBuilderAccessPolicyProperty(AccessPolicyConfig $policy)
Render the property of the generated object class that keeps the serialized access policy.
dolModuleBuilderSqlIdentifier(string $prefix, string $module, string $table, string $key)
Build the name of an index or of a foreign key constraint for a table generated by the module builder...
removeObjectFromApiFile($file, $objects, $objectname)
Remove Object variables and methods from API_Module File.
getModuleBuilderObjectCardActions()
Return the map of optional action buttons that can be generated on the card page of a ModuleBuilder o...
getModuleBuilderAccessPolicyPages()
Return the object pages whose read access is driven by the access policy defined in ModuleBuilder.
dolReplaceInFilePreservingModuleBuilderMarkers($file, $arrayreplacement)
Apply substitutions to a module descriptor file while preserving the MODULEBUILDER comment markers.
rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir='', $addfieldentry=array(), $delfieldentry='')
Regenerate files .class.php.
resolveModuleBuilderAccessPolicyBlock(string $file, ?string $replacement)
Resolve the ACCESSPOLICY block of a generated file.
reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $module, $action)
Rewriting all permissions after any actions.
checkExistComment($file, $number)
Function to check if comment BEGIN and END exists in modMyModule class.
getModuleBuilderAccessPolicyBlockPattern()
Return the regular expression matching the ACCESSPOLICY block of a template.
getModuleBuilderObjectTabs()
Return the map of optional tabs that can be generated for a ModuleBuilder object.
addObjectsToApiFile($srcfile, $file, $objects, $modulename)
Add Object in ModuleApi File.