Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
rnavigate.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Relation Navigation
8  *
9  * @author Anakeen
10  * @version $Id: rnavigate.php,v 1.7 2008/06/03 16:31:53 eric Exp $
11  * @package FDL
12  * @subpackage GED
13  */
14 /**
15  */
16 
17 include_once ("FDL/Lib.Dir.php");
18 
19 function rnavigate(Action & $action, $onlyGetResult = false)
20 {
21  $dbaccess = $action->dbaccess;
22 
23  $usage = new ActionUsage($action);
24  $docid = $usage->addRequiredParameter("id", "id of the current document");
25  $usage->setStrictMode(false);
26  $usage->verify(true);
27 
28  $action->parent->AddJsRef($action->GetParam("CORE_PUBURL") . "/FDL/Layout/common.js");
29  $action->parent->AddJsRef($action->GetParam("CORE_JSURL") . "/subwindow.js");
30  $limit = 100;
31 
33  if ($doc->locked == - 1) {
34  $doc = new_Doc($dbaccess, $doc->getLatestId());
35  }
36  $idocid = $doc->initid;
37 
38  $rdoc = new DocRel($dbaccess, $idocid);
39  $rdoc->sinitid = $idocid;
40 
41  $action->lay->set("Title", $doc->getHTMLTitle());
42 
43  $relationsFrom = array();
44  $relationsTo = array();
45 
46  $i18nFolder = _("folder");
47 
48  $trel = $rdoc->getIRelations("", "", $limit);
49  foreach ($trel as $currentResult) {
50  $relationsFrom[$currentResult["sinitid"]] = array(
51  "iconsrc" => $doc->getIcon($currentResult["sicon"]) ,
52  "initid" => $currentResult["sinitid"],
53  "title" => $currentResult["stitle"],
54  "url" => "?app=FDL&action=OPENDOC&mode=view&id=" . $currentResult["sinitid"],
55  "attributeId" => $currentResult["type"]
56  );
57  }
58 
59  $trel = $rdoc->getRelations("", "", $limit);
60  foreach ($trel as $currentResult) {
61  $relationsTo[$currentResult["cinitid"]] = array(
62  "iconsrc" => $doc->getIcon($currentResult["cicon"]) ,
63  "initid" => $currentResult["cinitid"],
64  "title" => $currentResult["ctitle"],
65  "url" => "?app=FDL&action=OPENDOC&mode=view&id=" . $currentResult["sinitid"],
66  "attributeId" => $currentResult["type"]
67  );
68  }
69  /* Get attribute that have the relation */
70 
71  $attributesId = array_unique(array_merge(array_map(function ($value)
72  {
73  return $value["attributeId"];
74  }
75  , $relationsFrom) , array_map(function ($value)
76  {
77  return $value["attributeId"];
78  }
79  , $relationsTo)));
80  $attributesId = array_filter($attributesId);
81  if (!empty($attributesId)) {
82  $query = new QueryDb($dbaccess, "DocAttr");
83  $query->AddQuery(GetSqlCond($attributesId, "id"));
84  $queryResults = $query->Query(0, 0, "TABLE");
85  if ($queryResults) {
86  $attributesValues = array();
87  foreach ($queryResults as $currentResult) {
88  $attributesValues[$currentResult["id"]] = $currentResult["labeltext"];
89  }
90  foreach ($relationsFrom as & $currentRelation) {
91  if (isset($attributesValues[$currentRelation["attributeId"]])) {
92  $currentRelation["attributeLabel"] = $attributesValues[$currentRelation["attributeId"]] != "folder" ? $attributesValues[$currentRelation["attributeId"]] : $i18nFolder;
93  }
94  }
95  foreach ($relationsTo as & $currentRelation) {
96  if (isset($attributesValues[$currentRelation["attributeId"]])) {
97  $currentRelation["attributeLabel"] = $attributesValues[$currentRelation["attributeId"]] != "folder" ? $attributesValues[$currentRelation["attributeId"]] : $i18nFolder;
98  }
99  }
100  }
101  }
102  // Verify visibility for current user
103  $tids = array_unique(array_merge(array_map(function ($value)
104  {
105  if (!empty($value["initid"])) {
106  return $value["initid"];
107  } else {
108  return null;
109  }
110  }
111  , $relationsFrom) , array_map(function ($value)
112  {
113  if (!empty($value["initid"])) {
114  return $value["initid"];
115  } else {
116  return null;
117  }
118  }
119  , $relationsTo)));
120  $tids = array_filter($tids);
121  if (!empty($tids)) {
122  $vdoc = getVisibleDocsFromIds($dbaccess, $tids, $action->user->id);
123  $tids = array_map(function ($value)
124  {
125  return $value["initid"];
126  }
127  , $vdoc);
128  }
129 
130  $filtersOnlyVisible = function ($value) use ($tids)
131  {
132  return in_array($value["initid"], $tids);
133  };
134 
135  $relationsFrom = array_filter($relationsFrom, $filtersOnlyVisible);
136  $relationsTo = array_filter($relationsTo, $filtersOnlyVisible);
137 
138  $results = array(
139  "currentDocument" => array(
140  "id" => $docid,
141  "title" => $doc->getHTMLTitle()
142  ) ,
143  "relationsTo" => $relationsTo,
144  "relationsFrom" => $relationsFrom
145  );
146 
147  if ($onlyGetResult) {
148  return $results;
149  } else {
150  $initData = array(
151  "i18n" => array(
152  "view document" => _("view document") ,
153  "noone document" => _("noone document") ,
154  "referenced from" => _("Referenced from") ,
155  "referenced" => _("Reference")
156  ) ,
157  'core_stand_url' => getParam("CORE_STANDURL") ,
158  'initial_data' => $results
159  );
160  $action->lay->set("init_data", json_encode($initData, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP));
161  $action->lay->set("RNAVIGATE_JS", $action->parent->getJsLink("FREEDOM:rnavigate.js"));
162  return null;
163  }
164 }
165 
167 {
168  $return = array(
169  "success" => true,
170  "error" => "",
171  "data" => array()
172  );
173 
174  try {
175  $return["data"] = rnavigate($action, true);
176  }
177  catch(Exception $e) {
178  $return["success"] = false;
179  $return["error"][] = $e->getMessage();
180  unset($return["data"]);
181  }
182 
183  $action->lay->template = json_encode($return);
184  $action->lay->noparse = true;
185  header('Content-type: application/json');
186 }
global $action
rnavigate_json(&$action)
Definition: rnavigate.php:166
$docid
Definition: cleanFamily.php:13
getParam($name, $def="")
must be in core or global type
Definition: Lib.Common.php:193
Verify arguments for action function.
new_Doc($dbaccess, $id= '', $latest=false)
GetSqlCond($Table, $column, $integer=false)
$dbaccess
Definition: checkVault.php:17
if(($docid!==0)&&(!is_numeric($docid))) $query
rnavigate(Action &$action, $onlyGetResult=false)
Definition: rnavigate.php:19
getVisibleDocsFromIds($dbaccess, $ids, $userid)
Definition: Lib.Dir.php:1062
$usage
$value
← centre documentaire © anakeen