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