17 include_once
"FDL/Class.Doc.php";
28 $usage->setDefinitionText(
"Return list of items for an enumerate attribute");
29 $famid =
$usage->addRequiredParameter(
"famid",
"Family identifier",
function ($fid)
31 $fam = new_doc(
"", $fid);
32 if (!$fam->isAlive()) {
33 return sprintf(
"document \"%s\" not found", $fid);
34 } elseif ($fam->doctype !=
'C') {
35 return sprintf(
"document \"%s\" is not a family", $fid);
39 $enumId =
$usage->addRequiredParameter(
"enumid",
"Enum identifier",
function ($eid) use (
$famid)
41 $fam = new_doc(
"",
$famid);
42 $oa = $fam->getAttribute($eid);
44 return sprintf(
"enumerate attribute \"%s\" not found", $eid);
45 } elseif ($oa->type !=
"enum") {
46 return sprintf(
"attribute \"%s\" is not an enum. Is is a \"%s\" ", $eid, $oa->type);
51 $modifications =
$usage->addRequiredParameter(
"items",
"Items modifications",
function ($items)
53 $dit = json_decode($items);
55 return sprintf(
"items \"%s\" must be json encoded structure", $items);
56 } elseif (!is_array($dit)) {
57 return sprintf(
"items \"%s\" must be json array", $items);
61 $usage->setStrictMode(
false);
67 $err = $e->getDcpMessage();
73 $fam = new_doc(
"",
$famid);
77 $oa = $fam->getAttribute($enumId);
80 $items = json_decode($modifications,
true);
81 foreach ($items as $item) {
82 if (empty($item[
"key"])) {
83 $err = sprintf(
"all keys must be not empty");
87 $enumKeys = array_keys($oa->getEnumLabel());
94 foreach ($items as $item) {
96 if (in_array($es->key, $enumKeys)) {
103 catch(\Dcp\Exception $e) {
104 $err = $e->getDcpMessage();
108 "familyName" => $fam->name,
114 $action->lay->template = json_encode(
$out);
115 $action->lay->noparse =
true;
116 header(
'Content-type: application/json');
static reloadLocaleCache()
static modifyEnum($famId, $attrid, EnumStructure $enumStruct)
static addEnum($famId, $attrid, EnumStructure $enumStruct)
modenumitems(Action &$action)
Verify arguments for action function.
static getFamilyEnums($famId, $attrid)
if($file) if($subject==""&&$file) if($subject=="") $err
Verify arguments for wsh programs.