* @package taoGroups */ class GroupsService extends OntologyClassService { const CLASS_URI = 'http://www.tao.lu/Ontologies/TAOGroup.rdf#Group'; const PROPERTY_MEMBERS_URI = 'http://www.tao.lu/Ontologies/TAOGroup.rdf#member'; /** * return the group top level class * * @access public * @author Joel Bout, * @return core_kernel_classes_Class */ public function getRootClass() { return $this->getClass(self::CLASS_URI); } /** * delete a group instance * * @access public * @author Joel Bout, * @param \core_kernel_classes_Resource group * @return boolean */ public function deleteGroup(\core_kernel_classes_Resource $group) { return $group !== null && $group->delete(true); } /** * Check if the Class in parameter is a subclass of the Group Class * * @access public * @author Joel Bout, * @param Class clazz * @return boolean */ public function isGroupClass(core_kernel_classes_Class $clazz) { return $clazz->equals($this->getRootClass()) || $clazz->isSubClassOf($this->getRootClass()); } /** * get the groups of a user * * @access public * @author Joel Bout, * @param string userUri * @return array resources of group */ public function getGroups(User $user) { $groups = $user->getPropertyValues(self::PROPERTY_MEMBERS_URI); array_walk($groups, function (&$group) { $group = new core_kernel_classes_Resource($group); }); return $groups; } /** * gets the users of a group * * @param string $groupUri * @return array resources of users */ public function getUsers($groupUri) { $subjectClass = TestTakerService::singleton()->getRootClass(); $users = $subjectClass->searchInstances([ self::PROPERTY_MEMBERS_URI => $groupUri ], [ 'recursive' => true, 'like' => false ]); return $users; } /** * Add a User to a Group * * @param string $userUri * @param core_kernel_classes_Resource $group * @return boolean */ public function addUser($userUri, core_kernel_classes_Resource $group) { $user = new \core_kernel_classes_Resource($userUri); return $user->setPropertyValue(new core_kernel_classes_Property(self::PROPERTY_MEMBERS_URI), $group); } /** * Remove a User from a Group * * @param string $userUri * @param core_kernel_classes_Resource $group * @return boolean */ public function removeUser($userUri, core_kernel_classes_Resource $group) { $user = new \core_kernel_classes_Resource($userUri); return $user->removePropertyValue(new core_kernel_classes_Property(self::PROPERTY_MEMBERS_URI), $group); } }