Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
getsearchmethods.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Get search methods for a given attribute and family
8  */
9 
10 include_once ("FDL/Class.Doc.php");
11 
13 {
14  $res = array(
15  'error' => null,
16  'data' => array()
17  );
18 
19  $parms = array();
20  foreach (array(
21  'famid' => true,
22  'attrid' => true
23  ) as $p => $isRequired) {
24  $parms[$p] = GetHttpVars($p, '');
25  if ($parms[$p] == '' && $isRequired) {
26  $res['error'] = sprintf("Missing or empty parameter '%s'.", $p);
27  sendResponse($action, $res);
28  return;
29  }
30  }
31  /*
32  * @var DocFam $fam
33  */
34  $fam = new_Doc($action->dbaccess, $parms['famid'], true);
35  if ($parms['famid'] && (!$fam->isAlive())) {
36  $res['error'] = sprintf("Could not get family with id '%s'.", $parms['famid']);
37  sendResponse($action, $res);
38  return;
39  }
40 
41  $tmpDoc = createTmpDoc($action->dbaccess, $fam->id);
42  if (!$tmpDoc) {
43  $res['error'] = sprintf("Could not create temporary document from family '%s'.", $fam->name);
44  sendResponse($action, $res);
45  return;
46  }
47 
48  $attrId = $parms['attrid'];
49  if (isset(Doc::$infofields[$attrId])) {
50  $attrType = Doc::$infofields[$attrId]['type'];
51  } else {
52  $attr = $fam->getAttribute($parms['attrid']);
53  if (!is_object($attr)) {
54  $res['error'] = sprintf("Could not get attribute '%s' from family '%s'.", $parms['attrid'], $fam->name);
55  sendResponse($action, $res);
56  return;
57  }
58  $attrType = $attr->type;
59  if ($attr->format != '') {
60  // Recompose full attr spec: <attrType>("<format>")
61  $attrType = sprintf('%s("%s")', $attrType, $attr->format);
62  }
63  }
64 
65  $methods = $tmpDoc->getSearchMethods($attrId, $attrType);
66  $res['data'] = $methods;
67  sendResponse($action, $res);
68  return;
69 }
70 
71 function sendResponse($action, $response)
72 {
73  if (headers_sent($file, $line)) {
74  error_log(__METHOD__ . " " . sprintf("Oops... someone (%s:%s) already sent the headers!", $file, $line));
75  exit;
76  }
77  header('Content-Type: application/json');
78  $action->lay->template = json_encode($response);
79  $action->lay->noparse = true;
80 }
static $infofields
Definition: Class.Doc.php:105
global $action
sendResponse($action, $response)
$file
getsearchmethods(Action &$action)
$parms
switch($command) exit
Definition: checkVault.php:46
new_Doc($dbaccess, $id= '', $latest=false)
createTmpDoc($dbaccess, $fromid, $defaultvalue=true)
← centre documentaire © anakeen