Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.DocWaitManager.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * Manage Waiting Doc
9  *
10  * @author Anakeen
11  * @version $Id: $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 
18 include_once ("FDL/Class.DocWait.php");
19 include_once ("FDL/Class.Doc.php");
20 
22 {
23  /**
24  * create or update a new entry in docWait
25  *
26  * @param Doc $doc
27  * @return string error message
28  */
29  public static function saveWaitingDoc(Doc & $doc, $domainId = null, $transaction = null, $extraData = null)
30  {
31  $err = '';
32 
33  if ($doc) {
34  $wd = new DocWait($doc->dbaccess, array(
35  $doc->initid,
36  $doc->getSystemUserId()
37  ));
38 
39  $wd->uid = $doc->getSystemUserId();
40  $wd->localid = $doc->localid;
41  $wd->values = serialize($doc->getValues());
42  $wd->status = docWait::recording;
43  $wd->title = $doc->getTitle();
44  $wd->fromid = $doc->fromid;
45  $wd->refererid = $doc->id;
46  $wd->refererinitid = $doc->initid;
47  $wd->domain = $domainId;
48  $wd->transaction = $transaction;
49  $wd->date = date('Y-m-d H:i:s.u');
50  if ($extraData !== null) $wd->extradata = json_encode($extraData);
51 
52  if ($wd->isAffected()) {
53  $err = $wd->modify();
54  } else {
55  $orivalues = $doc->getValues();
56  $ori = new_doc($doc->dbaccess, $doc->id, true);
57  if ($ori->isAlive()) {
58  $wd->orivalues = serialize($ori->getValues());
59  $wd->status = docWait::upToDate;
60  }
61  $err = $wd->add();
62  }
63  } else {
64  $err = sprintf(_("waiting : document not set"));
65  }
66  return $err;
67  }
68  /**
69  * Return waiting doc
70  * @param int $id doc identificator
71  * @return Doc
72  */
73  public static function getWaitingDoc($id)
74  {
75  $wd = new DocWait(getDbAccess() , array(
76  $id,
78  ));
79 
80  if ($wd->isAffected()) {
81  return $wd;
82  }
83  return null;
84  }
85  /**
86  * return unresolved links
87  * @param int $domain domain identificator
88  * @param int $user user identificator
89  * @return array index=localid, value=serverid
90  */
91  public static function getUnresolvedLocalLinks($domain = - 1, $user = - 1)
92  {
93  $q = new QueryDb(getDbAccess() , "docWait");
94  $q->addQuery(sprintf("domain = %d", $domain));
95  $q->addQuery(sprintf("uid = %d", $user));
96  $q->addQuery("localid is not null");
97  $q->addQuery("refererinitid < 0");
98 
99  $res = $q->Query(0, 0, 'TABLE');
100  $out = array();
101  if (is_array($res)) {
102  foreach ($res as $k => $v) {
103  $out[$v['localid']] = $v['refererinitid'];
104  }
105  }
106  return $out;
107  }
108  /**
109  * return waiting doc for a transaction
110  * @param int $transaction transaction identificator
111  * @return DbObjectList docWait list
112  */
113  public static function getWaitingDocs($transaction)
114  {
115  $q = new QueryDb(getDbAccess() , "docWait");
116  $q->addQuery(sprintf("transaction = %d", $transaction));
117 
118  return $q->Query(0, 0, 'ITER');
119  }
120  /**
121  * return waiting doc for a domain
122  * @param int $transaction transaction identificator
123  * @return DbObjectList docWait list
124  */
125  public static function getWaitingDocsByDomain($domainId)
126  {
127  $q = new QueryDb(getDbAccess() , "docWait");
128  $q->addQuery(sprintf("domain = %d", $domainId));
129 
130  return $q->Query(0, 0, 'ITER');
131  }
132  /**
133  * create a new transaction id
134  * @return int transaction identificator
135  */
136  public static function getTransaction()
137  {
138  $err = simpleQuery(getDbAccess() , "select nextval ('seq_waittransaction')", $transaction, true, true);
139  return $transaction;
140  }
141  /**
142  * delete waiting document for a domain, an user or an user in a domain
143  * @param int $domain domain identificator
144  * @param int $user user identificator
145  * @param int $docinitid initial document identificator
146  */
147  public static function clearWaitingDocs($domain = - 1, $user = - 1, $docinitid = - 1)
148  {
149  $err = '';
150  $wheres = array();
151  if ($domain >= 0) {
152  $wheres[] = sprintf("domain = %d", $domain);
153  }
154  if ($user >= 0) {
155  $wheres[] = sprintf("uid = %d", $user);
156  }
157  if ($docinitid >= 0) {
158  $wheres[] = sprintf("refererinitid = %d", $docinitid);
159  }
160  //error_log("clearWaitingDocs $domain - $user - $docinitid");
161  if (count($wheres) == 0) {
162  $err = simpleQuery(getDbAccess() , "delete from docwait");
163  } else {
164  $err = simpleQuery(getDbAccess() , sprintf("delete from docwait where %s", implode(" and ", $wheres)));
165  }
166  return $err;
167  }
168 }
169 ?>
← centre documentaire © anakeen - published under CC License - Dynacase