Can get group settings.

This commit is contained in:
Pierre HUBERT
2018-07-04 07:44:37 +02:00
parent 291558578b
commit 57401c8ce0
3 changed files with 123 additions and 5 deletions

View File

@ -107,6 +107,27 @@ class GroupsComponent {
return $this->dbToAdvancedGroupInfo($info[0]);
}
/**
* Get a group settings
*
* @param int $id The ID of the target group
* @return GroupSettings The settings of the group / invalid
* GroupSettings object in case of failure
*/
public function get_settings(int $id) : GroupSettings {
//Query the database
$info = db()->select(self::GROUPS_LIST_TABLE, "WHERE id = ?", array($id));
//Check for results
if(count($info) == 0)
return new GroupSettings(); //Return invalid object
//Create and fill GroupInfo object with database entry
return $this->dbToGroupSettings($info[0]);
}
/**
* Insert a new group member
*
@ -164,6 +185,18 @@ class GroupsComponent {
return $results[0]["level"];
}
/**
* Check whether a user is an administrator of a group
* or not
*
* @param int $userID Requested user ID to check
* @return bool TRUE if the user is an admin / FALSE else
*/
public function isAdmin(int $userID, int $groupID){
return $this->getMembershipLevel($userID, $groupID)
== GroupMember::ADMINISTRATOR;
}
/**
* Count the number of members of a group
*
@ -198,15 +231,19 @@ class GroupsComponent {
}
/**
* Turn a database entry into AdvancedGroupInfo object entry
* Turn a database group entry into AdvancedGroupInfo object entry
*
* @param array $data Database entry
* @param AdvancedGroupInfo $info Optionnal, fill an existing object
* instead of creating a new one
* @return AdvancedGroupInfo Advanced information about the group
*/
private function dbToAdvancedGroupInfo(array $data) : AdvancedGroupInfo {
private function dbToAdvancedGroupInfo(array $data, AdvancedGroupInfo $info = null) : AdvancedGroupInfo {
if($info == null)
$info = new AdvancedGroupInfo();
//Parse basical information about the group
$info = new AdvancedGroupInfo();
$this->dbToGroupInfo($data, $info);
//Parse advanced information
@ -215,6 +252,22 @@ class GroupsComponent {
return $info;
}
/**
* Turn a database group entry into GroupSettings object
*
* @param array $data Database entry
* @return GroupSettings The settings of the group
*/
private function dbToGroupSettings(array $data) : GroupSettings {
//Parse advanced settings about the group
$info = new GroupSettings();
$this->dbToAdvancedGroupInfo($data, $info);
return $info;
}
}
//Register component

View File

@ -0,0 +1,10 @@
<?php
/**
* Group settings model object
*
* @author Pierre HUBERT
*/
class GroupSettings extends AdvancedGroupInfo {
}