Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see common_ext_ExtensionUpdater::update()
  */
 public function update($initialVersion)
 {
     $current = $initialVersion;
     if ($current == '2.6') {
         OntologyUpdater::syncModels();
         $iterator = new \core_kernel_classes_ResourceIterator(array(GroupsService::singleton()->getRootClass()));
         foreach ($iterator as $group) {
             $users = $group->getPropertyValues(new \core_kernel_classes_Property(self::OLD_MEMBER_PROPERTY));
             foreach ($users as $userUri) {
                 if (GroupsService::singleton()->addUser($userUri, $group)) {
                     //$group->removePropertyValue(new \core_kernel_classes_Property(self::OLD_MEMBER_PROPERTY), $userUri);
                 }
             }
         }
         $current = '2.6.1';
     }
     if ($current == '2.6.1' || $current == '2.6.2') {
         $current = '2.7';
     }
     if ($current == '2.7') {
         OntologyUpdater::syncModels();
         $current = '2.7.1';
     }
     return $current;
 }
 public function onDelete(core_kernel_classes_Resource $delivery)
 {
     $groupClass = GroupsService::singleton()->getRootClass();
     $assigned = $groupClass->searchInstances(array(PROPERTY_GROUP_DELVIERY => $delivery), array('like' => false, 'recursive' => true));
     $assignationProperty = new core_kernel_classes_Property(PROPERTY_GROUP_DELVIERY);
     foreach ($assigned as $groupInstance) {
         $groupInstance->removePropertyValue($assignationProperty, $delivery);
     }
 }
 public static function generateTesttakers($count = 1000)
 {
     $ext = \common_ext_ExtensionsManager::singleton()->getExtensionById('taoGroups');
     $topClass = new \core_kernel_classes_Class(TAO_SUBJECT_CLASS);
     $role = new \core_kernel_classes_Resource(INSTANCE_ROLE_DELIVERY);
     $class = self::generateUsers($count, $topClass, $role, 'Test-Taker ', 'tt');
     $groupClass = new \core_kernel_classes_Class(TAO_GROUP_CLASS);
     $group = $groupClass->createInstanceWithProperties(array(RDFS_LABEL => $class->getLabel()));
     foreach ($class->getInstances() as $user) {
         GroupsService::singleton()->addUser($user->getUri(), $group);
     }
     return $class;
 }
 /**
  * @inheritdoc
  */
 public function getDeliveryIdsByUser(User $user)
 {
     $deliveryUris = array();
     // check if really available
     foreach (GroupsService::singleton()->getGroups($user) as $group) {
         foreach ($group->getPropertyValues(new \core_kernel_classes_Property(PROPERTY_GROUP_DELVIERY)) as $deliveryUri) {
             $candidate = new \core_kernel_classes_Resource($deliveryUri);
             if (!$this->isUserExcluded($candidate, $user) && $candidate->exists() && $this->isEligible($candidate, $user)) {
                 $deliveryUris[] = $candidate->getUri();
             }
         }
     }
     return array_unique($deliveryUris);
 }
 protected function get()
 {
     $requestParams = $this->getRequestParameters();
     $delivery = $this->getCurrentInstance();
     $deliveryUsers = $this->testTakersService->getDeliveryTestTakers($delivery);
     $result = array('ttexcluded' => array(), 'ttassigned' => array());
     $excludedUsersUri = array_map(function ($val) {
         return $val['uri'];
     }, $deliveryUsers['ttexcluded']);
     if (isset($requestParams['groups'])) {
         $groupsService = GroupsService::singleton();
         foreach ($requestParams['groups'] as $group) {
             $users = $groupsService->getUsers(\tao_helpers_Uri::decode($group));
             foreach ($users as $user) {
                 if (!in_array($user->getUri(), $excludedUsersUri)) {
                     $result['ttassigned'][] = $this->testTakersService->getTestTakerData($user);
                 } else {
                     $result['ttexcluded'][] = $this->testTakersService->getTestTakerData($user);
                 }
             }
         }
     }
     $this->sendData($result);
 }
Esempio n. 6
0
 /**
  * (non-PHPdoc)
  * @see common_ext_ExtensionUpdater::update()
  */
 public function update($initialVersion)
 {
     if ($this->isVersion('2.6')) {
         OntologyUpdater::syncModels();
         $iterator = new \core_kernel_classes_ResourceIterator(array(GroupsService::singleton()->getRootClass()));
         foreach ($iterator as $group) {
             $users = $group->getPropertyValues(new \core_kernel_classes_Property(self::OLD_MEMBER_PROPERTY));
             foreach ($users as $userUri) {
                 if (GroupsService::singleton()->addUser($userUri, $group)) {
                     //$group->removePropertyValue(new \core_kernel_classes_Property(self::OLD_MEMBER_PROPERTY), $userUri);
                 }
             }
         }
         $this->setVersion('2.6.1');
     }
     if ($this->isBetween('2.6.1', '2.7')) {
         $this->setVersion('2.7');
     }
     if ($this->isVersion('2.7')) {
         OntologyUpdater::syncModels();
         $this->setVersion('2.7.1');
     }
     $this->skip('2.7.1', '2.10.2');
 }
