Forráskód Böngészése

Return an empty array if there are no groups

FusionPBX 8 hónapja
szülő
commit
17234a3ddd
1 módosított fájl, 15 hozzáadás és 9 törlés
  1. 15 9
      resources/classes/permissions.php

+ 15 - 9
resources/classes/permissions.php

@@ -41,12 +41,16 @@ if (!class_exists('permissions')) {
 		 */
 		 */
 		public function __construct($database = null, $domain_uuid = null, $user_uuid = null) {
 		public function __construct($database = null, $domain_uuid = null, $user_uuid = null) {
 
 
+			//intitialize as empty arrays
+			$this->groups = [];
+			$this->permissions = [];
+
 			//handle the database object
 			//handle the database object
 			if (isset($database)) {
 			if (isset($database)) {
 				$this->database = $database;
 				$this->database = $database;
 			}
 			}
 			else {
 			else {
-				$this->database = new database;
+				$this->database = database::new();
 			}
 			}
 
 
 			//set the domain_uuid
 			//set the domain_uuid
@@ -75,7 +79,9 @@ if (!class_exists('permissions')) {
 				$this->groups = $groups->assigned();
 				$this->groups = $groups->assigned();
 
 
 				//get the list of groups assigned to the user
 				//get the list of groups assigned to the user
-				$this->permissions = $this->assigned();
+				if (!empty($this->groups)) {
+					$this->permissions = $this->assigned();
+				}
 			}
 			}
 		}
 		}
 
 
@@ -143,6 +149,11 @@ if (!class_exists('permissions')) {
 			//define the array
 			//define the array
 			$parameter_names = [];
 			$parameter_names = [];
 
 
+			//return empty array if there are no groups
+			if (empty($this->groups)) {
+				return [];
+			}
+
 			//prepare the parameters
 			//prepare the parameters
 			$x = 0;
 			$x = 0;
 			foreach ($this->groups as $field) {
 			foreach ($this->groups as $field) {
@@ -156,13 +167,10 @@ if (!class_exists('permissions')) {
 			//get the permissions assigned to the user through the assigned groups
 			//get the permissions assigned to the user through the assigned groups
 			$sql = "select distinct(permission_name) from v_group_permissions ";
 			$sql = "select distinct(permission_name) from v_group_permissions ";
 			$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
 			$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
-			if (is_array($parameter_names) && @sizeof($parameter_names) != 0) {
-				$sql .= "and group_name in (".implode(", ", $parameter_names).") \n";
-			}
+			$sql .= "and group_name in (".implode(", ", $parameter_names).") \n";
 			$sql .= "and permission_assigned = 'true' ";
 			$sql .= "and permission_assigned = 'true' ";
 			$parameters['domain_uuid'] = $this->domain_uuid;
 			$parameters['domain_uuid'] = $this->domain_uuid;
-			$database = new database;
-			$permissions = $database->select($sql, $parameters, 'all');
+			$permissions = $this->database->select($sql, $parameters, 'all');
 			unset($sql, $parameters, $result);
 			unset($sql, $parameters, $result);
 			return $permissions;
 			return $permissions;
 		}
 		}
@@ -191,5 +199,3 @@ if (!class_exists('permissions')) {
 		$p = new permissions;
 		$p = new permissions;
 		$p->delete($permission);
 		$p->delete($permission);
 	*/
 	*/
-
-?>