Highway to PSR2
[openemr.git] / interface / modules / zend_modules / module / Acl / src / Acl / Model / AclTable.php
blob3aeab269846a4855d56effdc33bcb97fdea1f495
1 <?php
2 /* +-----------------------------------------------------------------------------+
3 * OpenEMR - Open Source Electronic Medical Record
4 * Copyright (C) 2013 Z&H Consultancy Services Private Limited <sam@zhservices.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @author Jacob T.Paul <jacob@zhservices.com>
19 * @author Basil PT <basil@zhservices.com>
21 * +------------------------------------------------------------------------------+
24 namespace Acl\Model;
26 use Zend\Db\TableGateway\AbstractTableGateway;
27 use Zend\Db\Adapter\Adapter;
28 use Zend\Db\ResultSet\ResultSet;
29 use \Application\Model\ApplicationTable;
31 class AclTable extends AbstractTableGateway
33 protected $table = 'acl';
35 public function __construct(Adapter $adapter)
37 $this->adapter = $adapter;
38 $this->resultSetPrototype = new ResultSet();
39 $this->resultSetPrototype->setArrayObjectPrototype(new Acl());
40 $this->initialize();
43 public function aclSections($module_id)
45 $obj = new ApplicationTable;
46 if ($module_id != '') {
47 $sql = "SELECT * FROM module_acl_sections WHERE module_id = ?";
48 $params = array($module_id);
49 $result = $obj->zQuery($sql, $params);
50 } else {
51 $sql = "SELECT * FROM module_acl_sections ";
52 $result = $obj->zQuery($sql);
55 return $result;
57 public function aclUserGroupMapping()
59 $sql = "SELECT
60 usr. id AS user_id,
61 garo.id AS aro_id,
62 garo.value AS username,
63 garo.name AS display_name,
64 gagp.id AS group_id,
65 gagp.name AS group_name,
66 gagp.value AS group_nick
67 FROM
68 `gacl_aro` AS garo
69 LEFT JOIN `gacl_groups_aro_map` AS gamp
70 ON garo.id = gamp.aro_id
71 LEFT JOIN `gacl_aro_groups` AS gagp
72 ON gagp.id = gamp.group_id
73 RIGHT JOIN `users_secure` usr
74 ON usr. username = garo.value
75 WHERE
76 garo.section_value = ?";
77 $params = array('users');
78 $obj = new ApplicationTable;
79 $result = $obj->zQuery($sql, $params);
80 return $result;
82 public function getActiveModules()
84 $sql = "SELECT * FROM modules";
85 $obj = new ApplicationTable;
86 $result = $obj->zQuery($sql);
87 return $result;
89 public function getGroups()
91 $sql = "SELECT * FROM gacl_aro_groups WHERE parent_id > 0";
92 $obj = new ApplicationTable;
93 $result = $obj->zQuery($sql);
94 return $result;
96 public function getGroupAcl($module_id)
98 $sql = "SELECT * FROM module_acl_group_settings WHERE module_id = ? AND allowed = 1";
99 $obj = new ApplicationTable;
100 $result = $obj->zQuery($sql, array($module_id));
101 return $result;
103 public function deleteGroupACL($module_id, $section_id)
105 $sql = "DELETE FROM module_acl_group_settings WHERE module_id = ? AND section_id = ? ";
106 $obj = new ApplicationTable;
107 $result = $obj->zQuery($sql, array($module_id,$section_id));
109 public function deleteUserACL($module_id, $section_id)
111 $sql = "DELETE FROM module_acl_user_settings WHERE module_id = ? AND section_id = ? ";
112 $obj = new ApplicationTable;
113 $result = $obj->zQuery($sql, array($module_id,$section_id));
115 public function insertGroupACL($module_id, $group_id, $section_id, $allowed)
117 $sql = "INSERT INTO module_acl_group_settings (module_id,group_id,section_id,allowed) VALUES (?,?,?,?)";
118 $obj = new ApplicationTable;
119 $result = $obj->zQuery($sql, array($module_id,$group_id,$section_id,$allowed));
121 public function insertuserACL($module_id, $user_id, $section_id, $allowed)
123 $sql = "INSERT INTO module_acl_user_settings(module_id,user_id,section_id,allowed) VALUES (?,?,?,?)";
124 $obj = new ApplicationTable;
125 $result = $obj->zQuery($sql, array($module_id,$user_id,$section_id,$allowed));
127 public function getAclDataUsers($section_id)
129 $sql = " SELECT
130 usr_settings.*,
131 aromap.group_id
132 FROM
133 `module_acl_user_settings` AS usr_settings
134 LEFT JOIN `users_secure` AS usr
135 ON usr_settings.`user_id` = usr.id
136 LEFT JOIN `gacl_aro` AS aro
137 ON aro.value = usr.username
138 LEFT JOIN `gacl_groups_aro_map` AS aromap
139 ON aromap.aro_id = aro.id
140 WHERE
141 usr_settings.`section_id` = ? AND aro.section_value = 'users'";
142 $obj = new ApplicationTable;
143 $result = $obj->zQuery($sql, array($section_id));
144 return $result;
146 public function getAclDataGroups($section_id)
148 $sql = "SELECT * FROM module_acl_group_settings WHERE section_id =?";
149 $obj = new ApplicationTable;
150 $result = $obj->zQuery($sql, array($section_id));
151 return $result;
153 public function deleteModuleGroupACL($module_id)
155 $sql = "DELETE FROM module_acl_group_settings WHERE module_id =?";
156 $obj = new ApplicationTable;
157 $result = $obj->zQuery($sql, array($module_id));
159 public function getSectionsInsertId()
161 $sql = "SELECT MAX(section_id) AS max_id FROM module_acl_sections";
162 $obj = new ApplicationTable;
163 $result = $obj->zQuery($sql);
164 $max_id = 0;
165 foreach ($result as $row) {
166 $max_id = $row['max_id'];
169 $max_id++;
170 return $max_id;
172 public function saveACLSections($module_id, $parent_id, $section_identifier, $section_name, $section_id)
174 $sql = "INSERT INTO module_acl_sections(section_id,section_name,parent_section,section_identifier,module_id) VALUES(?,?,?,?,?)";
175 $obj = new ApplicationTable;
176 $result = $obj->zQuery($sql, array($section_id,$section_name,$parent_id,$section_identifier,$module_id));
178 public function getModuleSections($module_id)
180 $sql = "SELECT * FROM module_acl_sections WHERE module_id = ?";
181 $obj = new ApplicationTable;
182 $result = $obj->zQuery($sql, array($module_id));
183 return $result;