Esempio n. 7
0
 /**
  * (non-PHPdoc)
  * @see tao_actions_SaSModule::getClassService()
  */
 protected function getClassService()
 {
     return GroupsService::singleton();
 }
 /**
  * Get the group class where the group are stored
  * @return \core_kernel_classes_Class|null
  */
 private function getGroupClass()
 {
     if (is_null($this->groupClass)) {
         $subClasses = GroupsService::singleton()->getRootClass()->getSubClasses();
         foreach ($subClasses as $subClass) {
             if ($subClass->getLabel() === self::GROUP_CLASS_NAME) {
                 $this->groupClass = $subClass;
                 continue;
             }
         }
         if (is_null($this->groupClass)) {
             $this->groupClass = GroupsService::singleton()->getRootClass()->createSubClass(self::GROUP_CLASS_NAME);
         }
     }
     return $this->groupClass;
 }
Esempio n. 9
0
 /**
  * 
  * @author Lionel Lecaque, lionel@taotesting.com
  */
 public function testGetGroups()
 {
     $groupClass = GroupsService::singleton()->getRootClass();
     $this->assertTrue($this->groupsService->isGroupClass($groupClass));
     $subject = $this->subjectsService->createInstance($this->subjectsService->getRootClass(), 'testSubject');
     $oneGroup = $groupClass->createInstance('testGroupInstance');
     $this->groupsService->addUser($subject->getUri(), $oneGroup);
     $oneGroup2 = $groupClass->createInstance('testGroupInstance2');
     $subclass = $groupClass->createSubClass('testGroupSubclass');
     $oneGroup3 = $subclass->createInstance('testSubGroupInstance');
     $this->groupsService->addUser($subject->getUri(), $oneGroup3);
     $generisUser = new \core_kernel_users_GenerisUser($subject);
     $groups = $this->groupsService->getGroups($generisUser);
     $this->assertTrue(is_array($groups));
     $this->assertTrue(count($groups) == 2);
     array_walk($groups, function (&$group) {
         $group = $group->getUri();
     });
     $this->assertContains($oneGroup->getUri(), $groups);
     $this->assertNotContains($oneGroup2->getUri(), $groups);
     $this->assertContains($oneGroup3->getUri(), $groups);
     $this->assertTrue($this->groupsService->deleteGroup($oneGroup));
     $this->assertTrue($this->groupsService->deleteGroup($oneGroup2));
     $this->assertTrue($this->groupsService->deleteGroup($oneGroup3));
     $this->assertTrue($this->groupsService->deleteClass($subclass));
     $subject->delete();
 }
 /**
  * // assigned if:
  * (assigned to parent || assigned to recursion) && !exluded from recursion && !exluded from parent
  * 
  * @param \core_kernel_classes_Resource $delivery
  * @param User $user
  * @param bool $checkRepeated Whether check repeated deliveries if main (not repeated) delivery given
  * @return bool
  */
 public function verifyUserAssignedRecursiv(\core_kernel_classes_Resource $delivery, User $user)
 {
     $repeatedDeliveryService = $this->getServiceManager()->get(RepeatedDeliveryService::CONFIG_ID);
     $currentRepetition = $repeatedDeliveryService->getCurrentRepeatedDelivery($delivery);
     if (is_null($currentRepetition)) {
         $assigned = parent::verifyUserAssigned($delivery, $user);
     } else {
         $userGroups = GroupsService::singleton()->getGroups($user);
         $deliveryGroups = GroupsService::singleton()->getRootClass()->searchInstances(array(PROPERTY_GROUP_DELVIERY => array($currentRepetition->getUri(), $delivery->getUri())), array('like' => false, 'recursive' => true, 'chaining' => 'or'));
         $assigned = count(array_intersect($userGroups, $deliveryGroups)) > 0 && !$this->isUserExcluded($delivery, $user) && !$this->isUserExcluded($currentRepetition, $user);
     }
     return $assigned;
 }
 protected function verifyUserAssigned(core_kernel_classes_Resource $delivery, User $user)
 {
     $returnValue = false;
     //check for guest access mode
     if ($this->isDeliveryGuestUser($user) && $this->hasDeliveryGuestAccess($delivery)) {
         $returnValue = true;
     } else {
         $userGroups = GroupsService::singleton()->getGroups($user);
         $deliveryGroups = GroupsService::singleton()->getRootClass()->searchInstances(array(PROPERTY_GROUP_DELVIERY => $delivery->getUri()), array('like' => false, 'recursive' => true));
         $returnValue = count(array_intersect($userGroups, $deliveryGroups)) > 0 && !$this->isUserExcluded($delivery, $user);
     }
     return $returnValue;
 }
 /**
  * Returns a group assinged to the delivery
  * 
  * @param unknown $deliveryId
  * @return string
  */
 private function findGroup($deliveryId)
 {
     $groups = GroupsService::singleton()->getRootClass()->searchInstances(array(PROPERTY_GROUP_DELVIERY => $deliveryId), array('recursive' => true, 'like' => false));
     if (empty($groups)) {
         throw new \common_Exception('No system group exists for delivery ' . $deliveryId);
     }
     return reset($groups);
 }