/** * Short description of method getValue * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param string rowId * @param string columnId * @param string data * @return mixed */ public function getValue($rowId, $columnId, $data = null) { $returnValue = null; //@TODO : to be delegated to the LazyAdapter : columnNames, adapterOptions, excludedProperties if (isset($this->data[$rowId])) { //return values: if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } else { if (common_Utils::isUri($rowId)) { $user = new core_kernel_classes_Resource($rowId); $this->data[$rowId] = array(); $fastProperty = array(RDFS_LABEL, PROPERTY_USER_LOGIN, PROPERTY_USER_FIRSTNAME, PROPERTY_USER_LASTNAME, PROPERTY_USER_MAIL, PROPERTY_USER_UILG, PROPERTY_USER_DEFLG); $properties = array(); $propertyUris = array_diff($fastProperty, $this->excludedProperties); foreach ($propertyUris as $activityExecutionPropertyUri) { $properties[] = new core_kernel_classes_Property($activityExecutionPropertyUri); } $propertiesValues = $user->getPropertiesValues($properties); foreach ($propertyUris as $propertyUri) { $value = null; if (isset($propertiesValues[$propertyUri]) && count($propertiesValues[$propertyUri])) { $value = reset($propertiesValues[$propertyUri]); } switch ($propertyUri) { case RDFS_LABEL: case PROPERTY_USER_LOGIN: case PROPERTY_USER_FIRSTNAME: case PROPERTY_USER_LASTNAME: case PROPERTY_USER_MAIL: case PROPERTY_USER_LOGIN: case PROPERTY_USER_UILG: case PROPERTY_USER_DEFLG: $this->data[$rowId][$propertyUri] = $value instanceof core_kernel_classes_Resource ? $value->getLabel() : (string) $value; break; } } //get roles: if (!in_array('roles', $this->excludedProperties)) { $i = 0; foreach ($user->getTypes() as $role) { if ($role instanceof core_kernel_classes_Resource) { if ($i) { $this->data[$rowId]['roles'] .= ', '; } else { $this->data[$rowId]['roles'] = ''; } $this->data[$rowId]['roles'] .= $role->getLabel(); } $i++; } } if (isset($this->data[$rowId][$columnId])) { $returnValue = $this->data[$rowId][$columnId]; } } } return $returnValue; }
public function getResourceDescription(core_kernel_classes_Resource $resource, $fromDefinition = true) { $returnValue = new stdClass(); $properties = array(); if ($fromDefinition) { $types = $resource->getTypes(); foreach ($types as $type) { foreach ($type->getProperties(true) as $property) { //$this->$$property->getUri() = array($property->getLabel(),$this->getPropertyValues()); $properties[$property->getUri()] = $property; } } //var_dump($properties); $properties = array_unique($properties); $propertiesValues = $resource->getPropertiesValues($properties); if (count($propertiesValues) == 0) { throw new common_exception_NoContent(); } $propertiesValuesStdClasses = $this->propertiesValuestoStdClasses($propertiesValues); } else { $triples = $resource->getRdfTriples(); if (count($triples) == 0) { throw new common_exception_NoContent(); } foreach ($triples as $triple) { $properties[$triple->predicate][] = common_Utils::isUri($triple->object) ? new core_kernel_classes_Resource($triple->object) : new core_kernel_classes_Literal($triple->object); } $propertiesValuesStdClasses = $this->propertiesValuestoStdClasses($properties); } $returnValue->uri = $resource->getUri(); $returnValue->properties = $propertiesValuesStdClasses; return $returnValue; }
protected function getProperties(\core_kernel_classes_Resource $resource) { $classProperties = array($this->getProperty(RDFS_LABEL)); foreach ($resource->getTypes() as $type) { $classProperties = array_merge($classProperties, $this->getPropertiesByClass($type)); } return $classProperties; }
/** * (non-PHPdoc) * @see \oat\generis\model\data\PermissionInterface::onResourceCreated() */ public function onResourceCreated(\core_kernel_classes_Resource $resource) { $dbAccess = new DataBaseAccess(); // test if class $class = new \core_kernel_classes_Class($resource); foreach (array_merge($resource->getTypes(), $class->getParentClasses()) as $parent) { foreach (AdminService::getUsersPermissions($parent->getUri()) as $userUri => $rights) { $dbAccess->addPermissions($userUri, $resource->getUri(), $rights); } } }
/** * (non-PHPdoc) * @see \oat\generis\model\data\PermissionInterface::onResourceCreated() */ public function onResourceCreated(\core_kernel_classes_Resource $resource) { $dbAccess = new DataBaseAccess(); // verify resource is created $permissions = $dbAccess->getResourcePermissions($resource->getUri()); if (empty($permissions)) { // treat resources as classes without parent classes $class = new \core_kernel_classes_Class($resource); foreach (array_merge($resource->getTypes(), $class->getParentClasses()) as $parent) { foreach (AdminService::getUsersPermissions($parent->getUri()) as $userUri => $rights) { $dbAccess->addPermissions($userUri, $resource->getUri(), $rights); } } } }
/** * Get the categories of an item * * @param RdfResource $item the item * * @return string[] the list of categories */ public function getItemCategories(RdfResource $item) { $categories = []; foreach ($item->getTypes() as $class) { $eligibleProperties = $this->getElligibleProperties($class); $propertiesValues = $item->getPropertiesValues(array_keys($eligibleProperties)); foreach ($propertiesValues as $property => $propertyValues) { foreach ($propertyValues as $value) { if ($value instanceof RdfResource) { $sanitizedIdentifier = self::sanitizeCategoryName($value->getLabel()); } else { $sanitizedIdentifier = self::sanitizeCategoryName((string) $value); } if (Format::isIdentifier($sanitizedIdentifier)) { $categories[] = $sanitizedIdentifier; } } } } return $categories; }
/** * Retrieves information about the variable, including or not the related item $getItem (slower) * * @access public * @author Patrick Plichart, <*****@*****.**> * @param Resource variable * @param bool getItem retireve associated item reference * @return array simple associative */ public function getVariableData(core_kernel_classes_Resource $variable, $getItem = false) { $returnValue = array(); $baseTypes = $variable->getPropertyValues(new core_kernel_classes_Property(PROPERTY_VARIABLE_BASETYPE)); $baseType = current($baseTypes); if ($baseType != "file") { $propValues = $variable->getPropertiesValues(array(PROPERTY_IDENTIFIER, PROPERTY_VARIABLE_EPOCH, RDF_VALUE, PROPERTY_VARIABLE_CARDINALITY, PROPERTY_VARIABLE_BASETYPE)); $returnValue["value"] = (string) base64_decode(current($propValues[RDF_VALUE])); } else { $propValues = $variable->getPropertiesValues(array(PROPERTY_IDENTIFIER, PROPERTY_VARIABLE_EPOCH, PROPERTY_VARIABLE_CARDINALITY, PROPERTY_VARIABLE_BASETYPE)); $returnValue["value"] = ""; } $returnValue["identifier"] = current($propValues[PROPERTY_IDENTIFIER])->__toString(); $class = current($variable->getTypes()); $returnValue["type"] = $class; $returnValue["epoch"] = current($propValues[PROPERTY_VARIABLE_EPOCH])->__toString(); if (count($propValues[PROPERTY_VARIABLE_CARDINALITY]) > 0) { $returnValue["cardinality"] = current($propValues[PROPERTY_VARIABLE_CARDINALITY])->__toString(); } if (count($propValues[PROPERTY_VARIABLE_BASETYPE]) > 0) { $returnValue["basetype"] = current($propValues[PROPERTY_VARIABLE_BASETYPE])->__toString(); } if ($getItem) { $returnValue["item"] = $this->getItemFromVariable($variable); } return (array) $returnValue; }
/** * returns the nodes to open in order to display * all the listed resources to be visible * * @param array $resources list of resources to show * @param core_kernel_classes_Class $rootNode root node of the tree * @return array array of the uris of the nodes to open */ public static function getNodesToOpen($uris, core_kernel_classes_Class $rootNode) { // this array is in the form of // URI to test => array of uris that depend on the URI $toTest = array(); foreach ($uris as $uri) { $resource = new core_kernel_classes_Resource($uri); foreach ($resource->getTypes() as $type) { $toTest[$type->getUri()] = array(); } } $toOpen = array($rootNode->getUri()); while (!empty($toTest)) { reset($toTest); list($classUri, $depends) = each($toTest); unset($toTest[$classUri]); if (in_array($classUri, $toOpen)) { $toOpen = array_merge($toOpen, $depends); } else { $class = new core_kernel_classes_Class($classUri); foreach ($class->getParentClasses(false) as $parent) { if ($parent->getUri() == RDFS_CLASS) { continue; } if (!isset($toTest[$parent->getUri()])) { $toTest[$parent->getUri()] = array(); } $toTest[$parent->getUri()] = array_merge($toTest[$parent->getUri()], array($classUri), $depends); } } } return $toOpen; }
/** * Short description of method referenceResource * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource resource * @param string table * @param array types * @param boolean referenceClassLink * @return boolean */ public function referenceResource(\core_kernel_classes_Resource $resource, $table, $types = null, $referenceClassLink = false) { $returnValue = (bool) false; $types = !is_null($types) ? $types : $resource->getTypes(); $rows = array(); if (!$this->isResourceReferenced($resource)) { $dbWrapper = \core_kernel_classes_DbWrapper::singleton(); $query = 'INSERT INTO "resource_to_table" ("uri", "table") VALUES (?,?)'; $insertResult = $dbWrapper->exec($query, array($resource->getUri(), $table)); if ($referenceClassLink && $insertResult !== false) { $query = 'SELECT * FROM "resource_to_table" WHERE "uri" = ? AND "table" = ?'; $result = $dbWrapper->query($query, array($resource->getUri(), $table)); while ($row = $result->fetch(\PDO::FETCH_ASSOC)) { $rows[] = $row; } } $returnValue = (bool) $insertResult; if ($referenceClassLink) { foreach ($types as $type) { $typeClass = new \core_kernel_classes_Class($type->getUri()); if ($this->isClassReferenced($typeClass)) { $classLocations = $this->classLocations($typeClass); foreach ($classLocations as $classLocation) { foreach ($rows as $row) { $query = "INSERT INTO resource_has_class (resource_id, class_id) VALUES (?,?)"; $sth = $dbWrapper->exec($query, array($row['id'], $classLocation['id'])); } } } } } if ($returnValue) { foreach ($rows as $row) { self::$_resources[$row['uri']] = $row['table']; } ResourceProxy::singleton()->uncacheResource($resource); } } return (bool) $returnValue; }
/** * get the properties of an instance for a specific language * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Resource instance * @param string lang * @return array */ public function getTranslatedProperties(core_kernel_classes_Resource $instance, $lang) { $returnValue = array(); try { foreach ($instance->getTypes() as $clazz) { foreach ($clazz->getProperties(true) as $property) { if ($property->isLgDependent() || $property->getUri() == RDFS_LABEL) { $collection = $instance->getPropertyValuesByLg($property, $lang); if ($collection->count() > 0) { if ($collection->count() == 1) { $returnValue[$property->getUri()] = (string) $collection->get(0); } else { $propData = array(); foreach ($collection->getIterator() as $collectionItem) { $propData[] = (string) $collectionItem; } $returnValue[$property->getUri()] = $propData; } } } } } } catch (Exception $e) { print $e; } return (array) $returnValue; }
/** * Form to edit a user * User login must be set in parameter * @return void */ public function edit() { if (!$this->hasRequestParameter('uri')) { throw new Exception('Please set the user uri in request parameter'); } $user = new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri'))); $this->checkUser($user->getUri()); $types = $user->getTypes(); $myFormContainer = new tao_actions_form_Users(reset($types), $user); $myForm = $myFormContainer->getForm(); if ($myForm->isSubmited()) { if ($myForm->isValid()) { $values = $myForm->getValues(); if (!empty($values['password2']) && !empty($values['password3'])) { $values[PROPERTY_USER_PASSWORD] = core_kernel_users_Service::getPasswordHash()->encrypt($values['password2']); } unset($values['password2']); unset($values['password3']); if (!preg_match("/[A-Z]{2,4}\$/", trim($values[PROPERTY_USER_UILG]))) { unset($values[PROPERTY_USER_UILG]); } if (!preg_match("/[A-Z]{2,4}\$/", trim($values[PROPERTY_USER_DEFLG]))) { unset($values[PROPERTY_USER_DEFLG]); } $binder = new tao_models_classes_dataBinding_GenerisFormDataBinder($user); if ($binder->bind($values)) { $this->getEventManager()->trigger(new UserUpdatedEvent($user, $values)); $this->setData('message', __('User saved')); } } } $this->setData('formTitle', __('Edit a user')); $this->setData('myForm', $myForm->render()); $this->setView('user/form.tpl'); }
/** * Move an instance from a class to another * @return void * @requiresRight uri WRITE * @requiresRight destinationClassUri WRITE */ public function moveInstance() { $response = array(); if ($this->hasRequestParameter('destinationClassUri') && $this->hasRequestParameter('uri')) { $instance = new core_kernel_classes_Resource(tao_helpers_Uri::decode($this->getRequestParameter('uri'))); $types = $instance->getTypes(); $clazz = reset($types); $destinationUri = tao_helpers_Uri::decode($this->getRequestParameter('destinationClassUri')); if (!empty($destinationUri) && $destinationUri != $clazz->getUri()) { $destinationClass = new core_kernel_classes_Class($destinationUri); $confirmed = $this->getRequestParameter('confirmed'); if (empty($confirmed) || $confirmed == 'false' || $confirmed === false) { $diff = $this->getClassService()->getPropertyDiff($clazz, $destinationClass); if (count($diff) > 0) { return $this->returnJson(array('status' => 'diff', 'data' => $diff)); } } $status = $this->getClassService()->changeClass($instance, $destinationClass); $response = array('status' => $status); } } $this->returnJson($response); }