FusionDirectory
class_ListingEntry.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4 
5  Copyright (C) 2017-2019 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
22 class ListingEntry implements ArrayAccess
23 {
27  public $dn;
28 
32  public $aclBase;
33 
37  public $row;
38 
42  public $type;
43 
44  private $attrs;
45  protected $listing;
46 
47  /* Cache where columns may store stuff */
48  public $cache = [];
49 
50  public function __construct (managementListing $listing, string $type, string $dn, array $attrs, int $row = NULL)
51  {
52  $this->listing = $listing;
53  $this->type = $type;
54  $this->dn = $dn;
55  $this->aclBase = $dn;
56  $this->attrs = $attrs;
57  $this->row = $row;
58  }
59 
60  public function offsetSet ($offset, $value)
61  {
62  $this->attrs[$offset] = $value;
63  }
64 
65  public function offsetExists ($offset)
66  {
67  return isset($this->attrs[$offset]);
68  }
69 
70  public function offsetUnset ($offset)
71  {
72  unset($this->attrs[$offset]);
73  }
74 
75  public function offsetGet ($offset)
76  {
77  return (isset($this->attrs[$offset]) ? $this->attrs[$offset] : NULL);
78  }
79 
80  public function getPid (): string
81  {
82  return $this->listing->pid;
83  }
84 
85  public function isTemplate (): bool
86  {
87  return preg_match('/^template_/', $this->type);
88  }
89 
90  public function getTemplatedType (): string
91  {
92  return preg_replace('/^template_/', '', $this->type);
93  }
94 
95  public function getTemplatedFields (): array
96  {
97  return templateHandling::fieldsFromLDAP($this->attrs);
98  }
99 
100  public function checkAcl (string $acls): bool
101  {
102  global $ui;
103 
104  $infos = objects::infos($this->getTemplatedType());
105  $rights = $ui->get_permissions($this->aclBase, $infos['aclCategory'].'/'.($this->isTemplate() ? 'template' : $infos['mainTab']));
106  foreach (str_split($acls) as $acl) {
107  if (strpos($rights, $acl) === FALSE) {
108  return FALSE;
109  }
110  }
111 
112  return TRUE;
113  }
114 
115  public function snapshotCreationAllowed (): bool
116  {
117  global $ui;
118 
119  $infos = objects::infos($this->getTemplatedType());
120  return $ui->allow_snapshot_create($this->aclBase, $infos['aclCategory']);
121  }
122 
123  public function snapshotRestoreAllowed (): bool
124  {
125  global $ui;
126 
127  $infos = objects::infos($this->getTemplatedType());
128  return $ui->allow_snapshot_restore($this->aclBase, $infos['aclCategory'], FALSE);
129  }
130 }
$type
Object type.
This class handles the entries list for a management instance.
$aclBase
DN to use for ACL checks, usually the same as $dn.
static fieldsFromLDAP(array $template_attrs)
Translate template attrs into $attrs as if taken from LDAP.
$dn
LDAP dn if any, unique id otherwise.
$row
Row number.