Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.AccountCollection.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Specials methods for GROUP family
8  *
9  */
10 namespace Dcp\Core;
12 {
13  /*
14  * @end-method-ignore
15  */
16  /**
17  * reconstruct mail group & recompute parent group
18  *
19  * @return string error message, if no error empty string
20  */
21  function postStore()
22  {
23 
24  $err = $this->SetGroupMail();
25  $this->refreshParentGroup();
26  return $err;
27  }
28  /**
29  * @deprecated use postStore() instead
30  * @return string
31  */
32  public function postModify()
33  {
35  return self::postStore();
36  }
37  /**
38  * recompute only parent group
39  * @apiExpose
40  *
41  * @return string error message, if no error empty string
42  */
43  function RefreshGroup()
44  {
45  global $refreshedGrpId; // to avoid inifinitive loop recursion
46  $err = "";
47  if (!isset($refreshedGrpId[$this->id])) {
48  $err = $this->SetGroupMail();
49  $err.= $this->modify();
50  $this->specPostInsert();
51  $refreshedGrpId[$this->id] = true;
52  }
53  return $err;
54  }
55  /**
56  * update groups table in USER database
57  * @return string error message
58  */
59  function postInsertDocument($docid, $multiple = false)
60  {
61  if ($multiple == false) {
62  $this->SetGroupMail();
63  $this->refreshMembers();
64  $this->specPostInsert();
65  }
66  }
67  /**
68  * update groups table in USER database
69  * @return string error message
70  */
71  function postInsertMultipleDocuments($tdocid)
72  {
73  $this->SetGroupMail();
74  $this->refreshMembers();
75  $this->specPostInsert();
76  }
77  /**
78  * update groups table in USER database before suppress
79  * @return string error message
80  */
81  function postRemoveDocument($docid, $multiple = false)
82  {
83  $this->SetGroupMail();
84  $this->refreshMembers();
85  $this->specPostInsert();
86  }
87  /**
88  * special method for child classes
89  * call after insert user in group
90  * @return string error message
91  */
92  function specPostInsert()
93  {;
94  }
95  /**
96  * compute the mail of the group
97  * concatenation of each user mail and group member mail
98  *
99  *
100  * @return string error message, if no error empty string
101  */
102  function SetGroupMail($nomail = false)
103  {
104 
105  $err = "";
106  $gmail = " ";
107  $tmail = array();
108 
109  if (!$nomail) $nomail = ($this->getRawValue("grp_hasmail") == "no");
110  if (!$nomail) {
111 
112  $s = new \SearchDoc($this->dbaccess);
113  $s->useCollection($this->initid);
114  $r = $s->search();
115  foreach ($r as $account) {
116  $mail = $account["us_mail"];
117  if (!$mail) $account["grp_mail"];
118  if ($mail) $tmail[] = $mail;
119  }
120  $gmail = implode(", ", array_unique($tmail));
121  $this->SetValue("GRP_MAIL", $gmail);
122  }
123 
124  if ($this->getRawValue("grp_hasmail") == "no") $this->clearValue("GRP_MAIL");
125 
126  return $err;
127  }
128  /**
129  * recompute parent group and its ascendant
130  *
131  * @return array/array parents group list refreshed
132  * @see RefreshGroup()
133  */
134  function refreshParentGroup()
135  {
136  include_once ("FDL/freedom_util.php");
137  include_once ("FDL/Lib.Dir.php");
138 
139  $sqlfilters[] = sprintf("in_textlist(grp_idgroup,'%s')", $this->id);
140  // $sqlfilters[]="fromid !=".getFamIdFromName($this->dbaccess,"IGROUP");
141  $tgroup = internalGetDocCollection($this->dbaccess, 0, "0", "ALL", $sqlfilters, 1, "LIST", getFamIdFromName($this->dbaccess, "GROUP"));
142 
143  $tpgroup = array();
144  $tidpgroup = array();
145  /**
146  * @var \Dcp\Family\Group $v
147  */
148  foreach ($tgroup as $k => $v) {
149  $v->RefreshGroup();
150  $tpgroup[] = $v->title;
151  $tidpgroup[] = $v->id;
152  }
153 
154  $this->SetValue("GRP_IDPGROUP", implode("\n", $tidpgroup));
155  return $tgroup;
156  }
157  /**
158  * refresh members of the group from USER database
159  */
160  function refreshMembers()
161  {
162  include_once ("FDL/Lib.Dir.php");
163  // 2)groups
164  $tu = internalGetDocCollection($this->dbaccess, $this->initid, "0", "ALL", array() , 1, "TABLE", "GROUP");
165  $tmemid = array();
166  $tmem = array();
167  if (count($tu) > 0) {
168  foreach ($tu as $k => $v) {
169  $tmemid[] = $v["id"];
170  $tmem[] = $v["title"];
171  }
172  $this->SetValue("GRP_IDGROUP", $tmemid);
173  } else {
174  $this->clearValue("GRP_IDGROUP");
175  }
176  $err = $this->modify();
177  }
178 
180  {
181  // Recompute mail/members when the hasmail/hasmembers enum is changed
182  if ($this->getOldRawValue('GRP_HASMAIL') !== false || $this->getOldRawValue('GRP_HASMEMBERS') !== false) {
183  $err = $this->refreshGroup();
184  if ($err != '') {
185  return $err;
186  }
187  }
188  return '';
189  }
190 }
getOldRawValue($attrid)
Definition: Class.Doc.php:4375
postInsertDocument($docid, $multiple=false)
clearValue($attrid)
Definition: Class.Doc.php:4409
count($onlyprimary=false)
Definition: Class.Dir.php:916
if($famId) $s
modify($nopost=false, $sfields="", $nopre=false)
$docid
Definition: cleanFamily.php:13
internalGetDocCollection($dbaccess, $dirid, $start="0", $slice="ALL", $sqlfilters=array(), $userid=1, $qtype="LIST", $fromid="", $distinct=false, $orderby="title", $latest=true, $trash="", &$debug=null, $folderRecursiveLevel=2, $join= '',\SearchDoc &$searchDoc=null)
Definition: Lib.Dir.php:428
getFamIdFromName($dbaccess, $name)
deprecatedFunction($msg= '')
Definition: Lib.Common.php:86
$account
Definition: guest.php:36
if($file) if($subject==""&&$file) if($subject=="") $err
getRawValue($idAttr, $def="")
Definition: Class.Doc.php:3117
postRemoveDocument($docid, $multiple=false)
← centre documentaire © anakeen