13 private static $viewUserVector = array();
14 private static $relationCache = array();
29 $isAdmin = ($uid == 1);
35 if ($docrevOption ===
"") {
36 $docrevOption =
$latest ?
"latest" :
"fixed";
38 $keyCache = intval(
$docid) .
'-' . $docrevOption;
40 if (!isset(self::$relationCache[$uid][$keyCache])) {
41 self::setRelationCache($doc, $uid);
44 if (isset(self::$relationCache[$uid][$keyCache])) {
46 $keyCache = intval(
$docid) .
'-' . $docrevOption;
48 if (isset(self::$relationCache[$uid][$keyCache])) {
49 $relCache = self::$relationCache[$uid][$keyCache];
50 if (!isset($relCache[
"rid"]) || !isset($relCache[
"title"])) {
53 if ($relCache[
"canaccess"] ===
'f' && (!$isAdmin)) {
58 return $relCache[
"title"];
74 $relationIds = array();
75 foreach (
$la as $oa) {
77 $docRevOption = $oa->getOption(
"docrev",
"latest");
78 $latest = $docRevOption ===
"latest";
80 if (preg_match(
'/^state\(([^\)]+)\)/', $docRevOption, $matches)) {
81 $revState = $matches[1];
86 foreach ($ids as $rid) {
87 if (is_numeric($rid)) $realId[] = intval($rid);
88 elseif (strpos($rid,
'<BR>') !==
false) {
89 $tt = explode(
'<BR>', $rid);
90 foreach ($tt as $brelid) {
91 if (is_numeric($brelid)) $realId[] = intval($brelid);
95 foreach ($realId as $did) {
96 $relationIds[$did .
'-' . $docRevOption] = array(
106 foreach ($relationIds as $k => $relid) {
107 if ($relid[
"latest"]) $latestId[] = $relid[
"docid"];
108 elseif ($relid[
"state"]) {
110 simpleQuery($doc->dbaccess, sprintf(
"select id from docread where initid=(select initid from docread where id=%d) and state = '%s' and locked = -1 order by id desc limit 1", $relid[
"docid"], pg_escape_string($relid[
"state"])) , $stateId,
true,
true);
112 $relationIds[$k][
"rid"] = $stateId;
117 $sql = sprintf(
"select id,initid from docread where initid in (%s) and locked != -1", implode(
',', $latestId));
121 foreach ($result as $aRow) {
122 $tInitid[$aRow[
"initid"]] = $aRow[
"id"];
124 foreach ($relationIds as $k => $relid) {
125 if ($relid[
"latest"]) {
126 $relationIds[$k][
"rid"] = empty($tInitid[$relid[
"docid"]]) ? $relid[
"docid"] : $tInitid[$relid[
"docid"]];
128 if (!$relid[
"state"]) {
129 $relationIds[$k][
"rid"] = $relid[
"docid"];
136 foreach ($relationIds as $relid) {
137 if (!empty($relid[
"rid"])) $realIds[] = $relid[
"rid"];
140 $sql = sprintf(
"select id,initid,title,name,doctype,revision,icon,fromid,views && '%s' as canaccess from docread where id in (%s)", self::getUserVector() , implode(
',', $realIds));
143 foreach ($result as $access) {
144 $accesses[$access[
"id"]] = $access;
147 foreach ($relationIds as $k => $relid) {
148 $rid = $relid[
"rid"];
149 if ($rid && isset($accesses[$rid])) {
151 if ($accesses[$rid][
"doctype"] ===
"C") {
153 "name" => $accesses[$rid][
"name"],
154 "title" => $accesses[$rid][
"title"]
157 $relationIds[$k][
"title"] = $accesses[$rid][
"title"];
159 $relationIds[$k][
"canaccess"] = $accesses[$rid][
"canaccess"];
160 $relationIds[$k][
"revision"] = $accesses[$rid][
"revision"];
161 $relationIds[$k][
"initid"] = $accesses[$rid][
"initid"];
162 $relationIds[$k][
"fromid"] = $accesses[$rid][
"fromid"];
163 $relationIds[$k][
"icon"] = $accesses[$rid][
"icon"];
167 if (!empty(self::$relationCache[$uid])) self::$relationCache[$uid] = array_merge($relationIds, self::$relationCache[$uid]);
168 else self::$relationCache[$uid] = $relationIds;
182 if (
$latest || $docrevOption ===
"latest") {
183 $sql = sprintf(
"select id,initid,title,revision,name,doctype,fromid,icon,views && '%s' as canaccess from docread where initid = %d and locked != -1", self::getUserVector() ,
$docid);
185 if (preg_match(
'/^state\(([^\)]+)\)/', $docrevOption, $matches)) {
186 $revState = $matches[1];
187 $sql = sprintf(
"select id,initid,revision,title,name,doctype,fromid,icon,views && '%s' as canaccess from docread where initid=(select initid from docread where id=%d) and state = '%s' and locked = -1 order by id desc limit 1", self::getUserVector() ,
$docid, pg_escape_string($revState));
189 $sql = sprintf(
"select id,initid,revision,title,name,doctype,fromid,icon,views && '%s' as canaccess from docread where id = %d", self::getUserVector() ,
$docid);
195 $keyCache = $result[
"id"] .
'-' . intval(
$latest);
196 self::$relationCache[$uid][$keyCache] = array(
197 "docid" => $result[
"id"],
198 "rid" => $result[
"id"],
199 "initid" => $result[
"initid"],
201 "revision" => $result[
"revision"],
202 "title" => $result[
"title"],
203 "fromid" => $result[
"fromid"],
204 "icon" => $result[
"icon"],
205 "canaccess" => $result[
"canaccess"]
208 if ($result[
"canaccess"] ===
't' || $uid ===
"1") {
210 return $result[
"title"];
223 private static function getUserVector()
226 if (!isset(self::$viewUserVector[$uid])) {
229 return self::$viewUserVector[$uid];
static setRelationCache(Doc $doc, $uid)
getNormalAttributes($onlyopt=false)
static getRelationTitle($docid, $latest=true, Doc $doc, $docrevOption="", array &$info=array())
getMultipleRawValues($idAttr, $def="", $index=-1)
static getLangTitle($values)
static getUserViewVector($uid)
getIdFromName($dbaccess, $name)
simpleQuery($dbaccess, $query, &$result=array(), $singlecolumn=false, $singleresult=false, $useStrict=null)
static getTitle($docid, $latest=true, $docrevOption="latest", array &$info=array())