Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
getenumitems.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Get Enum items in jsonD
8  *
9  * @author Anakeen
10  * @version $Id: editchangestate.php,v 1.8 2008/10/02 15:41:45 eric Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once "FDL/Class.Doc.php";
18 /**
19  * Get Enum Items
20  * @param Action &$action current action
21  * @global string $famid Http var : family id
22  * @global string $enumid Http var : enum id
23  */
25 {
26  $usage = new ActionUsage($action);
27  $usage->setDefinitionText("Return list of items for an enumerate attribute");
28  $famid = $usage->addRequiredParameter("famid", "Family identifier", function ($fid)
29  {
30  $fam = new_doc("", $fid);
31  if (!$fam->isAlive()) {
32  return sprintf("document \"%s\" not found", $fid);
33  } elseif ($fam->doctype != 'C') {
34  return sprintf("document \"%s\" is not a family", $fid);
35  }
36  return '';
37  });
38  $enumId = $usage->addRequiredParameter("enumid", "Enum identifier", function ($eid) use ($famid)
39  {
40  $fam = new_doc("", $famid);
41  $oa = $fam->getAttribute($eid);
42  if (!$oa) {
43  return sprintf("enumerate attribute \"%s\" not found", $eid);
44  } elseif ($oa->type != "enum") {
45  return sprintf("attribute \"%s\" is not an enum. Is is a \"%s\" ", $eid, $oa->type);
46  }
47  return '';
48  });
49  $out = array();
50 
51  try {
52  $usage->verify(true);
53  }
54  catch(\Dcp\ApiUsage\Exception $e) {
55  $err = $e->getDcpMessage();
56  $out = array(
57  "error" => $err
58  );
59  }
60 
61  if (empty($err)) {
62  $fam = new_doc("", $famid);
63  $oa = $fam->getAttribute($enumId);
64  $enums = DocEnum::getFamilyEnums($fam->id, $oa->id);
65 
66  $lang = getLocales();
67 
68  $items = array();
69 
70  foreach ($enums as $enum) {
71  $key = $enum["key"];
72  $items[$key] = array(
73  "key" => $key,
74  "label" => $enum["label"],
75  "parentKey" => $enum["parentkey"],
76  "disabled" => ($enum["disabled"] == "t") ,
77  "active" => ($enum["disabled"] != "t") ,
78  "order" => $enum["eorder"]
79  );
80  }
81  $localeConfig = array();
82  foreach ($lang as $klang => $locale) {
83  if (empty($locale["localeLabel"])) {
84  $locale["localeLabel"] = $locale["label"];
85  }
86  $localeConfig[] = array_merge($locale, array(
87  "id" => $klang,
88  "flag" => sprintf("Images/flags/%s.png", strtolower(substr($klang, -2)))
89  ));
90  setLanguage($klang);
91  foreach ($enums as $enum) {
92  $key = $enum["key"];
93  $lkey = sprintf("%s#%s#%s", $fam->name, $oa->id, $key);
94  $l10n = _($lkey);
95  if ($l10n == $lkey) {
96  $l10n = '';
97  }
98  $items[$enum["key"]]["locale"][] = array(
99  "lang" => $klang,
100  "label" => $l10n
101  );
102  }
103  }
104  setLanguage($action->getParam("CORE_LANG"));
105  $parentLabel = ''; // get parent label - not use direct parent label if the same
106  $label = $oa->getLabel();
107  if (!empty($oa->fieldSet)) {
108  $parentLabel = $oa->fieldSet->getLabel();
109  if ($parentLabel == $label) {
110  if (!empty($oa->fieldSet->fieldSet)) {
111  $parentLabel = $oa->fieldSet->fieldSet->getLabel();
112  } else {
113  $parentLabel = '';
114  }
115  }
116  }
117  $out = array(
118  "error" => '',
119  "familyName" => $fam->name,
120  "familyTitle" => $fam->getHtmlTitle() ,
121  "enumId" => $oa->id,
122  "enumLabel" => $oa->getLabel() ,
123  "parentLabel" => $parentLabel,
124  "items" => $items,
125  "localeConfig" => $localeConfig
126  );
127  }
128  $action->lay->template = json_encode($out);
129  $action->lay->noparse = true;
130  header('Content-type: application/json');
131 }
132 ?>
global $action
getenumitems(Action &$action)
$locale
$lang
Definition: lang.php:18
getLocales()
Definition: Lib.Common.php:870
setLanguage($lang)
Definition: Lib.Common.php:886
Verify arguments for action function.
static getFamilyEnums($famId, $attrid)
getParam($name, $def="")
if($file) if($subject==""&&$file) if($subject=="") $err
$usage
Verify arguments for wsh programs.
← centre documentaire © anakeen