repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
oat-sa/tao-core | actions/class.PropertiesAuthoring.php | tao_actions_PropertiesAuthoring.addPropertyIndex | public function addPropertyIndex()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
if(!$this->hasRequestParameter('uri')){
throw new Exception("wrong request Parameter");
}
$uri = $this->getRequestParameter('uri');
$clazz = $this->getCurrentClass();
$index = 1;
if($this->hasRequestParameter('index')){
$index = $this->getRequestParameter('index');
}
$propertyIndex = 1;
if($this->hasRequestParameter('propertyIndex')){
$propertyIndex = $this->getRequestParameter('propertyIndex');
}
//create and attach the new index property to the property
$property = $this->getProperty(tao_helpers_Uri::decode($uri));
$class = $this->getClass("http://www.tao.lu/Ontologies/TAO.rdf#Index");
//get property range to select a default tokenizer
/** @var core_kernel_classes_Class $range */
$range = $property->getRange();
//range is empty select item content
$tokenizer = null;
if (is_null($range)) {
$tokenizer = $this->getResource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer');
} else {
$tokenizer = $range->getUri() === OntologyRdfs::RDFS_LITERAL
? $this->getResource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer')
: $this->getResource('http://www.tao.lu/Ontologies/TAO.rdf#LabelTokenizer');
}
$indexClass = $this->getClass('http://www.tao.lu/Ontologies/TAO.rdf#Index');
$i = 0;
$indexIdentifierBackup = preg_replace('/[^a-z_0-9]/','_',strtolower($property->getLabel()));
$indexIdentifierBackup = ltrim(trim($indexIdentifierBackup, '_'),'0..9');
$indexIdentifier = $indexIdentifierBackup;
do{
if($i !== 0){
$indexIdentifier = $indexIdentifierBackup.'_'.$i;
}
$resources = $indexClass->searchInstances(array(OntologyIndex::PROPERTY_INDEX_IDENTIFIER => $indexIdentifier), array('like' => false));
$count = count($resources);
$i++;
}while($count !== 0);
$indexProperty = $class->createInstanceWithProperties(array(
OntologyRdfs::RDFS_LABEL => preg_replace('/_/',' ',ucfirst($indexIdentifier)),
OntologyIndex::PROPERTY_INDEX_IDENTIFIER => $indexIdentifier,
OntologyIndex::PROPERTY_INDEX_TOKENIZER => $tokenizer,
OntologyIndex::PROPERTY_INDEX_FUZZY_MATCHING => GenerisRdf::GENERIS_TRUE,
OntologyIndex::PROPERTY_DEFAULT_SEARCH => GenerisRdf::GENERIS_FALSE,
));
$property->setPropertyValue($this->getProperty(OntologyIndex::PROPERTY_INDEX), $indexProperty);
//generate form
$indexFormContainer = new tao_actions_form_IndexProperty(new OntologyIndex($indexProperty), $propertyIndex.$index);
$myForm = $indexFormContainer->getForm();
$form = trim(preg_replace('/\s+/', ' ', $myForm->renderElements()));
$this->returnJson(array('form' => $form));
} | php | public function addPropertyIndex()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
if(!$this->hasRequestParameter('uri')){
throw new Exception("wrong request Parameter");
}
$uri = $this->getRequestParameter('uri');
$clazz = $this->getCurrentClass();
$index = 1;
if($this->hasRequestParameter('index')){
$index = $this->getRequestParameter('index');
}
$propertyIndex = 1;
if($this->hasRequestParameter('propertyIndex')){
$propertyIndex = $this->getRequestParameter('propertyIndex');
}
//create and attach the new index property to the property
$property = $this->getProperty(tao_helpers_Uri::decode($uri));
$class = $this->getClass("http://www.tao.lu/Ontologies/TAO.rdf#Index");
//get property range to select a default tokenizer
/** @var core_kernel_classes_Class $range */
$range = $property->getRange();
//range is empty select item content
$tokenizer = null;
if (is_null($range)) {
$tokenizer = $this->getResource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer');
} else {
$tokenizer = $range->getUri() === OntologyRdfs::RDFS_LITERAL
? $this->getResource('http://www.tao.lu/Ontologies/TAO.rdf#RawValueTokenizer')
: $this->getResource('http://www.tao.lu/Ontologies/TAO.rdf#LabelTokenizer');
}
$indexClass = $this->getClass('http://www.tao.lu/Ontologies/TAO.rdf#Index');
$i = 0;
$indexIdentifierBackup = preg_replace('/[^a-z_0-9]/','_',strtolower($property->getLabel()));
$indexIdentifierBackup = ltrim(trim($indexIdentifierBackup, '_'),'0..9');
$indexIdentifier = $indexIdentifierBackup;
do{
if($i !== 0){
$indexIdentifier = $indexIdentifierBackup.'_'.$i;
}
$resources = $indexClass->searchInstances(array(OntologyIndex::PROPERTY_INDEX_IDENTIFIER => $indexIdentifier), array('like' => false));
$count = count($resources);
$i++;
}while($count !== 0);
$indexProperty = $class->createInstanceWithProperties(array(
OntologyRdfs::RDFS_LABEL => preg_replace('/_/',' ',ucfirst($indexIdentifier)),
OntologyIndex::PROPERTY_INDEX_IDENTIFIER => $indexIdentifier,
OntologyIndex::PROPERTY_INDEX_TOKENIZER => $tokenizer,
OntologyIndex::PROPERTY_INDEX_FUZZY_MATCHING => GenerisRdf::GENERIS_TRUE,
OntologyIndex::PROPERTY_DEFAULT_SEARCH => GenerisRdf::GENERIS_FALSE,
));
$property->setPropertyValue($this->getProperty(OntologyIndex::PROPERTY_INDEX), $indexProperty);
//generate form
$indexFormContainer = new tao_actions_form_IndexProperty(new OntologyIndex($indexProperty), $propertyIndex.$index);
$myForm = $indexFormContainer->getForm();
$form = trim(preg_replace('/\s+/', ' ', $myForm->renderElements()));
$this->returnJson(array('form' => $form));
} | [
"public",
"function",
"addPropertyIndex",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wrong request mode'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->"... | Render the add index sub form.
@throws Exception
@throws common_exception_BadRequest
@return void | [
"Render",
"the",
"add",
"index",
"sub",
"form",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PropertiesAuthoring.php#L201-L269 |
oat-sa/tao-core | actions/class.PropertiesAuthoring.php | tao_actions_PropertiesAuthoring.getClassForm | public function getClassForm(core_kernel_classes_Class $clazz)
{
$propMode = 'simple';
if($this->hasSessionAttribute('property_mode')){
$propMode = $this->getSessionAttribute('property_mode');
}
$options = array(
'property_mode' => $propMode,
'topClazz' => $this->getClass(GenerisRdf::CLASS_GENERIS_RESOURCE)
);
$data = $this->getRequestParameters();
$formContainer = new tao_actions_form_Clazz($clazz, $this->extractClassData($data), $this->extractPropertyData($data), $propMode);
$myForm = $formContainer->getForm();
if($myForm->isSubmited()){
if($myForm->isValid()){
//get the data from parameters
// get class data and save them
if(isset($data['class'])){
$classValues = array();
foreach($data['class'] as $key => $value){
$classKey = tao_helpers_Uri::decode($key);
$classValues[$classKey] = tao_helpers_Uri::decode($value);
}
$this->bindProperties($clazz, $classValues);
}
//save all properties values
if(isset($data['properties'])){
foreach($data['properties'] as $i => $propertyValues) {
//get index values
$indexes = null;
if(isset($propertyValues['indexes'])){
$indexes = $propertyValues['indexes'];
unset($propertyValues['indexes']);
}
if($propMode === 'simple') {
$this->saveSimpleProperty($propertyValues);
} else {
$this->saveAdvProperty($propertyValues);
}
//save index
if(!is_null($indexes)){
foreach($indexes as $indexValues){
$this->savePropertyIndex($indexValues);
}
}
}
}
}
}
return $myForm;
} | php | public function getClassForm(core_kernel_classes_Class $clazz)
{
$propMode = 'simple';
if($this->hasSessionAttribute('property_mode')){
$propMode = $this->getSessionAttribute('property_mode');
}
$options = array(
'property_mode' => $propMode,
'topClazz' => $this->getClass(GenerisRdf::CLASS_GENERIS_RESOURCE)
);
$data = $this->getRequestParameters();
$formContainer = new tao_actions_form_Clazz($clazz, $this->extractClassData($data), $this->extractPropertyData($data), $propMode);
$myForm = $formContainer->getForm();
if($myForm->isSubmited()){
if($myForm->isValid()){
//get the data from parameters
// get class data and save them
if(isset($data['class'])){
$classValues = array();
foreach($data['class'] as $key => $value){
$classKey = tao_helpers_Uri::decode($key);
$classValues[$classKey] = tao_helpers_Uri::decode($value);
}
$this->bindProperties($clazz, $classValues);
}
//save all properties values
if(isset($data['properties'])){
foreach($data['properties'] as $i => $propertyValues) {
//get index values
$indexes = null;
if(isset($propertyValues['indexes'])){
$indexes = $propertyValues['indexes'];
unset($propertyValues['indexes']);
}
if($propMode === 'simple') {
$this->saveSimpleProperty($propertyValues);
} else {
$this->saveAdvProperty($propertyValues);
}
//save index
if(!is_null($indexes)){
foreach($indexes as $indexValues){
$this->savePropertyIndex($indexValues);
}
}
}
}
}
}
return $myForm;
} | [
"public",
"function",
"getClassForm",
"(",
"core_kernel_classes_Class",
"$",
"clazz",
")",
"{",
"$",
"propMode",
"=",
"'simple'",
";",
"if",
"(",
"$",
"this",
"->",
"hasSessionAttribute",
"(",
"'property_mode'",
")",
")",
"{",
"$",
"propMode",
"=",
"$",
"thi... | Create an edit form for a class and its property
and handle the submited data on save
@param core_kernel_classes_Class $clazz
@param core_kernel_classes_Resource $resource
@return tao_helpers_form_Form the generated form | [
"Create",
"an",
"edit",
"form",
"for",
"a",
"class",
"and",
"its",
"property",
"and",
"handle",
"the",
"submited",
"data",
"on",
"save"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PropertiesAuthoring.php#L311-L367 |
oat-sa/tao-core | actions/class.PropertiesAuthoring.php | tao_actions_PropertiesAuthoring.saveSimpleProperty | protected function saveSimpleProperty($propertyValues)
{
$propertyMap = tao_helpers_form_GenerisFormFactory::getPropertyMap();
$property = $this->getProperty(tao_helpers_Uri::decode($propertyValues['uri']));
$type = $propertyValues['type'];
$range = (isset($propertyValues['range']) ? tao_helpers_Uri::decode(trim($propertyValues['range'])) : null);
unset($propertyValues['uri']);
unset($propertyValues['type']);
unset($propertyValues['range']);
$rangeNotEmpty = false;
$values = array(
ValidationRuleRegistry::PROPERTY_VALIDATION_RULE => array()
);
if (isset($propertyMap[$type])) {
$values[WidgetRdf::PROPERTY_WIDGET] = $propertyMap[$type]['widget'];
$rangeNotEmpty = ($propertyMap[$type]['range'] === OntologyRdfs::RDFS_RESOURCE );
}
foreach($propertyValues as $key => $value){
if (is_string($value)) {
$values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value);
} elseif (is_array($value)) {
$values[tao_helpers_Uri::decode($key)] = $value;
} else {
$this->logWarning('Unsuported value type '.gettype($value));
}
}
$rangeValidator = new tao_helpers_form_validators_NotEmpty(array('message' => __('Range field is required')));
if($rangeNotEmpty && !$rangeValidator->evaluate($range)){
throw new Exception($rangeValidator->getMessage());
}
$this->bindProperties($property, $values);
// set the range
$property->removePropertyValues($this->getProperty(OntologyRdfs::RDFS_RANGE));
if(!empty($range)) {
$property->setRange($this->getClass($range));
} elseif (isset($propertyMap[$type]) && !empty($propertyMap[$type]['range'])) {
$property->setRange($this->getClass($propertyMap[$type]['range']));
}
// set cardinality
if(isset($propertyMap[$type]['multiple'])) {
$property->setMultiple($propertyMap[$type]['multiple'] == GenerisRdf::GENERIS_TRUE);
}
} | php | protected function saveSimpleProperty($propertyValues)
{
$propertyMap = tao_helpers_form_GenerisFormFactory::getPropertyMap();
$property = $this->getProperty(tao_helpers_Uri::decode($propertyValues['uri']));
$type = $propertyValues['type'];
$range = (isset($propertyValues['range']) ? tao_helpers_Uri::decode(trim($propertyValues['range'])) : null);
unset($propertyValues['uri']);
unset($propertyValues['type']);
unset($propertyValues['range']);
$rangeNotEmpty = false;
$values = array(
ValidationRuleRegistry::PROPERTY_VALIDATION_RULE => array()
);
if (isset($propertyMap[$type])) {
$values[WidgetRdf::PROPERTY_WIDGET] = $propertyMap[$type]['widget'];
$rangeNotEmpty = ($propertyMap[$type]['range'] === OntologyRdfs::RDFS_RESOURCE );
}
foreach($propertyValues as $key => $value){
if (is_string($value)) {
$values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value);
} elseif (is_array($value)) {
$values[tao_helpers_Uri::decode($key)] = $value;
} else {
$this->logWarning('Unsuported value type '.gettype($value));
}
}
$rangeValidator = new tao_helpers_form_validators_NotEmpty(array('message' => __('Range field is required')));
if($rangeNotEmpty && !$rangeValidator->evaluate($range)){
throw new Exception($rangeValidator->getMessage());
}
$this->bindProperties($property, $values);
// set the range
$property->removePropertyValues($this->getProperty(OntologyRdfs::RDFS_RANGE));
if(!empty($range)) {
$property->setRange($this->getClass($range));
} elseif (isset($propertyMap[$type]) && !empty($propertyMap[$type]['range'])) {
$property->setRange($this->getClass($propertyMap[$type]['range']));
}
// set cardinality
if(isset($propertyMap[$type]['multiple'])) {
$property->setMultiple($propertyMap[$type]['multiple'] == GenerisRdf::GENERIS_TRUE);
}
} | [
"protected",
"function",
"saveSimpleProperty",
"(",
"$",
"propertyValues",
")",
"{",
"$",
"propertyMap",
"=",
"tao_helpers_form_GenerisFormFactory",
"::",
"getPropertyMap",
"(",
")",
";",
"$",
"property",
"=",
"$",
"this",
"->",
"getProperty",
"(",
"tao_helpers_Uri"... | Default property handling
@param array $propertyValues | [
"Default",
"property",
"handling"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PropertiesAuthoring.php#L374-L422 |
oat-sa/tao-core | actions/class.PropertiesAuthoring.php | tao_actions_PropertiesAuthoring.saveAdvProperty | protected function saveAdvProperty($propertyValues)
{
// might break using hard
$range = array();
foreach($propertyValues as $key => $value){
if(is_array($value)){
// set the range
foreach($value as $v){
$range[] = $this->getClass(tao_helpers_Uri::decode($v));
}
}
else{
$values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value);
}
}
//if label is empty
$validator = new tao_helpers_form_validators_NotEmpty(array('message' => __('Property\'s label field is required')));
if(!$validator->evaluate($values[OntologyRdfs::RDFS_LABEL])){
throw new Exception($validator->getMessage());
}
$property = $this->getProperty($values['uri']);
unset($values['uri']);
$property->removePropertyValues($this->getProperty(OntologyRdfs::RDFS_RANGE));
if(!empty($range)){
foreach($range as $r){
$property->setRange($r);
}
}
$this->bindProperties($property, $values);
} | php | protected function saveAdvProperty($propertyValues)
{
// might break using hard
$range = array();
foreach($propertyValues as $key => $value){
if(is_array($value)){
// set the range
foreach($value as $v){
$range[] = $this->getClass(tao_helpers_Uri::decode($v));
}
}
else{
$values[tao_helpers_Uri::decode($key)] = tao_helpers_Uri::decode($value);
}
}
//if label is empty
$validator = new tao_helpers_form_validators_NotEmpty(array('message' => __('Property\'s label field is required')));
if(!$validator->evaluate($values[OntologyRdfs::RDFS_LABEL])){
throw new Exception($validator->getMessage());
}
$property = $this->getProperty($values['uri']);
unset($values['uri']);
$property->removePropertyValues($this->getProperty(OntologyRdfs::RDFS_RANGE));
if(!empty($range)){
foreach($range as $r){
$property->setRange($r);
}
}
$this->bindProperties($property, $values);
} | [
"protected",
"function",
"saveAdvProperty",
"(",
"$",
"propertyValues",
")",
"{",
"// might break using hard",
"$",
"range",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"propertyValues",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_... | Advanced property handling
@param array $propertyValues | [
"Advanced",
"property",
"handling"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PropertiesAuthoring.php#L429-L460 |
oat-sa/tao-core | actions/class.PropertiesAuthoring.php | tao_actions_PropertiesAuthoring.bindProperties | protected function bindProperties(core_kernel_classes_Resource $resource, $values)
{
$binder = new tao_models_classes_dataBinding_GenerisInstanceDataBinder($resource);
$binder->bind($values);
} | php | protected function bindProperties(core_kernel_classes_Resource $resource, $values)
{
$binder = new tao_models_classes_dataBinding_GenerisInstanceDataBinder($resource);
$binder->bind($values);
} | [
"protected",
"function",
"bindProperties",
"(",
"core_kernel_classes_Resource",
"$",
"resource",
",",
"$",
"values",
")",
"{",
"$",
"binder",
"=",
"new",
"tao_models_classes_dataBinding_GenerisInstanceDataBinder",
"(",
"$",
"resource",
")",
";",
"$",
"binder",
"->",
... | Helper to save class and properties
@param core_kernel_classes_Resource $resource
@param array $values | [
"Helper",
"to",
"save",
"class",
"and",
"properties"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PropertiesAuthoring.php#L493-L497 |
oat-sa/tao-core | actions/class.PropertiesAuthoring.php | tao_actions_PropertiesAuthoring.extractClassData | protected function extractClassData($data)
{
$classData = array();
if (isset($data['class'])) {
foreach ($data['class'] as $key => $value) {
$classData['class_'.$key] = $value;
}
}
return $classData;
} | php | protected function extractClassData($data)
{
$classData = array();
if (isset($data['class'])) {
foreach ($data['class'] as $key => $value) {
$classData['class_'.$key] = $value;
}
}
return $classData;
} | [
"protected",
"function",
"extractClassData",
"(",
"$",
"data",
")",
"{",
"$",
"classData",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'class'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"[",
"'class'",
"]",
"as"... | Extracts the data assoicuated with the class from the request
@param array $data
@return array | [
"Extracts",
"the",
"data",
"assoicuated",
"with",
"the",
"class",
"from",
"the",
"request"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PropertiesAuthoring.php#L505-L514 |
oat-sa/tao-core | actions/class.PropertiesAuthoring.php | tao_actions_PropertiesAuthoring.extractPropertyData | protected function extractPropertyData($data)
{
$propertyData = array();
if (isset($data['properties'])) {
foreach ($data['properties'] as $key => $value) {
$propertyData[tao_helpers_Uri::decode($value['uri'])] = $value;
}
}
return $propertyData;
} | php | protected function extractPropertyData($data)
{
$propertyData = array();
if (isset($data['properties'])) {
foreach ($data['properties'] as $key => $value) {
$propertyData[tao_helpers_Uri::decode($value['uri'])] = $value;
}
}
return $propertyData;
} | [
"protected",
"function",
"extractPropertyData",
"(",
"$",
"data",
")",
"{",
"$",
"propertyData",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'properties'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"[",
"'properties'... | Extracts the properties data from the request data, and formats
it as an array with the keys being the property URI and the values
being the associated data
@param array $data
@return array | [
"Extracts",
"the",
"properties",
"data",
"from",
"the",
"request",
"data",
"and",
"formats",
"it",
"as",
"an",
"array",
"with",
"the",
"keys",
"being",
"the",
"property",
"URI",
"and",
"the",
"values",
"being",
"the",
"associated",
"data"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PropertiesAuthoring.php#L524-L533 |
oat-sa/tao-core | models/classes/resources/ResourceService.php | ResourceService.getAllClasses | public function getAllClasses(core_kernel_classes_Class $rootClass)
{
$result = [
'uri' => $rootClass->getUri(),
'label' => $rootClass->getLabel(),
'children' => $this->getSubClasses($rootClass->getSubClasses(false))
];
return $result;
} | php | public function getAllClasses(core_kernel_classes_Class $rootClass)
{
$result = [
'uri' => $rootClass->getUri(),
'label' => $rootClass->getLabel(),
'children' => $this->getSubClasses($rootClass->getSubClasses(false))
];
return $result;
} | [
"public",
"function",
"getAllClasses",
"(",
"core_kernel_classes_Class",
"$",
"rootClass",
")",
"{",
"$",
"result",
"=",
"[",
"'uri'",
"=>",
"$",
"rootClass",
"->",
"getUri",
"(",
")",
",",
"'label'",
"=>",
"$",
"rootClass",
"->",
"getLabel",
"(",
")",
","... | Get the list of classes from the given root class
@param core_kernel_classes_Class $rootClass the root class
@return array the classes hierarchy | [
"Get",
"the",
"list",
"of",
"classes",
"from",
"the",
"given",
"root",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceService.php#L54-L63 |
oat-sa/tao-core | models/classes/resources/ResourceService.php | ResourceService.getSubClasses | private function getSubClasses($subClasses)
{
$result = [];
foreach ($subClasses as $subClass) {
$children = $subClass->getSubClasses(false);
$entry = [
'uri' => $subClass->getUri(),
'label' => $subClass->getLabel()
];
if (count($children) > 0) {
$entry['children'] = $this->getSubClasses($children);
}
array_push($result, $entry);
}
return $result;
} | php | private function getSubClasses($subClasses)
{
$result = [];
foreach ($subClasses as $subClass) {
$children = $subClass->getSubClasses(false);
$entry = [
'uri' => $subClass->getUri(),
'label' => $subClass->getLabel()
];
if (count($children) > 0) {
$entry['children'] = $this->getSubClasses($children);
}
array_push($result, $entry);
}
return $result;
} | [
"private",
"function",
"getSubClasses",
"(",
"$",
"subClasses",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"subClasses",
"as",
"$",
"subClass",
")",
"{",
"$",
"children",
"=",
"$",
"subClass",
"->",
"getSubClasses",
"(",
"false",
... | Get the class subclasses
@return array the classes hierarchy | [
"Get",
"the",
"class",
"subclasses"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceService.php#L69-L86 |
oat-sa/tao-core | models/classes/resources/ResourceService.php | ResourceService.getResources | public function getResources(\core_kernel_classes_Class $rootClass, $format = 'list', $selectedUris = [], $search = '', $offset = 0, $limit = 30)
{
$propertyFilters = $this->getPropertyFilters($search);
$result = [];
$resourceLookup = $this->getResourceLookup($format);
if (!is_null($resourceLookup)) {
$result = $resourceLookup->getResources($rootClass, $selectedUris, $propertyFilters, $offset, $limit);
}
return $result;
} | php | public function getResources(\core_kernel_classes_Class $rootClass, $format = 'list', $selectedUris = [], $search = '', $offset = 0, $limit = 30)
{
$propertyFilters = $this->getPropertyFilters($search);
$result = [];
$resourceLookup = $this->getResourceLookup($format);
if (!is_null($resourceLookup)) {
$result = $resourceLookup->getResources($rootClass, $selectedUris, $propertyFilters, $offset, $limit);
}
return $result;
} | [
"public",
"function",
"getResources",
"(",
"\\",
"core_kernel_classes_Class",
"$",
"rootClass",
",",
"$",
"format",
"=",
"'list'",
",",
"$",
"selectedUris",
"=",
"[",
"]",
",",
"$",
"search",
"=",
"''",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"limit",
... | Retrieve the resources for the given parameters
@param \core_kernel_classes_Class $resourceClass the resource class
@param string $format the lookup format
@param string|array $search to filter by label if a string or provides the search filters
@param int $offset for paging
@param int $limit for paging
@return array the resources | [
"Retrieve",
"the",
"resources",
"for",
"the",
"given",
"parameters"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceService.php#L97-L108 |
oat-sa/tao-core | models/classes/resources/ResourceService.php | ResourceService.getResourcesPermissions | public function getResourcesPermissions(User $user, $resources)
{
$permissions = [];
if(!is_null($user)){
try {
$permissionManager = $this->getServiceManager()->get(PermissionInterface::SERVICE_ID);
$supportedRights = $permissionManager->getSupportedRights();
$permissions['supportedRights'] = $supportedRights;
if(count($supportedRights) > 0){
$uris = $this->getUris($resources);
$permissions['data'] = $permissionManager->getPermissions($user, $uris);
}
} catch(\Exception $e){
\common_Logger::w('Unable to retrieve permssions ' . $e->getMessage());
}
}
return $permissions;
} | php | public function getResourcesPermissions(User $user, $resources)
{
$permissions = [];
if(!is_null($user)){
try {
$permissionManager = $this->getServiceManager()->get(PermissionInterface::SERVICE_ID);
$supportedRights = $permissionManager->getSupportedRights();
$permissions['supportedRights'] = $supportedRights;
if(count($supportedRights) > 0){
$uris = $this->getUris($resources);
$permissions['data'] = $permissionManager->getPermissions($user, $uris);
}
} catch(\Exception $e){
\common_Logger::w('Unable to retrieve permssions ' . $e->getMessage());
}
}
return $permissions;
} | [
"public",
"function",
"getResourcesPermissions",
"(",
"User",
"$",
"user",
",",
"$",
"resources",
")",
"{",
"$",
"permissions",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"user",
")",
")",
"{",
"try",
"{",
"$",
"permissionManager",
"=",
... | Get the permissions for a list of resources.
@param User $user the user to check the permissions
@param array $resources the resources to get the permissions
@return array the available rights and the permissions per resource | [
"Get",
"the",
"permissions",
"for",
"a",
"list",
"of",
"resources",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceService.php#L139-L159 |
oat-sa/tao-core | models/classes/resources/ResourceService.php | ResourceService.getPropertyFilters | private function getPropertyFilters($search = '')
{
$propertyFilters = [];
if(is_string($search) && strlen(trim($search)) > 0){
$propertyFilters[self::LABEL_URI] = $search;
}
if(is_array($search)){
foreach($search as $uri => $value){
if( is_string($uri) &&
(is_string($value) && strlen(trim($value)) > 0) ||
(is_array($value) && count($value) > 0) ) {
$propertyFilters[$uri] = $value;
}
}
}
return $propertyFilters;
} | php | private function getPropertyFilters($search = '')
{
$propertyFilters = [];
if(is_string($search) && strlen(trim($search)) > 0){
$propertyFilters[self::LABEL_URI] = $search;
}
if(is_array($search)){
foreach($search as $uri => $value){
if( is_string($uri) &&
(is_string($value) && strlen(trim($value)) > 0) ||
(is_array($value) && count($value) > 0) ) {
$propertyFilters[$uri] = $value;
}
}
}
return $propertyFilters;
} | [
"private",
"function",
"getPropertyFilters",
"(",
"$",
"search",
"=",
"''",
")",
"{",
"$",
"propertyFilters",
"=",
"[",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"search",
")",
"&&",
"strlen",
"(",
"trim",
"(",
"$",
"search",
")",
")",
">",
"0",
... | Get the filters based on the search param
@param string|array $search to filter by label if a string or provides the search filters
@return array the list of property filters | [
"Get",
"the",
"filters",
"based",
"on",
"the",
"search",
"param"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceService.php#L167-L184 |
oat-sa/tao-core | models/classes/resources/ResourceService.php | ResourceService.getResourceLookup | private function getResourceLookup($format)
{
if(in_array($format, self::$formats)){
if(!isset($this->lookups)){
$this->lookups = [
'list' => $this->getServiceManager()->get(ListResourceLookup::SERVICE_ID),
'tree' => $this->getServiceManager()->get(TreeResourceLookup::SERVICE_ID)
];
}
return $this->lookups[$format];
}
return null;
} | php | private function getResourceLookup($format)
{
if(in_array($format, self::$formats)){
if(!isset($this->lookups)){
$this->lookups = [
'list' => $this->getServiceManager()->get(ListResourceLookup::SERVICE_ID),
'tree' => $this->getServiceManager()->get(TreeResourceLookup::SERVICE_ID)
];
}
return $this->lookups[$format];
}
return null;
} | [
"private",
"function",
"getResourceLookup",
"(",
"$",
"format",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"format",
",",
"self",
"::",
"$",
"formats",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"lookups",
")",
")",
"{",
"$",
... | Get the resource lookup for the given format
@return ResourceLookup or null | [
"Get",
"the",
"resource",
"lookup",
"for",
"the",
"given",
"format"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceService.php#L190-L202 |
oat-sa/tao-core | models/classes/resources/ResourceService.php | ResourceService.getUris | private function getUris($nodes)
{
$uris = [];
if ($nodes instanceof core_kernel_classes_Resource) {
$uris[] = $nodes->getUri();
}
if(is_array($nodes)){
//legacy format
if (isset($nodes['attributes']['data-uri'])) {
$uris[] = $nodes['attributes']['data-uri'];
}
if (isset($nodes['uri'])) {
$uris[] = $nodes['uri'];
}
$treeKeys = array_keys($nodes);
if (isset($treeKeys[0]) && is_int($treeKeys[0])) {
foreach ($nodes as $node) {
$uris = array_merge($uris, $this->getUris($node));
}
}
if (isset($nodes['children'])) {
$uris = array_merge($uris, $this->getUris($nodes['children']));
}
}
return $uris;
} | php | private function getUris($nodes)
{
$uris = [];
if ($nodes instanceof core_kernel_classes_Resource) {
$uris[] = $nodes->getUri();
}
if(is_array($nodes)){
//legacy format
if (isset($nodes['attributes']['data-uri'])) {
$uris[] = $nodes['attributes']['data-uri'];
}
if (isset($nodes['uri'])) {
$uris[] = $nodes['uri'];
}
$treeKeys = array_keys($nodes);
if (isset($treeKeys[0]) && is_int($treeKeys[0])) {
foreach ($nodes as $node) {
$uris = array_merge($uris, $this->getUris($node));
}
}
if (isset($nodes['children'])) {
$uris = array_merge($uris, $this->getUris($nodes['children']));
}
}
return $uris;
} | [
"private",
"function",
"getUris",
"(",
"$",
"nodes",
")",
"{",
"$",
"uris",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"nodes",
"instanceof",
"core_kernel_classes_Resource",
")",
"{",
"$",
"uris",
"[",
"]",
"=",
"$",
"nodes",
"->",
"getUri",
"(",
")",
";",
... | Walk through the resources (recursively) to get theirs URIs
@param array|core_kernel_class_Resource $nodes the tree or a sub tree, a resource or a resource list
@return string[] the list of URIs | [
"Walk",
"through",
"the",
"resources",
"(",
"recursively",
")",
"to",
"get",
"theirs",
"URIs"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceService.php#L210-L241 |
oat-sa/tao-core | helpers/form/validators/class.IndexIdentifier.php | tao_helpers_form_validators_IndexIdentifier.evaluate | public function evaluate($values)
{
//evaluate identifier, starts with letter, contains letters, numbers and _, ends with letter, number
if(preg_match("/^[a-z]+[a-z_0-9]*$/", $values) === 1){
return true;
} else {
if (!$this->hasOption('message')) {
$message = empty($values)
? __('The index identifier should not be empty')
: __('"%s" is not a valid index identifier. It must start with a letter and contain letters, numbers or underscores only', $values)
;
$this->setMessage($message);
}
}
return false;
} | php | public function evaluate($values)
{
//evaluate identifier, starts with letter, contains letters, numbers and _, ends with letter, number
if(preg_match("/^[a-z]+[a-z_0-9]*$/", $values) === 1){
return true;
} else {
if (!$this->hasOption('message')) {
$message = empty($values)
? __('The index identifier should not be empty')
: __('"%s" is not a valid index identifier. It must start with a letter and contain letters, numbers or underscores only', $values)
;
$this->setMessage($message);
}
}
return false;
} | [
"public",
"function",
"evaluate",
"(",
"$",
"values",
")",
"{",
"//evaluate identifier, starts with letter, contains letters, numbers and _, ends with letter, number",
"if",
"(",
"preg_match",
"(",
"\"/^[a-z]+[a-z_0-9]*$/\"",
",",
"$",
"values",
")",
"===",
"1",
")",
"{",
... | evalute the identifier
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param values
@return boolean | [
"evalute",
"the",
"identifier"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/validators/class.IndexIdentifier.php#L41-L56 |
oat-sa/tao-core | helpers/form/elements/xhtml/class.Password.php | tao_helpers_form_elements_xhtml_Password.feed | public function feed()
{
if (isset($_POST[$this->name]) && is_array($_POST[$this->name])) {
$this->setValue(array_values($_POST[$this->name]));
}
} | php | public function feed()
{
if (isset($_POST[$this->name]) && is_array($_POST[$this->name])) {
$this->setValue(array_values($_POST[$this->name]));
}
} | [
"public",
"function",
"feed",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"name",
"]",
")",
"&&",
"is_array",
"(",
"$",
"_POST",
"[",
"$",
"this",
"->",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"setValue"... | Short description of method feed
@access public
@author Joel Bout, <joel.bout@tudor.lu> | [
"Short",
"description",
"of",
"method",
"feed"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/elements/xhtml/class.Password.php#L40-L45 |
oat-sa/tao-core | helpers/form/elements/xhtml/class.Password.php | tao_helpers_form_elements_xhtml_Password.render | public function render()
{
$returnValue = (string) '';
// custom label rendering
if (! isset($this->attributes['noLabel'])) {
$returnValue .= "<label class='form_desc' for='{$this->name}'>" . _dh($this->getDescription()) . (strlen($this->value) == 0 ? '' : ' (change)') . "</label>";
} else {
unset($this->attributes['noLabel']);
}
$returnValue .= "<input type='password' name='{$this->name}[]' id='{$this->name}' ";
$returnValue .= $this->renderAttributes();
$returnValue .= ' value="" /><br /><br />';
$returnValue .= "<label class='form_desc'></label>";
$returnValue .= "<input type='password' name='{$this->name}[]' id='{$this->name}' ";
$returnValue .= $this->renderAttributes();
$returnValue .= ' value="" />';
return (string) $returnValue;
} | php | public function render()
{
$returnValue = (string) '';
// custom label rendering
if (! isset($this->attributes['noLabel'])) {
$returnValue .= "<label class='form_desc' for='{$this->name}'>" . _dh($this->getDescription()) . (strlen($this->value) == 0 ? '' : ' (change)') . "</label>";
} else {
unset($this->attributes['noLabel']);
}
$returnValue .= "<input type='password' name='{$this->name}[]' id='{$this->name}' ";
$returnValue .= $this->renderAttributes();
$returnValue .= ' value="" /><br /><br />';
$returnValue .= "<label class='form_desc'></label>";
$returnValue .= "<input type='password' name='{$this->name}[]' id='{$this->name}' ";
$returnValue .= $this->renderAttributes();
$returnValue .= ' value="" />';
return (string) $returnValue;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"// custom label rendering",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'noLabel'",
"]",
")",
")",
"{",
"$",
"returnValue",
... | Short description of method render
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"render"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/elements/xhtml/class.Password.php#L54-L73 |
oat-sa/tao-core | helpers/form/elements/xhtml/class.Password.php | tao_helpers_form_elements_xhtml_Password.getEvaluatedValue | public function getEvaluatedValue()
{
$returnValue = null;
$arr = $this->getRawValue();
$returnValue = core_kernel_users_Service::getPasswordHash()->encrypt(array_shift($arr));
return $returnValue;
} | php | public function getEvaluatedValue()
{
$returnValue = null;
$arr = $this->getRawValue();
$returnValue = core_kernel_users_Service::getPasswordHash()->encrypt(array_shift($arr));
return $returnValue;
} | [
"public",
"function",
"getEvaluatedValue",
"(",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"$",
"arr",
"=",
"$",
"this",
"->",
"getRawValue",
"(",
")",
";",
"$",
"returnValue",
"=",
"core_kernel_users_Service",
"::",
"getPasswordHash",
"(",
")",
"->",
... | returns the md5 hash of the password
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return mixed | [
"returns",
"the",
"md5",
"hash",
"of",
"the",
"password"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/elements/xhtml/class.Password.php#L82-L90 |
oat-sa/tao-core | models/classes/theme/ThemeConverter.php | ThemeConverter.convertFromLegacyTheme | public static function convertFromLegacyTheme($theme)
{
if ($theme instanceof ConfigurablePlatformTheme) {
return $theme;
}
// older themes are stored as an instance, newer ones as array
if(is_array($theme)) {
if(empty($theme[ThemeServiceInterface::THEME_CLASS_OFFSET])) {
throw new \common_exception_MissingParameter(
ThemeServiceInterface::THEME_CLASS_OFFSET,
__METHOD__
);
}
$options = !empty($theme[ThemeServiceInterface::THEME_OPTIONS_OFFSET])
? $theme[ThemeServiceInterface::THEME_OPTIONS_OFFSET]
: []
;
$theme = new $theme[ThemeServiceInterface::THEME_CLASS_OFFSET]($options);
}
// list of all previously used templates
$templates = ['footer', 'header', 'header-logo', 'login-message'];
// all keys associated with a public getter from previously used theme classes
$getKeys = ['id', 'label', 'stylesheet', 'logoUrl', 'link', 'message', 'customTexts'];
// collect options
$options = [];
if (method_exists($theme, 'getOptions')) {
$options = $theme->getOptions();
}
if (method_exists($theme, 'getThemeData')) {
$options = array_merge($options, $theme->getThemeData());
}
unset($options['data']);
foreach ($getKeys as $key) {
$method = 'get' . ucfirst($key);
if (method_exists($theme, $method)) {
$options[$key] = $theme->{$method}();
}
}
// TAO default logo URL is different
if($theme instanceof DefaultTheme) {
$options['logoUrl'] = Template::img('tao-logo.png', 'tao');
}
if (method_exists($theme, 'getTemplate')) {
if (empty($options[ConfigurablePlatformTheme::TEMPLATES])) {
$options[ConfigurablePlatformTheme::TEMPLATES] = [];
}
foreach ($templates as $id) {
$template = $theme->getTemplate($id);
if(!is_null($template)) {
$options[ConfigurablePlatformTheme::TEMPLATES][$id] = $template;
}
}
}
// example: oat\taoExtension\model\theme\MyTheme
$themeClass = get_class($theme);
//@todo: map to container id
if (empty($options[ConfigurablePlatformTheme::EXTENSION_ID])) {
strtok($themeClass, '\\');
$options[ConfigurablePlatformTheme::EXTENSION_ID] = strtok('\\');
}
if (empty($options[ConfigurablePlatformTheme::LABEL])) {
$options[ConfigurablePlatformTheme::LABEL] = basename($themeClass);
}
return new ConfigurablePlatformTheme($options);
} | php | public static function convertFromLegacyTheme($theme)
{
if ($theme instanceof ConfigurablePlatformTheme) {
return $theme;
}
// older themes are stored as an instance, newer ones as array
if(is_array($theme)) {
if(empty($theme[ThemeServiceInterface::THEME_CLASS_OFFSET])) {
throw new \common_exception_MissingParameter(
ThemeServiceInterface::THEME_CLASS_OFFSET,
__METHOD__
);
}
$options = !empty($theme[ThemeServiceInterface::THEME_OPTIONS_OFFSET])
? $theme[ThemeServiceInterface::THEME_OPTIONS_OFFSET]
: []
;
$theme = new $theme[ThemeServiceInterface::THEME_CLASS_OFFSET]($options);
}
// list of all previously used templates
$templates = ['footer', 'header', 'header-logo', 'login-message'];
// all keys associated with a public getter from previously used theme classes
$getKeys = ['id', 'label', 'stylesheet', 'logoUrl', 'link', 'message', 'customTexts'];
// collect options
$options = [];
if (method_exists($theme, 'getOptions')) {
$options = $theme->getOptions();
}
if (method_exists($theme, 'getThemeData')) {
$options = array_merge($options, $theme->getThemeData());
}
unset($options['data']);
foreach ($getKeys as $key) {
$method = 'get' . ucfirst($key);
if (method_exists($theme, $method)) {
$options[$key] = $theme->{$method}();
}
}
// TAO default logo URL is different
if($theme instanceof DefaultTheme) {
$options['logoUrl'] = Template::img('tao-logo.png', 'tao');
}
if (method_exists($theme, 'getTemplate')) {
if (empty($options[ConfigurablePlatformTheme::TEMPLATES])) {
$options[ConfigurablePlatformTheme::TEMPLATES] = [];
}
foreach ($templates as $id) {
$template = $theme->getTemplate($id);
if(!is_null($template)) {
$options[ConfigurablePlatformTheme::TEMPLATES][$id] = $template;
}
}
}
// example: oat\taoExtension\model\theme\MyTheme
$themeClass = get_class($theme);
//@todo: map to container id
if (empty($options[ConfigurablePlatformTheme::EXTENSION_ID])) {
strtok($themeClass, '\\');
$options[ConfigurablePlatformTheme::EXTENSION_ID] = strtok('\\');
}
if (empty($options[ConfigurablePlatformTheme::LABEL])) {
$options[ConfigurablePlatformTheme::LABEL] = basename($themeClass);
}
return new ConfigurablePlatformTheme($options);
} | [
"public",
"static",
"function",
"convertFromLegacyTheme",
"(",
"$",
"theme",
")",
"{",
"if",
"(",
"$",
"theme",
"instanceof",
"ConfigurablePlatformTheme",
")",
"{",
"return",
"$",
"theme",
";",
"}",
"// older themes are stored as an instance, newer ones as array",
"if",... | Build an instance of ConfigurablePlatformTheme from a legacy theme
@param object|array $theme
@return ConfigurablePlatformTheme
@throws \common_exception_MissingParameter | [
"Build",
"an",
"instance",
"of",
"ConfigurablePlatformTheme",
"from",
"a",
"legacy",
"theme"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/theme/ThemeConverter.php#L46-L121 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.hasElement | public function hasElement($name)
{
foreach($this->elements as $element){
if($element->getName() == $name) {
return true;
}
}
return false;
} | php | public function hasElement($name)
{
foreach($this->elements as $element){
if($element->getName() == $name) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasElement",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName",
"(",
")",
"==",
"$",
"name",
")",
"{",
"return",
"true",
";",... | Has an element of the form identified by it's name
@param string $name
@return bool | [
"Has",
"an",
"element",
"of",
"the",
"form",
"identified",
"by",
"it",
"s",
"name"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L188-L197 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.getElement | public function getElement($name)
{
$returnValue = null;
foreach($this->elements as $element){
if($element->getName() == $name){
$returnValue = $element;
break;
}
}
if (is_null($returnValue)) {
common_Logger::w('Element with name \''.$name.'\' not found');
}
return $returnValue;
} | php | public function getElement($name)
{
$returnValue = null;
foreach($this->elements as $element){
if($element->getName() == $name){
$returnValue = $element;
break;
}
}
if (is_null($returnValue)) {
common_Logger::w('Element with name \''.$name.'\' not found');
}
return $returnValue;
} | [
"public",
"function",
"getElement",
"(",
"$",
"name",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName",
"(",
")",
"==",
"$",
"n... | get an element of the form identified by it's name
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $name
@return tao_helpers_form_FormElement | [
"get",
"an",
"element",
"of",
"the",
"form",
"identified",
"by",
"it",
"s",
"name"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L207-L225 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.removeElement | public function removeElement($name)
{
$returnValue = false;
foreach($this->elements as $index => $element){
if($element->getName() == $name){
unset($this->elements[$index]);
$groupName = $this->getElementGroup($name);
if(!empty($groupName)){
if(isset($this->groups[$groupName]['elements'][$name])){
unset($this->groups[$groupName]['elements'][$name]);
}
}
$returnValue = true;
}
}
return $returnValue;
} | php | public function removeElement($name)
{
$returnValue = false;
foreach($this->elements as $index => $element){
if($element->getName() == $name){
unset($this->elements[$index]);
$groupName = $this->getElementGroup($name);
if(!empty($groupName)){
if(isset($this->groups[$groupName]['elements'][$name])){
unset($this->groups[$groupName]['elements'][$name]);
}
}
$returnValue = true;
}
}
return $returnValue;
} | [
"public",
"function",
"removeElement",
"(",
"$",
"name",
")",
"{",
"$",
"returnValue",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"index",
"=>",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName",
"... | Remove an element identified by it's name.
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $name
@return boolean | [
"Remove",
"an",
"element",
"identified",
"by",
"it",
"s",
"name",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L259-L277 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.addElement | public function addElement( tao_helpers_form_FormElement $element, $isSystem = false)
{
$elementPosition = -1;
foreach($this->elements as $i => $elt){
if($elt->getName() == $element->getName()){
$elementPosition = $i;
break;
}
}
if($elementPosition >= 0){
$this->elements[$elementPosition] = $element;
}else{
$this->elements[] = $element;
}
if ($isSystem) {
$this->systemElements[] = $element->getName();
}
} | php | public function addElement( tao_helpers_form_FormElement $element, $isSystem = false)
{
$elementPosition = -1;
foreach($this->elements as $i => $elt){
if($elt->getName() == $element->getName()){
$elementPosition = $i;
break;
}
}
if($elementPosition >= 0){
$this->elements[$elementPosition] = $element;
}else{
$this->elements[] = $element;
}
if ($isSystem) {
$this->systemElements[] = $element->getName();
}
} | [
"public",
"function",
"addElement",
"(",
"tao_helpers_form_FormElement",
"$",
"element",
",",
"$",
"isSystem",
"=",
"false",
")",
"{",
"$",
"elementPosition",
"=",
"-",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"i",
"=>",
"$",
"... | Add an element to the form
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param tao_helpers_form_FormElement $element
@param bool|false $isSystem | [
"Add",
"an",
"element",
"to",
"the",
"form"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L287-L309 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.setActions | public function setActions($actions, $context = 'bottom')
{
$this->actions[$context] = array();
foreach($actions as $action){
if( ! $action instanceof tao_helpers_form_FormElement){
throw new Exception(" the actions parameter must only contains instances of tao_helpers_form_FormElement ");
}
$this->actions[$context][] = $action;
}
} | php | public function setActions($actions, $context = 'bottom')
{
$this->actions[$context] = array();
foreach($actions as $action){
if( ! $action instanceof tao_helpers_form_FormElement){
throw new Exception(" the actions parameter must only contains instances of tao_helpers_form_FormElement ");
}
$this->actions[$context][] = $action;
}
} | [
"public",
"function",
"setActions",
"(",
"$",
"actions",
",",
"$",
"context",
"=",
"'bottom'",
")",
"{",
"$",
"this",
"->",
"actions",
"[",
"$",
"context",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"action",
")",
... | Define the form actions for a context.
The different contexts are top and bottom.
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param array $actions
@param string $context
@throws Exception | [
"Define",
"the",
"form",
"actions",
"for",
"a",
"context",
".",
"The",
"different",
"contexts",
"are",
"top",
"and",
"bottom",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L323-L335 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.getActions | public function getActions($context = 'bottom')
{
$returnValue = array();
if(isset($this->actions[$context])){
$returnValue = $this->actions[$context];
}
return (array) $returnValue;
} | php | public function getActions($context = 'bottom')
{
$returnValue = array();
if(isset($this->actions[$context])){
$returnValue = $this->actions[$context];
}
return (array) $returnValue;
} | [
"public",
"function",
"getActions",
"(",
"$",
"context",
"=",
"'bottom'",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"actions",
"[",
"$",
"context",
"]",
")",
")",
"{",
"$",
"returnValue",
... | Get the defined actions for a context
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $context
@return array | [
"Get",
"the",
"defined",
"actions",
"for",
"a",
"context"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L345-L354 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.getAction | public function getAction($name, $context = 'bottom'){
foreach($this->getActions($context) as $element){
if($element->getName() == $name){
$returnValue = $element;
break;
}
}
if (is_null($returnValue)) {
common_Logger::w('Action with name \''.$name.'\' not found');
}
return $returnValue;
} | php | public function getAction($name, $context = 'bottom'){
foreach($this->getActions($context) as $element){
if($element->getName() == $name){
$returnValue = $element;
break;
}
}
if (is_null($returnValue)) {
common_Logger::w('Action with name \''.$name.'\' not found');
}
return $returnValue;
} | [
"public",
"function",
"getAction",
"(",
"$",
"name",
",",
"$",
"context",
"=",
"'bottom'",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getActions",
"(",
"$",
"context",
")",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName"... | Get specific action element from context
@param $name
@param string $context
@return mixed | [
"Get",
"specific",
"action",
"element",
"from",
"context",
"@param",
"$name",
"@param",
"string",
"$context"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L363-L376 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.setDecorators | public function setDecorators($decorators)
{
foreach($decorators as $type => $decorator){
$this->setDecorator($decorator, $type);
}
} | php | public function setDecorators($decorators)
{
foreach($decorators as $type => $decorator){
$this->setDecorator($decorator, $type);
}
} | [
"public",
"function",
"setDecorators",
"(",
"$",
"decorators",
")",
"{",
"foreach",
"(",
"$",
"decorators",
"as",
"$",
"type",
"=>",
"$",
"decorator",
")",
"{",
"$",
"this",
"->",
"setDecorator",
"(",
"$",
"decorator",
",",
"$",
"type",
")",
";",
"}",
... | Set the form decorators
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param array decorators
@return mixed | [
"Set",
"the",
"form",
"decorators"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L405-L410 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.getDecorator | public function getDecorator($type = 'element')
{
$returnValue = null;
if(array_key_exists($type, $this->decorators)){
$returnValue = $this->decorators[$type];
}
return $returnValue;
} | php | public function getDecorator($type = 'element')
{
$returnValue = null;
if(array_key_exists($type, $this->decorators)){
$returnValue = $this->decorators[$type];
}
return $returnValue;
} | [
"public",
"function",
"getDecorator",
"(",
"$",
"type",
"=",
"'element'",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"decorators",
")",
")",
"{",
"$",
"returnValue",
"=",
"$"... | Get the decorator of the type defined in parameter.
The different types are element, error, group.
By default it uses the element decorator.
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $type
@return tao_helpers_form_Decorator | [
"Get",
"the",
"decorator",
"of",
"the",
"type",
"defined",
"in",
"parameter",
".",
"The",
"different",
"types",
"are",
"element",
"error",
"group",
".",
"By",
"default",
"it",
"uses",
"the",
"element",
"decorator",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L422-L433 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.renderElements | public function renderElements()
{
$returnValue = '';
foreach($this->elements as $element){
if($this->getElementGroup($element->getName()) !== ''){
continue; //render grouped elements after
}
if(!is_null($this->getDecorator()) && !($element instanceof tao_helpers_form_elements_Hidden)){
$returnValue .= $this->getDecorator()->preRender();
}
if(!$this->isValid() && $element->getError()) {
$element->addClass('error');
}
//render element
$returnValue .= $element->render();
//render element help
$help = trim($element->getHelp());
if(!empty($help)){
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->preRender();
}
$returnValue .= $help;
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->postRender();
}
}
//render error message
if(!$this->isValid() && $element->getError()){
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->preRender();
}
$returnValue .= nl2br($element->getError());
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->postRender();
}
}
if(!is_null($this->getDecorator()) && !($element instanceof tao_helpers_form_elements_Hidden)){
$returnValue .= $this->getDecorator()->postRender();
}
}
$subGroupDecorator = null;
if(!is_null($this->getDecorator('group'))){
$decoratorClass = get_class($this->getDecorator('group'));
$subGroupDecorator = new $decoratorClass();
}
//render group
foreach($this->groups as $groupName => $group){
if(!is_null($this->getDecorator('group'))){
$this->getDecorator('group')->setOption('id', $groupName);
if(isset($group['options'])){
if(isset($group['options']['class'])){
$currentClasses = array_map('trim', explode(' ',$this->getDecorator('group')->getOption('cssClass')));
if(!in_array($group['options']['class'], $currentClasses)){
$currentClasses[] = $group['options']['class'];
$this->getDecorator('group')->setOption('cssClass', implode(' ', array_unique($currentClasses)));
}
}
}
$returnValue .= $this->getDecorator('group')->preRender();
}
$returnValue .= $group['title'];
if(!is_null($subGroupDecorator)){
$returnValue .= $subGroupDecorator->preRender();
}
foreach($group['elements'] as $elementName){
if($this->getElementGroup($elementName) === $groupName && $element = $this->getElement( $elementName )){
if(!is_null($this->getDecorator())){// && !($element instanceof tao_helpers_form_elements_Hidden) ){
$returnValue .= $this->getDecorator()->preRender();
}
//render element
if ( ! $this->isValid() && $element->getError()) {
$element->addClass( 'error' );
}
$returnValue .= $element->render();
//render element help
$help = trim($element->getHelp());
if(!empty($help)){
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->preRender();
}
$returnValue .= $help;
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->postRender();
}
}
//render error message
if(!$this->isValid() && $element->getError()){
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->preRender();
}
$returnValue .= nl2br($element->getError());
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->postRender();
}
}
if(!is_null($this->getDecorator())){// && !($element instanceof tao_helpers_form_elements_Hidden) ){
$returnValue .= $this->getDecorator()->postRender();
}
}
}
if(!is_null($subGroupDecorator)){
$returnValue .= $subGroupDecorator->postRender();
}
if(!is_null($this->getDecorator('group'))){
$returnValue .= $this->getDecorator('group')->postRender();
$this->getDecorator('group')->setOption('id', '');
}
}
return $returnValue;
} | php | public function renderElements()
{
$returnValue = '';
foreach($this->elements as $element){
if($this->getElementGroup($element->getName()) !== ''){
continue; //render grouped elements after
}
if(!is_null($this->getDecorator()) && !($element instanceof tao_helpers_form_elements_Hidden)){
$returnValue .= $this->getDecorator()->preRender();
}
if(!$this->isValid() && $element->getError()) {
$element->addClass('error');
}
//render element
$returnValue .= $element->render();
//render element help
$help = trim($element->getHelp());
if(!empty($help)){
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->preRender();
}
$returnValue .= $help;
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->postRender();
}
}
//render error message
if(!$this->isValid() && $element->getError()){
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->preRender();
}
$returnValue .= nl2br($element->getError());
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->postRender();
}
}
if(!is_null($this->getDecorator()) && !($element instanceof tao_helpers_form_elements_Hidden)){
$returnValue .= $this->getDecorator()->postRender();
}
}
$subGroupDecorator = null;
if(!is_null($this->getDecorator('group'))){
$decoratorClass = get_class($this->getDecorator('group'));
$subGroupDecorator = new $decoratorClass();
}
//render group
foreach($this->groups as $groupName => $group){
if(!is_null($this->getDecorator('group'))){
$this->getDecorator('group')->setOption('id', $groupName);
if(isset($group['options'])){
if(isset($group['options']['class'])){
$currentClasses = array_map('trim', explode(' ',$this->getDecorator('group')->getOption('cssClass')));
if(!in_array($group['options']['class'], $currentClasses)){
$currentClasses[] = $group['options']['class'];
$this->getDecorator('group')->setOption('cssClass', implode(' ', array_unique($currentClasses)));
}
}
}
$returnValue .= $this->getDecorator('group')->preRender();
}
$returnValue .= $group['title'];
if(!is_null($subGroupDecorator)){
$returnValue .= $subGroupDecorator->preRender();
}
foreach($group['elements'] as $elementName){
if($this->getElementGroup($elementName) === $groupName && $element = $this->getElement( $elementName )){
if(!is_null($this->getDecorator())){// && !($element instanceof tao_helpers_form_elements_Hidden) ){
$returnValue .= $this->getDecorator()->preRender();
}
//render element
if ( ! $this->isValid() && $element->getError()) {
$element->addClass( 'error' );
}
$returnValue .= $element->render();
//render element help
$help = trim($element->getHelp());
if(!empty($help)){
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->preRender();
}
$returnValue .= $help;
if(!is_null($this->getDecorator('help'))){
$returnValue .= $this->getDecorator('help')->postRender();
}
}
//render error message
if(!$this->isValid() && $element->getError()){
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->preRender();
}
$returnValue .= nl2br($element->getError());
if(!is_null($this->getDecorator('error'))){
$returnValue .= $this->getDecorator('error')->postRender();
}
}
if(!is_null($this->getDecorator())){// && !($element instanceof tao_helpers_form_elements_Hidden) ){
$returnValue .= $this->getDecorator()->postRender();
}
}
}
if(!is_null($subGroupDecorator)){
$returnValue .= $subGroupDecorator->postRender();
}
if(!is_null($this->getDecorator('group'))){
$returnValue .= $this->getDecorator('group')->postRender();
$this->getDecorator('group')->setOption('id', '');
}
}
return $returnValue;
} | [
"public",
"function",
"renderElements",
"(",
")",
"{",
"$",
"returnValue",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getElementGroup",
"(",
"$",
"element",
"->",
"getNa... | render all the form elements
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@return string | [
"render",
"all",
"the",
"form",
"elements"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L442-L577 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.renderActions | public function renderActions($context = 'bottom')
{
$returnValue = (string) '';
if(isset($this->actions[$context])){
$decorator = null;
if(!is_null($this->getDecorator('actions-'.$context))){
$decorator = $this->getDecorator('actions-'.$context);
}
else if(!is_null($this->getDecorator('actions'))){
$decorator = $this->getDecorator('actions');
}
if(!is_null($decorator)){
$returnValue .= $decorator->preRender();
}
foreach($this->actions[$context] as $action){
$returnValue .= $action->render();
}
if(!is_null($decorator)){
$returnValue .= $decorator->postRender();
}
}
return (string) $returnValue;
} | php | public function renderActions($context = 'bottom')
{
$returnValue = (string) '';
if(isset($this->actions[$context])){
$decorator = null;
if(!is_null($this->getDecorator('actions-'.$context))){
$decorator = $this->getDecorator('actions-'.$context);
}
else if(!is_null($this->getDecorator('actions'))){
$decorator = $this->getDecorator('actions');
}
if(!is_null($decorator)){
$returnValue .= $decorator->preRender();
}
foreach($this->actions[$context] as $action){
$returnValue .= $action->render();
}
if(!is_null($decorator)){
$returnValue .= $decorator->postRender();
}
}
return (string) $returnValue;
} | [
"public",
"function",
"renderActions",
"(",
"$",
"context",
"=",
"'bottom'",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"actions",
"[",
"$",
"context",
"]",
")",
")",
"{",
"$",
"dec... | render the form actions by context
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $context
@return string | [
"render",
"the",
"form",
"actions",
"by",
"context"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L587-L618 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.hasFileUpload | public function hasFileUpload()
{
$returnValue = false;
foreach($this->elements as $element){
if($element instanceof tao_helpers_form_elements_File){
$returnValue = true;
break;
}
}
return $returnValue;
} | php | public function hasFileUpload()
{
$returnValue = false;
foreach($this->elements as $element){
if($element instanceof tao_helpers_form_elements_File){
$returnValue = true;
break;
}
}
return $returnValue;
} | [
"public",
"function",
"hasFileUpload",
"(",
")",
"{",
"$",
"returnValue",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"tao_helpers_form_elements_File",
")",
"{",
... | Check if the form contains a file upload element
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@return boolean | [
"Check",
"if",
"the",
"form",
"contains",
"a",
"file",
"upload",
"element"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L640-L652 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.setValues | public function setValues($values)
{
foreach($values as $key => $value){
foreach($this->elements as $element){
if($element->getName() == $key){
if( $element instanceof tao_helpers_form_elements_Checkbox ||
(method_exists($element, 'setValues') && is_array($value)) ){
$element->setValues($value);
}
else{
$element->setValue($value);
}
break;
}
}
}
} | php | public function setValues($values)
{
foreach($values as $key => $value){
foreach($this->elements as $element){
if($element->getName() == $key){
if( $element instanceof tao_helpers_form_elements_Checkbox ||
(method_exists($element, 'setValues') && is_array($value)) ){
$element->setValues($value);
}
else{
$element->setValue($value);
}
break;
}
}
}
} | [
"public",
"function",
"setValues",
"(",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element"... | Update manually the values of the form
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param array $values | [
"Update",
"manually",
"the",
"values",
"of",
"the",
"form"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L685-L704 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.getValue | public function getValue($name)
{
foreach($this->elements as $element){
if($element->getName() == $name){
return $element->getEvaluatedValue();
}
}
return false;
} | php | public function getValue($name)
{
foreach($this->elements as $element){
if($element->getName() == $name){
return $element->getEvaluatedValue();
}
}
return false;
} | [
"public",
"function",
"getValue",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName",
"(",
")",
"==",
"$",
"name",
")",
"{",
"return",
"$",
"element"... | get the current value of the element identified by the name in parameter
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $name
@return boolean | [
"get",
"the",
"current",
"value",
"of",
"the",
"element",
"identified",
"by",
"the",
"name",
"in",
"parameter"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L724-L733 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.createGroup | public function createGroup($groupName, $groupTitle = '', array $elements = array(), array $options = array())
{
$identifier = array();
foreach ($elements as $element) {
if ($element instanceof tao_helpers_form_FormElement) {
$identifier[] = $element->getName();
} elseif (is_string($element)) {
$identifier[] = $element;
} else {
throw new common_Exception('Unknown element of type '.gettype($element).' in '.__FUNCTION__);
}
}
$this->groups[$groupName] = array(
'title' => (empty($groupTitle)) ? $groupName : $groupTitle,
'elements' => $identifier,
'options' => $options
);
} | php | public function createGroup($groupName, $groupTitle = '', array $elements = array(), array $options = array())
{
$identifier = array();
foreach ($elements as $element) {
if ($element instanceof tao_helpers_form_FormElement) {
$identifier[] = $element->getName();
} elseif (is_string($element)) {
$identifier[] = $element;
} else {
throw new common_Exception('Unknown element of type '.gettype($element).' in '.__FUNCTION__);
}
}
$this->groups[$groupName] = array(
'title' => (empty($groupTitle)) ? $groupName : $groupTitle,
'elements' => $identifier,
'options' => $options
);
} | [
"public",
"function",
"createGroup",
"(",
"$",
"groupName",
",",
"$",
"groupTitle",
"=",
"''",
",",
"array",
"$",
"elements",
"=",
"array",
"(",
")",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"identifier",
"=",
"array",
"("... | Create a logical group of elements
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $groupName
@param string $groupTitle
@param array $elements array of form elements or their identifiers
@param array $options
@return mixed
@throws common_Exception | [
"Create",
"a",
"logical",
"group",
"of",
"elements"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L772-L789 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.addToGroup | public function addToGroup($groupName, $elementName = '')
{
if(isset($this->groups[$groupName])){
if(isset($this->groups[$groupName]['elements'])){
if(!in_array($elementName, $this->groups[$groupName]['elements'])){
$this->groups[$groupName]['elements'][] = $elementName;
}
}
}
} | php | public function addToGroup($groupName, $elementName = '')
{
if(isset($this->groups[$groupName])){
if(isset($this->groups[$groupName]['elements'])){
if(!in_array($elementName, $this->groups[$groupName]['elements'])){
$this->groups[$groupName]['elements'][] = $elementName;
}
}
}
} | [
"public",
"function",
"addToGroup",
"(",
"$",
"groupName",
",",
"$",
"elementName",
"=",
"''",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"groups",
"[",
"$",
"groupName",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
... | add an element to a group
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $groupName
@param string $elementName | [
"add",
"an",
"element",
"to",
"a",
"group"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L799-L810 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.getElementGroup | protected function getElementGroup($elementName)
{
$returnValue = '';
foreach($this->groups as $groupName => $group){
if(in_array($elementName, $group['elements'])){
$returnValue = $groupName;
break;
}
}
return $returnValue;
} | php | protected function getElementGroup($elementName)
{
$returnValue = '';
foreach($this->groups as $groupName => $group){
if(in_array($elementName, $group['elements'])){
$returnValue = $groupName;
break;
}
}
return $returnValue;
} | [
"protected",
"function",
"getElementGroup",
"(",
"$",
"elementName",
")",
"{",
"$",
"returnValue",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"groups",
"as",
"$",
"groupName",
"=>",
"$",
"group",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"elem... | get the group where is an element
@access protected
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $elementName
@return string | [
"get",
"the",
"group",
"where",
"is",
"an",
"element"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L820-L832 |
oat-sa/tao-core | helpers/form/class.Form.php | tao_helpers_form_Form.removeGroup | public function removeGroup($groupName)
{
if(isset($this->groups[$groupName])){
foreach($this->groups[$groupName]['elements'] as $element){
$this->removeElement($element);
}
unset($this->groups[$groupName]);
}
} | php | public function removeGroup($groupName)
{
if(isset($this->groups[$groupName])){
foreach($this->groups[$groupName]['elements'] as $element){
$this->removeElement($element);
}
unset($this->groups[$groupName]);
}
} | [
"public",
"function",
"removeGroup",
"(",
"$",
"groupName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"groups",
"[",
"$",
"groupName",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"groups",
"[",
"$",
"groupName",
"]",
"[",
"'e... | remove the group identified by the name in parameter
@access public
@author Cédric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string $groupName | [
"remove",
"the",
"group",
"identified",
"by",
"the",
"name",
"in",
"parameter"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/class.Form.php#L841-L851 |
oat-sa/tao-core | install/class.ExtensionUninstaller.php | tao_install_ExtensionUninstaller.extendedUninstall | public function extendedUninstall() {
foreach ($this->extension->getManifest()->getAclTable() as $tableEntry) {
$rule = new AccessRule($tableEntry[0], $tableEntry[1], $tableEntry[2]);
AclProxy::revokeRule($rule);
}
} | php | public function extendedUninstall() {
foreach ($this->extension->getManifest()->getAclTable() as $tableEntry) {
$rule = new AccessRule($tableEntry[0], $tableEntry[1], $tableEntry[2]);
AclProxy::revokeRule($rule);
}
} | [
"public",
"function",
"extendedUninstall",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"extension",
"->",
"getManifest",
"(",
")",
"->",
"getAclTable",
"(",
")",
"as",
"$",
"tableEntry",
")",
"{",
"$",
"rule",
"=",
"new",
"AccessRule",
"(",
"$",
... | Uninstall all access rules
@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@return void
@since 2.4 | [
"Uninstall",
"all",
"access",
"rules"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/install/class.ExtensionUninstaller.php#L48-L53 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.validateInstanceRoot | protected function validateInstanceRoot($uri)
{
$instance = $this->getResource($uri);
$root = $this->getRootClass();
if ($instance->isClass()) {
$class = new core_kernel_classes_Class($instance->getUri());
if (!($class->isSubClassOf($root) || $class->equals($root))) {
throw new SecurityException(
sprintf(
'Security issue: class %s is not a subclass of %s',
$instance->getLabel(),
$root->getLabel()
)
);
}
return;
}
if (!$instance->isInstanceOf($root)) {
throw new SecurityException(sprintf(
'Security issue: instance %s is not a child of %s',
$instance->getLabel(),
$root->getLabel()
));
}
} | php | protected function validateInstanceRoot($uri)
{
$instance = $this->getResource($uri);
$root = $this->getRootClass();
if ($instance->isClass()) {
$class = new core_kernel_classes_Class($instance->getUri());
if (!($class->isSubClassOf($root) || $class->equals($root))) {
throw new SecurityException(
sprintf(
'Security issue: class %s is not a subclass of %s',
$instance->getLabel(),
$root->getLabel()
)
);
}
return;
}
if (!$instance->isInstanceOf($root)) {
throw new SecurityException(sprintf(
'Security issue: instance %s is not a child of %s',
$instance->getLabel(),
$root->getLabel()
));
}
} | [
"protected",
"function",
"validateInstanceRoot",
"(",
"$",
"uri",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"getResource",
"(",
"$",
"uri",
")",
";",
"$",
"root",
"=",
"$",
"this",
"->",
"getRootClass",
"(",
")",
";",
"if",
"(",
"$",
"instan... | @param string $uri
@throws common_exception_Error
@throws SecurityException | [
"@param",
"string",
"$uri"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L87-L116 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.isLocked | protected function isLocked($resource, $view = null){
$lock = LockManager::getImplementation()->getLockData($resource);
if (!is_null($lock) && $lock->getOwnerId() != $this->getSession()->getUser()->getIdentifier()) {
//if (LockManager::getImplementation()->isLocked($resource)) {
$params = array(
'id' => $resource->getUri(),
'topclass-label' => $this->getRootClass()->getLabel()
);
if (!is_null($view)) {
$params['view'] = $view;
$params['ext'] = Context::getInstance()->getExtensionName();
}
$this->forward('locked', 'Lock', 'tao', $params);
}
return false;
} | php | protected function isLocked($resource, $view = null){
$lock = LockManager::getImplementation()->getLockData($resource);
if (!is_null($lock) && $lock->getOwnerId() != $this->getSession()->getUser()->getIdentifier()) {
//if (LockManager::getImplementation()->isLocked($resource)) {
$params = array(
'id' => $resource->getUri(),
'topclass-label' => $this->getRootClass()->getLabel()
);
if (!is_null($view)) {
$params['view'] = $view;
$params['ext'] = Context::getInstance()->getExtensionName();
}
$this->forward('locked', 'Lock', 'tao', $params);
}
return false;
} | [
"protected",
"function",
"isLocked",
"(",
"$",
"resource",
",",
"$",
"view",
"=",
"null",
")",
"{",
"$",
"lock",
"=",
"LockManager",
"::",
"getImplementation",
"(",
")",
"->",
"getLockData",
"(",
"$",
"resource",
")",
";",
"if",
"(",
"!",
"is_null",
"(... | If you want strictly to check if the resource is locked,
you should use LockManager::getImplementation()->isLocked($resource)
Controller level convenience method to check if @resource is being locked, prepare data ans sets view,
@param core_kernel_classes_Resource $resource
@param $view
@return boolean | [
"If",
"you",
"want",
"strictly",
"to",
"check",
"if",
"the",
"resource",
"is",
"locked",
"you",
"should",
"use",
"LockManager",
"::",
"getImplementation",
"()",
"-",
">",
"isLocked",
"(",
"$resource",
")",
"Controller",
"level",
"convenience",
"method",
"to",
... | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L135-L151 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.getCurrentInstance | protected function getCurrentInstance($parameterName = 'uri')
{
$uri = tao_helpers_Uri::decode($this->getRequestParameter($parameterName));
$this->validateUri($uri);
return $this->getResource($uri);
} | php | protected function getCurrentInstance($parameterName = 'uri')
{
$uri = tao_helpers_Uri::decode($this->getRequestParameter($parameterName));
$this->validateUri($uri);
return $this->getResource($uri);
} | [
"protected",
"function",
"getCurrentInstance",
"(",
"$",
"parameterName",
"=",
"'uri'",
")",
"{",
"$",
"uri",
"=",
"tao_helpers_Uri",
"::",
"decode",
"(",
"$",
"this",
"->",
"getRequestParameter",
"(",
"$",
"parameterName",
")",
")",
";",
"$",
"this",
"->",
... | ! Please override me !
get the current instance regarding the uri and classUri in parameter
@param string $parameterName
@return core_kernel_classes_Resource
@throws tao_models_classes_MissingRequestParameterException | [
"!",
"Please",
"override",
"me",
"!",
"get",
"the",
"current",
"instance",
"regarding",
"the",
"uri",
"and",
"classUri",
"in",
"parameter",
"@param",
"string",
"$parameterName"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L192-L199 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.editClass | protected function editClass(core_kernel_classes_Class $clazz, core_kernel_classes_Resource $resource, core_kernel_classes_Class $topclass = null)
{
return $this->getClassForm($clazz, $resource, $topclass);
} | php | protected function editClass(core_kernel_classes_Class $clazz, core_kernel_classes_Resource $resource, core_kernel_classes_Class $topclass = null)
{
return $this->getClassForm($clazz, $resource, $topclass);
} | [
"protected",
"function",
"editClass",
"(",
"core_kernel_classes_Class",
"$",
"clazz",
",",
"core_kernel_classes_Resource",
"$",
"resource",
",",
"core_kernel_classes_Class",
"$",
"topclass",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getClassForm",
"(",
"$... | Deprecated alias for getClassForm
@deprecated | [
"Deprecated",
"alias",
"for",
"getClassForm"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L224-L227 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.getOntologyData | public function getOntologyData()
{
if (!$this->isXmlHttpRequest()) {
throw new common_exception_IsAjaxAction(__FUNCTION__);
}
$options = $this->getTreeOptionsFromRequest([]);
//generate the tree from the given parameters
$tree = $this->getClassService()->toTree($options['class'], $options);
//retrieve resources permissions
$user = \common_Session_SessionManager::getSession()->getUser();
$permissions = $this->getResourceService()->getResourcesPermissions($user, $tree);
//expose the tree
$this->returnJson([
'tree' => $tree,
'permissions' => $permissions
]);
} | php | public function getOntologyData()
{
if (!$this->isXmlHttpRequest()) {
throw new common_exception_IsAjaxAction(__FUNCTION__);
}
$options = $this->getTreeOptionsFromRequest([]);
//generate the tree from the given parameters
$tree = $this->getClassService()->toTree($options['class'], $options);
//retrieve resources permissions
$user = \common_Session_SessionManager::getSession()->getUser();
$permissions = $this->getResourceService()->getResourcesPermissions($user, $tree);
//expose the tree
$this->returnJson([
'tree' => $tree,
'permissions' => $permissions
]);
} | [
"public",
"function",
"getOntologyData",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_IsAjaxAction",
"(",
"__FUNCTION__",
")",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
... | Renders json data from the current ontology root class.
The possible request parameters are the following:
* uniqueNode: A URI indicating the returned hiearchy will be a single class, with a single children corresponding to the URI.
* browse:
* hideInstances:
* chunk:
* offset:
* limit:
* subclasses:
* classUri:
@return void
@requiresRight classUri READ | [
"Renders",
"json",
"data",
"from",
"the",
"current",
"ontology",
"root",
"class",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L265-L284 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.getTreeOptionsFromRequest | protected function getTreeOptionsFromRequest($options = [])
{
$options = array_merge([
'subclasses' => true,
'instances' => true,
'highlightUri' => '',
'chunk' => false,
'offset' => 0,
'limit' => 0
], $options);
if ($this->hasRequestParameter('loadNode')) {
$options['uniqueNode'] = $this->getRequestParameter('loadNode');
}
if ($this->hasRequestParameter("selected")) {
$options['browse'] = array($this->getRequestParameter("selected"));
}
if ($this->hasRequestParameter('hideInstances')) {
if((bool) $this->getRequestParameter('hideInstances')) {
$options['instances'] = false;
}
}
if ($this->hasRequestParameter('classUri')) {
$options['class'] = $this->getCurrentClass();
$options['chunk'] = !$options['class']->equals($this->getRootClass());
} else {
$options['class'] = $this->getRootClass();
}
if ($this->hasRequestParameter('offset')) {
$options['offset'] = $this->getRequestParameter('offset');
}
if ($this->hasRequestParameter('limit')) {
$options['limit'] = $this->getRequestParameter('limit');
}
if ($this->hasRequestParameter('order')) {
$options['order'] = tao_helpers_Uri::decode($this->getRequestParameter('order'));
}
if ($this->hasRequestParameter('orderdir')) {
$options['orderdir'] = $this->getRequestParameter('orderdir');
}
return $options;
} | php | protected function getTreeOptionsFromRequest($options = [])
{
$options = array_merge([
'subclasses' => true,
'instances' => true,
'highlightUri' => '',
'chunk' => false,
'offset' => 0,
'limit' => 0
], $options);
if ($this->hasRequestParameter('loadNode')) {
$options['uniqueNode'] = $this->getRequestParameter('loadNode');
}
if ($this->hasRequestParameter("selected")) {
$options['browse'] = array($this->getRequestParameter("selected"));
}
if ($this->hasRequestParameter('hideInstances')) {
if((bool) $this->getRequestParameter('hideInstances')) {
$options['instances'] = false;
}
}
if ($this->hasRequestParameter('classUri')) {
$options['class'] = $this->getCurrentClass();
$options['chunk'] = !$options['class']->equals($this->getRootClass());
} else {
$options['class'] = $this->getRootClass();
}
if ($this->hasRequestParameter('offset')) {
$options['offset'] = $this->getRequestParameter('offset');
}
if ($this->hasRequestParameter('limit')) {
$options['limit'] = $this->getRequestParameter('limit');
}
if ($this->hasRequestParameter('order')) {
$options['order'] = tao_helpers_Uri::decode($this->getRequestParameter('order'));
}
if ($this->hasRequestParameter('orderdir')) {
$options['orderdir'] = $this->getRequestParameter('orderdir');
}
return $options;
} | [
"protected",
"function",
"getTreeOptionsFromRequest",
"(",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'subclasses'",
"=>",
"true",
",",
"'instances'",
"=>",
"true",
",",
"'highlightUri'",
"=>",
"''",
",",
"'chunk'... | Get options to generate tree
@return array
@throws Exception | [
"Get",
"options",
"to",
"generate",
"tree"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L291-L338 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.addPermissions | protected function addPermissions($tree)
{
$user = $this->getSession()->getUser();
$section = MenuService::getSection(
$this->getRequestParameter('extension'),
$this->getRequestParameter('perspective'),
$this->getRequestParameter('section')
);
$actions = $section->getActions();
//then compute ACL for each node of the tree
$treeKeys = array_keys($tree);
if (isset($treeKeys[0]) && is_int($treeKeys[0])) {
foreach ($tree as $index => $treeNode) {
$tree[$index] = $this->computePermissions($actions, $user, $treeNode);
}
} else {
$tree = $this->computePermissions($actions, $user, $tree);
}
return $tree;
} | php | protected function addPermissions($tree)
{
$user = $this->getSession()->getUser();
$section = MenuService::getSection(
$this->getRequestParameter('extension'),
$this->getRequestParameter('perspective'),
$this->getRequestParameter('section')
);
$actions = $section->getActions();
//then compute ACL for each node of the tree
$treeKeys = array_keys($tree);
if (isset($treeKeys[0]) && is_int($treeKeys[0])) {
foreach ($tree as $index => $treeNode) {
$tree[$index] = $this->computePermissions($actions, $user, $treeNode);
}
} else {
$tree = $this->computePermissions($actions, $user, $tree);
}
return $tree;
} | [
"protected",
"function",
"addPermissions",
"(",
"$",
"tree",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"section",
"=",
"MenuService",
"::",
"getSection",
"(",
"$",
"this",
"->",
"getRequ... | Add permission information to the tree structure
@deprecated
@param array $tree
@return array | [
"Add",
"permission",
"information",
"to",
"the",
"tree",
"structure"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L348-L371 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.computePermissions | private function computePermissions($actions, $user, $node)
{
if (isset($node['attributes']['data-uri'])) {
if($node['type'] == 'class'){
$params = array('classUri' => $node['attributes']['data-uri']);
} else {
$params = array();
foreach ($node['attributes'] as $key => $value) {
if (substr($key, 0, strlen('data-')) == 'data-') {
$params[substr($key, strlen('data-'))] = $value;
}
}
}
$params['id'] = $node['attributes']['data-uri'];
$node['permissions'] = $this->getActionService()->computePermissions($actions, $user, $params);
}
if (isset($node['children'])) {
foreach($node['children'] as $index => $child){
$node['children'][$index] = $this->computePermissions($actions, $user, $child);
}
}
return $node;
} | php | private function computePermissions($actions, $user, $node)
{
if (isset($node['attributes']['data-uri'])) {
if($node['type'] == 'class'){
$params = array('classUri' => $node['attributes']['data-uri']);
} else {
$params = array();
foreach ($node['attributes'] as $key => $value) {
if (substr($key, 0, strlen('data-')) == 'data-') {
$params[substr($key, strlen('data-'))] = $value;
}
}
}
$params['id'] = $node['attributes']['data-uri'];
$node['permissions'] = $this->getActionService()->computePermissions($actions, $user, $params);
}
if (isset($node['children'])) {
foreach($node['children'] as $index => $child){
$node['children'][$index] = $this->computePermissions($actions, $user, $child);
}
}
return $node;
} | [
"private",
"function",
"computePermissions",
"(",
"$",
"actions",
",",
"$",
"user",
",",
"$",
"node",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"node",
"[",
"'attributes'",
"]",
"[",
"'data-uri'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"node",
"[",
"'ty... | compulte permissions for a node against actions
@deprecated
@param array[] $actions the actions data with context, name and the resolver
@param User $user the user
@param array $node a tree node
@return array the node augmented with permissions | [
"compulte",
"permissions",
"for",
"a",
"node",
"against",
"actions"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L383-L406 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.editClassLabel | public function editClassLabel()
{
$clazz = $this->getCurrentClass();
/** @var SignatureGenerator $signatureGenerator */
$signatureGenerator = ServiceManager::getServiceManager()->get(SignatureGenerator::class);
$signature = $signatureGenerator->generate(
tao_helpers_Uri::encode($this->getRequestParameter('classUri'))
);
$editClassLabelForm = new tao_actions_form_EditClassLabel(
$clazz,
$this->getRequestParameters(),
$signature
);
$myForm = $editClassLabelForm->getForm();
if ($myForm->isSubmited()) {
if ($myForm->isValid()) {
$clazz->setLabel($myForm->getValue(tao_helpers_Uri::encode(OntologyRdfs::RDFS_LABEL)));
$this->setData("selectNode", tao_helpers_Uri::encode($clazz->getUri()));
$this->setData('message', __('%s Class saved', $clazz->getLabel()));
$this->setData('reload', true);
}
}
$this->setData('formTitle', __('Edit class %s', \tao_helpers_Display::htmlize($clazz->getLabel())));
$this->setData('myForm', $myForm->render());
$this->setView('form.tpl', 'tao');
} | php | public function editClassLabel()
{
$clazz = $this->getCurrentClass();
/** @var SignatureGenerator $signatureGenerator */
$signatureGenerator = ServiceManager::getServiceManager()->get(SignatureGenerator::class);
$signature = $signatureGenerator->generate(
tao_helpers_Uri::encode($this->getRequestParameter('classUri'))
);
$editClassLabelForm = new tao_actions_form_EditClassLabel(
$clazz,
$this->getRequestParameters(),
$signature
);
$myForm = $editClassLabelForm->getForm();
if ($myForm->isSubmited()) {
if ($myForm->isValid()) {
$clazz->setLabel($myForm->getValue(tao_helpers_Uri::encode(OntologyRdfs::RDFS_LABEL)));
$this->setData("selectNode", tao_helpers_Uri::encode($clazz->getUri()));
$this->setData('message', __('%s Class saved', $clazz->getLabel()));
$this->setData('reload', true);
}
}
$this->setData('formTitle', __('Edit class %s', \tao_helpers_Display::htmlize($clazz->getLabel())));
$this->setData('myForm', $myForm->render());
$this->setView('form.tpl', 'tao');
} | [
"public",
"function",
"editClassLabel",
"(",
")",
"{",
"$",
"clazz",
"=",
"$",
"this",
"->",
"getCurrentClass",
"(",
")",
";",
"/** @var SignatureGenerator $signatureGenerator */",
"$",
"signatureGenerator",
"=",
"ServiceManager",
"::",
"getServiceManager",
"(",
")",
... | Common action to view and change the label of a class | [
"Common",
"action",
"to",
"view",
"and",
"change",
"the",
"label",
"of",
"a",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L411-L443 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.addInstance | public function addInstance()
{
if (!$this->isXmlHttpRequest()) {
throw new common_exception_BadRequest('wrong request mode');
}
$id = $this->getRequestParameter('id');
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$id
);
$response = [];
$clazz = $this->getClass($id);
$label = $this->getClassService()->createUniqueLabel($clazz);
$instance = $this->getClassService()->createInstance($clazz, $label);
if(!is_null($instance) && $instance instanceof core_kernel_classes_Resource){
$response = [
'label' => $instance->getLabel(),
'uri' => $instance->getUri()
];
}
$this->returnJson($response);
} | php | public function addInstance()
{
if (!$this->isXmlHttpRequest()) {
throw new common_exception_BadRequest('wrong request mode');
}
$id = $this->getRequestParameter('id');
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$id
);
$response = [];
$clazz = $this->getClass($id);
$label = $this->getClassService()->createUniqueLabel($clazz);
$instance = $this->getClassService()->createInstance($clazz, $label);
if(!is_null($instance) && $instance instanceof core_kernel_classes_Resource){
$response = [
'label' => $instance->getLabel(),
'uri' => $instance->getUri()
];
}
$this->returnJson($response);
} | [
"public",
"function",
"addInstance",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wrong request mode'",
")",
";",
"}",
"$",
"id",
"=",
"$",
"this",
"->",
"... | Add an instance of the selected class
@requiresRight id WRITE
@return void
@throws SecurityException
@throws \oat\tao\model\metadata\exception\InconsistencyConfigException
@throws common_exception_BadRequest
@throws common_exception_Error | [
"Add",
"an",
"instance",
"of",
"the",
"selected",
"class",
"@requiresRight",
"id",
"WRITE"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L456-L486 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.addSubClass | public function addSubClass()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$classId = $this->getRequestParameter('id');
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$classId
);
$this->validateInstanceRoot($classId);
$parent = $this->getClass($classId);
$clazz = $this->getClassService()->createSubClass($parent);
if(!is_null($clazz) && $clazz instanceof core_kernel_classes_Class){
$this->returnJson(array(
'label' => $clazz->getLabel(),
'uri' => tao_helpers_Uri::encode($clazz->getUri())
));
}
} | php | public function addSubClass()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$classId = $this->getRequestParameter('id');
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$classId
);
$this->validateInstanceRoot($classId);
$parent = $this->getClass($classId);
$clazz = $this->getClassService()->createSubClass($parent);
if(!is_null($clazz) && $clazz instanceof core_kernel_classes_Class){
$this->returnJson(array(
'label' => $clazz->getLabel(),
'uri' => tao_helpers_Uri::encode($clazz->getUri())
));
}
} | [
"public",
"function",
"addSubClass",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wrong request mode'",
")",
";",
"}",
"$",
"classId",
"=",
"$",
"this",
"->"... | Add a subclass to the currently selected class
@requiresRight id WRITE
@throws Exception
@throws common_exception_BadRequest | [
"Add",
"a",
"subclass",
"to",
"the",
"currently",
"selected",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L494-L517 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.addInstanceForm | public function addInstanceForm()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$clazz = $this->getCurrentClass();
$formContainer = new tao_actions_form_CreateInstance(array($clazz), array());
$myForm = $formContainer->getForm();
if ($myForm->isSubmited() && $myForm->isValid()) {
$properties = $myForm->getValues();
$instance = $this->createInstance(array($clazz), $properties);
$this->setData('message', __('%s created', $instance->getLabel()));
$this->setData('reload', true);
}
$this->setData('formTitle', __('Create instance of ').$clazz->getLabel());
$this->setData('myForm', $myForm->render());
$this->setView('form.tpl', 'tao');
} | php | public function addInstanceForm()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$clazz = $this->getCurrentClass();
$formContainer = new tao_actions_form_CreateInstance(array($clazz), array());
$myForm = $formContainer->getForm();
if ($myForm->isSubmited() && $myForm->isValid()) {
$properties = $myForm->getValues();
$instance = $this->createInstance(array($clazz), $properties);
$this->setData('message', __('%s created', $instance->getLabel()));
$this->setData('reload', true);
}
$this->setData('formTitle', __('Create instance of ').$clazz->getLabel());
$this->setData('myForm', $myForm->render());
$this->setView('form.tpl', 'tao');
} | [
"public",
"function",
"addInstanceForm",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wrong request mode'",
")",
";",
"}",
"$",
"clazz",
"=",
"$",
"this",
"-... | Add an instance of the selected class
@throws common_exception_BadRequest
@return void | [
"Add",
"an",
"instance",
"of",
"the",
"selected",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L524-L546 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.createInstance | protected function createInstance($classes, $properties) {
$first = array_shift($classes);
$instance = $first->createInstanceWithProperties($properties);
foreach ($classes as $class) {
$instance = $this->getResource('');
$instance->setType($class);
}
return $instance;
} | php | protected function createInstance($classes, $properties) {
$first = array_shift($classes);
$instance = $first->createInstanceWithProperties($properties);
foreach ($classes as $class) {
$instance = $this->getResource('');
$instance->setType($class);
}
return $instance;
} | [
"protected",
"function",
"createInstance",
"(",
"$",
"classes",
",",
"$",
"properties",
")",
"{",
"$",
"first",
"=",
"array_shift",
"(",
"$",
"classes",
")",
";",
"$",
"instance",
"=",
"$",
"first",
"->",
"createInstanceWithProperties",
"(",
"$",
"properties... | creates the instance
@param array $classes
@param array $properties
@return core_kernel_classes_Resource | [
"creates",
"the",
"instance"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L555-L563 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.cloneInstance | public function cloneInstance()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$uri = $this->getRequestParameter('uri');
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$uri
);
$this->validateInstanceRoot($uri);
$clone = $this->getClassService()->cloneInstance($this->getCurrentInstance(), $this->getCurrentClass());
if(!is_null($clone)){
$this->returnJson(array(
'label' => $clone->getLabel(),
'uri' => tao_helpers_Uri::encode($clone->getUri())
));
}
} | php | public function cloneInstance()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$uri = $this->getRequestParameter('uri');
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$uri
);
$this->validateInstanceRoot($uri);
$clone = $this->getClassService()->cloneInstance($this->getCurrentInstance(), $this->getCurrentClass());
if(!is_null($clone)){
$this->returnJson(array(
'label' => $clone->getLabel(),
'uri' => tao_helpers_Uri::encode($clone->getUri())
));
}
} | [
"public",
"function",
"cloneInstance",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wrong request mode'",
")",
";",
"}",
"$",
"uri",
"=",
"$",
"this",
"->",
... | Duplicate the current instance
render a JSON response
@throws \League\Flysystem\FileExistsException
@throws common_Exception
@throws common_exception_BadRequest
@throws common_exception_Error
@throws tao_models_classes_MissingRequestParameterException
@return void
@requiresRight uri READ
@requiresRight classUri WRITE | [
"Duplicate",
"the",
"current",
"instance",
"render",
"a",
"JSON",
"response"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L604-L626 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.copyInstance | public function copyInstance()
{
if (
$this->hasRequestParameter('destinationClassUri')
&& $this->hasRequestParameter('uri')
&& common_Utils::isUri($this->getRequestParameter('destinationClassUri'))
) {
$this->validateInstanceRoot(
$this->getRequestParameter('uri')
);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$this->getRequestParameter('uri')
);
$instance = $this->getCurrentInstance();
$destinationClass = $this->getClass($this->getRequestParameter('destinationClassUri'));
if ($this->hasWriteAccess($destinationClass->getUri())) {
$copy = $this->getClassService()->cloneInstance($instance, $destinationClass);
if(!is_null($copy)){
return $this->returnJson([
'success' => true,
'data' => [
'label' => $copy->getLabel(),
'uri' => $copy->getUri()
]
]);
}
return $this->returnJson([
'success' => false,
'errorCode' => 204,
'errorMessage' => __("Unable to copy the resource")
], 204);
}
return $this->returnJson([
'success' => false,
'errorCode' => 401,
'errorMessage' => __("Permission denied to write in the selected class")
], 401);
}
return $this->returnJson([
'success' => false,
'errorCode' => 412,
'errorMessage' => __('Missing Parameters')
], 412);
} | php | public function copyInstance()
{
if (
$this->hasRequestParameter('destinationClassUri')
&& $this->hasRequestParameter('uri')
&& common_Utils::isUri($this->getRequestParameter('destinationClassUri'))
) {
$this->validateInstanceRoot(
$this->getRequestParameter('uri')
);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$this->getRequestParameter('uri')
);
$instance = $this->getCurrentInstance();
$destinationClass = $this->getClass($this->getRequestParameter('destinationClassUri'));
if ($this->hasWriteAccess($destinationClass->getUri())) {
$copy = $this->getClassService()->cloneInstance($instance, $destinationClass);
if(!is_null($copy)){
return $this->returnJson([
'success' => true,
'data' => [
'label' => $copy->getLabel(),
'uri' => $copy->getUri()
]
]);
}
return $this->returnJson([
'success' => false,
'errorCode' => 204,
'errorMessage' => __("Unable to copy the resource")
], 204);
}
return $this->returnJson([
'success' => false,
'errorCode' => 401,
'errorMessage' => __("Permission denied to write in the selected class")
], 401);
}
return $this->returnJson([
'success' => false,
'errorCode' => 412,
'errorMessage' => __('Missing Parameters')
], 412);
} | [
"public",
"function",
"copyInstance",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'destinationClassUri'",
")",
"&&",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'uri'",
")",
"&&",
"common_Utils",
"::",
"isUri",
"(",
"$",
"th... | Copy a resource to a destination
@requiresRight uri READ | [
"Copy",
"a",
"resource",
"to",
"a",
"destination"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L633-L681 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.moveInstance | public function moveInstance()
{
$response = array();
if($this->hasRequestParameter('destinationClassUri') && $this->hasRequestParameter('uri')){
$id = $this->getRequestParameter('uri');
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature($this->getRequestParameter('signature'), $id);
$instance = $this->getResource($id);
$types = $instance->getTypes();
$clazz = reset($types);
$destinationUri = tao_helpers_Uri::decode($this->getRequestParameter('destinationClassUri'));
if(!empty($destinationUri) && $destinationUri != $clazz->getUri()){
$destinationClass = $this->getClass($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);
} | php | public function moveInstance()
{
$response = array();
if($this->hasRequestParameter('destinationClassUri') && $this->hasRequestParameter('uri')){
$id = $this->getRequestParameter('uri');
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature($this->getRequestParameter('signature'), $id);
$instance = $this->getResource($id);
$types = $instance->getTypes();
$clazz = reset($types);
$destinationUri = tao_helpers_Uri::decode($this->getRequestParameter('destinationClassUri'));
if(!empty($destinationUri) && $destinationUri != $clazz->getUri()){
$destinationClass = $this->getClass($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);
} | [
"public",
"function",
"moveInstance",
"(",
")",
"{",
"$",
"response",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'destinationClassUri'",
")",
"&&",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'uri'",
")",
")... | Move an instance from a class to another
@return void
@requiresRight uri WRITE
@requiresRight destinationClassUri WRITE | [
"Move",
"an",
"instance",
"from",
"a",
"class",
"to",
"another"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L689-L725 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.moveResource | public function moveResource()
{
try {
if (!$this->hasRequestParameter('uri')) {
throw new InvalidArgumentException('Resource uri must be specified.');
}
$data = $this->getRequestParameter('uri');
$id = $data['id'];
$this->validateUri($id);
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature($data['signature'], $id);
$ids = [$id];
$this->validateMoveRequest();
$response = $this->moveAllInstances($ids);
$this->returnJson($response);
} catch (\InvalidArgumentException $e) {
$this->returnJsonError($e->getMessage());
}
} | php | public function moveResource()
{
try {
if (!$this->hasRequestParameter('uri')) {
throw new InvalidArgumentException('Resource uri must be specified.');
}
$data = $this->getRequestParameter('uri');
$id = $data['id'];
$this->validateUri($id);
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature($data['signature'], $id);
$ids = [$id];
$this->validateMoveRequest();
$response = $this->moveAllInstances($ids);
$this->returnJson($response);
} catch (\InvalidArgumentException $e) {
$this->returnJsonError($e->getMessage());
}
} | [
"public",
"function",
"moveResource",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'uri'",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Resource uri must be specified.'",
")",
";",
"}",
"$",
... | Move a single resource to another class
@requiresRight uri WRITE
@throws common_exception_Error
@throws common_exception_MethodNotAllowed | [
"Move",
"a",
"single",
"resource",
"to",
"another",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L736-L759 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.moveAll | public function moveAll()
{
try {
if (!$this->hasRequestParameter('ids')) {
throw new InvalidArgumentException('Resource ids must be specified.');
}
$ids = [];
foreach ($this->getRequestParameter('ids') as $id) {
$ids[] = $id['id'];
}
$this->validateInstancesRoot($ids);
if (empty($ids)) {
throw new InvalidArgumentException('No instances specified.');
}
$this->signatureValidator->checkSignatures(
$this->getRequestParameter('ids')
);
$this->validateMoveRequest();
$response = $this->moveAllInstances($ids);
$this->returnJson($response);
} catch (\InvalidArgumentException $e) {
$this->returnJsonError($e->getMessage());
}
} | php | public function moveAll()
{
try {
if (!$this->hasRequestParameter('ids')) {
throw new InvalidArgumentException('Resource ids must be specified.');
}
$ids = [];
foreach ($this->getRequestParameter('ids') as $id) {
$ids[] = $id['id'];
}
$this->validateInstancesRoot($ids);
if (empty($ids)) {
throw new InvalidArgumentException('No instances specified.');
}
$this->signatureValidator->checkSignatures(
$this->getRequestParameter('ids')
);
$this->validateMoveRequest();
$response = $this->moveAllInstances($ids);
$this->returnJson($response);
} catch (\InvalidArgumentException $e) {
$this->returnJsonError($e->getMessage());
}
} | [
"public",
"function",
"moveAll",
"(",
")",
"{",
"try",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'ids'",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Resource ids must be specified.'",
")",
";",
"}",
"$",
"ids"... | Move all specififed resources to the given destination root class
@throws common_exception_Error
@throws common_exception_MethodNotAllowed
@requiresRight id WRITE | [
"Move",
"all",
"specififed",
"resources",
"to",
"the",
"given",
"destination",
"root",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L768-L797 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.translateInstance | public function translateInstance()
{
$instance = $this->getCurrentInstance();
$formContainer = new tao_actions_form_Translate($this->getCurrentClass(), $instance);
$myForm = $formContainer->getForm();
if ($this->hasRequestParameter('target_lang')) {
$targetLang = $this->getRequestParameter('target_lang');
if(in_array($targetLang, tao_helpers_I18n::getAvailableLangsByUsage($this->getResource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA)))){
$langElt = $myForm->getElement('translate_lang');
$langElt->setValue($targetLang);
$langElt->setAttribute('readonly', 'true');
$trData = $this->getClassService()->getTranslatedProperties($instance, $targetLang);
foreach($trData as $key => $value){
$element = $myForm->getElement(tao_helpers_Uri::encode($key));
if(!is_null($element)){
$element->setValue($value);
}
}
}
}
if($myForm->isSubmited()){
if($myForm->isValid()){
$values = $myForm->getValues();
if(isset($values['translate_lang'])){
$datalang = $this->getSession()->getDataLanguage();
$lang = $values['translate_lang'];
$translated = 0;
foreach($values as $key => $value){
if(preg_match("/^http/", $key)){
$value = trim($value);
$property = $this->getProperty($key);
if(empty($value)){
if($datalang != $lang && $lang != ''){
$instance->removePropertyValueByLg($property, $lang);
}
}
else if($instance->editPropertyValueByLg($property, $value, $lang)){
$translated++;
}
}
}
if($translated > 0){
$this->setData('message', __('Translation saved'));
}
}
}
}
$this->setData('myForm', $myForm->render());
$this->setData('formTitle', __('Translate'));
$this->setView('form.tpl', 'tao');
} | php | public function translateInstance()
{
$instance = $this->getCurrentInstance();
$formContainer = new tao_actions_form_Translate($this->getCurrentClass(), $instance);
$myForm = $formContainer->getForm();
if ($this->hasRequestParameter('target_lang')) {
$targetLang = $this->getRequestParameter('target_lang');
if(in_array($targetLang, tao_helpers_I18n::getAvailableLangsByUsage($this->getResource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA)))){
$langElt = $myForm->getElement('translate_lang');
$langElt->setValue($targetLang);
$langElt->setAttribute('readonly', 'true');
$trData = $this->getClassService()->getTranslatedProperties($instance, $targetLang);
foreach($trData as $key => $value){
$element = $myForm->getElement(tao_helpers_Uri::encode($key));
if(!is_null($element)){
$element->setValue($value);
}
}
}
}
if($myForm->isSubmited()){
if($myForm->isValid()){
$values = $myForm->getValues();
if(isset($values['translate_lang'])){
$datalang = $this->getSession()->getDataLanguage();
$lang = $values['translate_lang'];
$translated = 0;
foreach($values as $key => $value){
if(preg_match("/^http/", $key)){
$value = trim($value);
$property = $this->getProperty($key);
if(empty($value)){
if($datalang != $lang && $lang != ''){
$instance->removePropertyValueByLg($property, $lang);
}
}
else if($instance->editPropertyValueByLg($property, $value, $lang)){
$translated++;
}
}
}
if($translated > 0){
$this->setData('message', __('Translation saved'));
}
}
}
}
$this->setData('myForm', $myForm->render());
$this->setData('formTitle', __('Translate'));
$this->setView('form.tpl', 'tao');
} | [
"public",
"function",
"translateInstance",
"(",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"getCurrentInstance",
"(",
")",
";",
"$",
"formContainer",
"=",
"new",
"tao_actions_form_Translate",
"(",
"$",
"this",
"->",
"getCurrentClass",
"(",
")",
",",
... | Render the form to translate a Resource instance
@return void
@requiresRight id WRITE | [
"Render",
"the",
"form",
"to",
"translate",
"a",
"Resource",
"instance"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L804-L864 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.getTranslatedData | public function getTranslatedData()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$data = array();
if($this->hasRequestParameter('lang')){
$data = tao_helpers_Uri::encodeArray(
$this->getClassService()->getTranslatedProperties(
$this->getCurrentInstance(),
$this->getRequestParameter('lang')
),
tao_helpers_Uri::ENCODE_ARRAY_KEYS);
}
$this->returnJson($data);
} | php | public function getTranslatedData()
{
if(!$this->isXmlHttpRequest()){
throw new common_exception_BadRequest('wrong request mode');
}
$data = array();
if($this->hasRequestParameter('lang')){
$data = tao_helpers_Uri::encodeArray(
$this->getClassService()->getTranslatedProperties(
$this->getCurrentInstance(),
$this->getRequestParameter('lang')
),
tao_helpers_Uri::ENCODE_ARRAY_KEYS);
}
$this->returnJson($data);
} | [
"public",
"function",
"getTranslatedData",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wrong request mode'",
")",
";",
"}",
"$",
"data",
"=",
"array",
"(",
... | load the translated data of an instance regarding the given lang
@throws common_exception_BadRequest
@throws common_exception_Error
@throws tao_models_classes_MissingRequestParameterException
@return void | [
"load",
"the",
"translated",
"data",
"of",
"an",
"instance",
"regarding",
"the",
"given",
"lang"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L875-L890 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.delete | public function delete()
{
if (!$this->isXmlHttpRequest()) {
throw new common_exception_BadRequest('wrong request mode');
}
if ($this->hasRequestParameter('uri')) {
return $this->forward('deleteResource', null, null, (array('id' => tao_helpers_Uri::decode($this->getRequestParameter('uri')))));
} elseif ($this->hasRequestParameter('classUri')) {
return $this->forward('deleteClass', null, null, (array('id' => tao_helpers_Uri::decode($this->getRequestParameter('classUri')))));
} else {
throw new common_exception_MissingParameter();
}
} | php | public function delete()
{
if (!$this->isXmlHttpRequest()) {
throw new common_exception_BadRequest('wrong request mode');
}
if ($this->hasRequestParameter('uri')) {
return $this->forward('deleteResource', null, null, (array('id' => tao_helpers_Uri::decode($this->getRequestParameter('uri')))));
} elseif ($this->hasRequestParameter('classUri')) {
return $this->forward('deleteClass', null, null, (array('id' => tao_helpers_Uri::decode($this->getRequestParameter('classUri')))));
} else {
throw new common_exception_MissingParameter();
}
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wrong request mode'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasRequestPa... | delete an instance or a class
called via ajax
@throws common_exception_BadRequest
@throws common_exception_MissingParameter | [
"delete",
"an",
"instance",
"or",
"a",
"class",
"called",
"via",
"ajax"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L899-L912 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.deleteResource | public function deleteResource()
{
if (!$this->isXmlHttpRequest() || !$this->hasRequestParameter('id')) {
throw new common_exception_BadRequest('wrong request mode');
}
$id = $this->getRequestParameter('id');
// Csrf token validation
$this->validateCsrf();
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$id
);
$resource = $this->getResource($this->getRequestParameter('id'));
$deleted = $this->getClassService()->deleteResource($resource);
return $this->returnJson(array(
'deleted' => $deleted
));
} | php | public function deleteResource()
{
if (!$this->isXmlHttpRequest() || !$this->hasRequestParameter('id')) {
throw new common_exception_BadRequest('wrong request mode');
}
$id = $this->getRequestParameter('id');
// Csrf token validation
$this->validateCsrf();
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$id
);
$resource = $this->getResource($this->getRequestParameter('id'));
$deleted = $this->getClassService()->deleteResource($resource);
return $this->returnJson(array(
'deleted' => $deleted
));
} | [
"public",
"function",
"deleteResource",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'id'",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'w... | Generic resource deletion action
@throws Exception
@throws common_exception_BadRequest
@requiresRight id WRITE | [
"Generic",
"resource",
"deletion",
"action"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L921-L943 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.deleteClass | public function deleteClass()
{
if (!$this->isXmlHttpRequest() || !$this->hasRequestParameter('id')) {
throw new common_exception_BadRequest('wrong request mode');
}
$id = $this->getRequestParameter('id');
// Csrf token validation
$this->validateCsrf();
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$id
);
$clazz = $this->getClass($id);
if ($this->getRootClass()->equals($clazz)) {
$success = false;
$msg = __('You cannot delete the root node');
} else {
$label = $clazz->getLabel();
$success = $this->getClassService()->deleteClass($clazz);
$msg = $success ? __('%s has been deleted', $label) : __('Unable to delete %s', $label);
}
return $this->returnJson(array(
'deleted' => $success,
'msg' => $msg
));
} | php | public function deleteClass()
{
if (!$this->isXmlHttpRequest() || !$this->hasRequestParameter('id')) {
throw new common_exception_BadRequest('wrong request mode');
}
$id = $this->getRequestParameter('id');
// Csrf token validation
$this->validateCsrf();
$this->validateInstanceRoot($id);
$this->signatureValidator->checkSignature(
$this->getRequestParameter('signature'),
$id
);
$clazz = $this->getClass($id);
if ($this->getRootClass()->equals($clazz)) {
$success = false;
$msg = __('You cannot delete the root node');
} else {
$label = $clazz->getLabel();
$success = $this->getClassService()->deleteClass($clazz);
$msg = $success ? __('%s has been deleted', $label) : __('Unable to delete %s', $label);
}
return $this->returnJson(array(
'deleted' => $success,
'msg' => $msg
));
} | [
"public",
"function",
"deleteClass",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"'id'",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'wron... | Generic class deletion action
@throws Exception
@throws common_exception_BadRequest
@requiresRight id WRITE | [
"Generic",
"class",
"deletion",
"action"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L952-L982 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.deleteAll | public function deleteAll()
{
$response = [
'success' => true,
'deleted' => []
];
if (!$this->isXmlHttpRequest()) {
throw new common_exception_BadRequest('wrong request mode');
}
// Csrf token validation
$this->validateCsrf();
$ids = [];
foreach ($this->getRequestParameter('ids') as $id) {
$ids[] = $id['id'];
}
$this->signatureValidator->checkSignatures($this->getRequestParameter('ids'));
$this->validateInstancesRoot($ids);
foreach ($ids as $id) {
$deleted = false;
try {
if ($this->hasWriteAccess($id)) {
$resource = new \core_kernel_classes_Resource($id);
if ($resource->isClass()) {
$deleted = $this->getClassService()->deleteClass(new \core_kernel_classes_Class($id));
} else {
$deleted = $this->getClassService()->deleteResource($resource);
}
}
} catch (\common_Exception $ce) {
\common_Logger::w('Unable to remove resource ' . $id . ' : ' . $ce->getMessage());
}
if ($deleted) {
$response['deleted'][] = $id;
}
}
return $this->returnJson($response);
} | php | public function deleteAll()
{
$response = [
'success' => true,
'deleted' => []
];
if (!$this->isXmlHttpRequest()) {
throw new common_exception_BadRequest('wrong request mode');
}
// Csrf token validation
$this->validateCsrf();
$ids = [];
foreach ($this->getRequestParameter('ids') as $id) {
$ids[] = $id['id'];
}
$this->signatureValidator->checkSignatures($this->getRequestParameter('ids'));
$this->validateInstancesRoot($ids);
foreach ($ids as $id) {
$deleted = false;
try {
if ($this->hasWriteAccess($id)) {
$resource = new \core_kernel_classes_Resource($id);
if ($resource->isClass()) {
$deleted = $this->getClassService()->deleteClass(new \core_kernel_classes_Class($id));
} else {
$deleted = $this->getClassService()->deleteResource($resource);
}
}
} catch (\common_Exception $ce) {
\common_Logger::w('Unable to remove resource ' . $id . ' : ' . $ce->getMessage());
}
if ($deleted) {
$response['deleted'][] = $id;
}
}
return $this->returnJson($response);
} | [
"public",
"function",
"deleteAll",
"(",
")",
"{",
"$",
"response",
"=",
"[",
"'success'",
"=>",
"true",
",",
"'deleted'",
"=>",
"[",
"]",
"]",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"throw",
"new",
"common_exc... | Delete all given resources
@requiresRight ids WRITE
@throws Exception
@throws common_exception_BadRequest | [
"Delete",
"all",
"given",
"resources"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L992-L1035 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.hasWriteAccess | protected function hasWriteAccess($resourceId)
{
$user = $this->getSession()->getUser();
return (new DataAccessControl())->hasPrivileges($user, array($resourceId => 'WRITE'));
} | php | protected function hasWriteAccess($resourceId)
{
$user = $this->getSession()->getUser();
return (new DataAccessControl())->hasPrivileges($user, array($resourceId => 'WRITE'));
} | [
"protected",
"function",
"hasWriteAccess",
"(",
"$",
"resourceId",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"return",
"(",
"new",
"DataAccessControl",
"(",
")",
")",
"->",
"hasPrivileges",
"("... | Test whenever the current user has "WRITE" access to the specified id
@param string $resourceId
@return boolean | [
"Test",
"whenever",
"the",
"current",
"user",
"has",
"WRITE",
"access",
"to",
"the",
"specified",
"id"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L1043-L1047 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.validateCsrf | public function validateCsrf()
{
$tokenService = $this->getServiceLocator()->get(TokenService::SERVICE_ID);
$tokenName = $tokenService->getTokenName();
$token = $this->getRequestParameter($tokenName);
if ( $tokenService->checkToken($token) ) {
$tokenService->revokeToken($token);
$newToken = $tokenService->createToken();
$this->setCookie($tokenName, $newToken, null, '/');
return true;
}
\common_Logger::w('Csrf validation failed');
throw new \common_exception_Unauthorized();
} | php | public function validateCsrf()
{
$tokenService = $this->getServiceLocator()->get(TokenService::SERVICE_ID);
$tokenName = $tokenService->getTokenName();
$token = $this->getRequestParameter($tokenName);
if ( $tokenService->checkToken($token) ) {
$tokenService->revokeToken($token);
$newToken = $tokenService->createToken();
$this->setCookie($tokenName, $newToken, null, '/');
return true;
}
\common_Logger::w('Csrf validation failed');
throw new \common_exception_Unauthorized();
} | [
"public",
"function",
"validateCsrf",
"(",
")",
"{",
"$",
"tokenService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"TokenService",
"::",
"SERVICE_ID",
")",
";",
"$",
"tokenName",
"=",
"$",
"tokenService",
"->",
"getTokenName",... | Validates csrf token and revokes token on success
@return {Boolean}
@throws common_exception_Unauthorized | [
"Validates",
"csrf",
"token",
"and",
"revokes",
"token",
"on",
"success"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L1055-L1071 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.validateMoveRequest | protected function validateMoveRequest()
{
if (!$this->isRequestPost()) {
throw new common_exception_MethodNotAllowed('Only POST method is allowed to move instances.');
}
if (!$this->hasRequestParameter('destinationClassUri')) {
throw new InvalidArgumentException('Destination class must be specified');
}
$destinationClass = new \core_kernel_classes_Class($this->getRequestParameter('destinationClassUri'));
if (!$destinationClass->isClass()) {
throw new InvalidArgumentException('Destination class must be a valid class');
}
} | php | protected function validateMoveRequest()
{
if (!$this->isRequestPost()) {
throw new common_exception_MethodNotAllowed('Only POST method is allowed to move instances.');
}
if (!$this->hasRequestParameter('destinationClassUri')) {
throw new InvalidArgumentException('Destination class must be specified');
}
$destinationClass = new \core_kernel_classes_Class($this->getRequestParameter('destinationClassUri'));
if (!$destinationClass->isClass()) {
throw new InvalidArgumentException('Destination class must be a valid class');
}
} | [
"protected",
"function",
"validateMoveRequest",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isRequestPost",
"(",
")",
")",
"{",
"throw",
"new",
"common_exception_MethodNotAllowed",
"(",
"'Only POST method is allowed to move instances.'",
")",
";",
"}",
"if",
... | Validate request with all required parameters
@throws common_exception_Error
@throws common_exception_MethodNotAllowed If it is not POST method
@throws InvalidArgumentException If parameters are not correct | [
"Validate",
"request",
"with",
"all",
"required",
"parameters"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L1080-L1094 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.moveAllInstances | protected function moveAllInstances(array $ids)
{
$rootClass = $this->getClassService()->getRootClass();
if (in_array($rootClass->getUri(), $ids)) {
throw new InvalidArgumentException(sprintf('Root class "%s" cannot be moved', $rootClass->getUri()));
}
$destinationClass = new \core_kernel_classes_Class($this->getRequestParameter('destinationClassUri'));
if (!$destinationClass->isSubClassOf($rootClass) && $destinationClass->getUri() != $rootClass->getUri()) {
throw new InvalidArgumentException(sprintf('Instance "%s" cannot be moved to another root class', $destinationClass->getUri()));
}
list($statuses, $instances, $classes) = $this->getInstancesList($ids);
$movableInstances = $this->getInstancesToMove($classes, $instances, $statuses);
$statuses = $this->move($destinationClass, $movableInstances, $statuses);
return [
'success' => true,
'data' => $statuses
];
} | php | protected function moveAllInstances(array $ids)
{
$rootClass = $this->getClassService()->getRootClass();
if (in_array($rootClass->getUri(), $ids)) {
throw new InvalidArgumentException(sprintf('Root class "%s" cannot be moved', $rootClass->getUri()));
}
$destinationClass = new \core_kernel_classes_Class($this->getRequestParameter('destinationClassUri'));
if (!$destinationClass->isSubClassOf($rootClass) && $destinationClass->getUri() != $rootClass->getUri()) {
throw new InvalidArgumentException(sprintf('Instance "%s" cannot be moved to another root class', $destinationClass->getUri()));
}
list($statuses, $instances, $classes) = $this->getInstancesList($ids);
$movableInstances = $this->getInstancesToMove($classes, $instances, $statuses);
$statuses = $this->move($destinationClass, $movableInstances, $statuses);
return [
'success' => true,
'data' => $statuses
];
} | [
"protected",
"function",
"moveAllInstances",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"rootClass",
"=",
"$",
"this",
"->",
"getClassService",
"(",
")",
"->",
"getRootClass",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"rootClass",
"->",
"getUri",
"("... | Move instances to another class
{
"destinationClassUri": "http://test.it",
"ids": [
"http://resource1",
"http://resource2",
"http://class1",
"http://class2"
]
}
@requiresRight destinationClassUri WRITE
@params array $ids The list of instance uris to move
@throws common_exception_Error | [
"Move",
"instances",
"to",
"another",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L1113-L1136 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.getInstancesList | private function getInstancesList(array $ids)
{
$statuses = $instances = $classes = [];
foreach ($ids as $key => $instance) {
$instance = $this->getResource($instance);
if ($instance->isClass()) {
$instance = $this->getClass($instance);
$classes[] = $instance;
} elseif (!$instance->exists()) {
$statuses[$instance->getUri()] = [
'success' => false,
'message' => sprintf('Instance "%s" does not exist', $instance->getUri()),
];
break;
}
$instances[$key] = $instance;
}
return [
$statuses,
$instances,
$classes
];
} | php | private function getInstancesList(array $ids)
{
$statuses = $instances = $classes = [];
foreach ($ids as $key => $instance) {
$instance = $this->getResource($instance);
if ($instance->isClass()) {
$instance = $this->getClass($instance);
$classes[] = $instance;
} elseif (!$instance->exists()) {
$statuses[$instance->getUri()] = [
'success' => false,
'message' => sprintf('Instance "%s" does not exist', $instance->getUri()),
];
break;
}
$instances[$key] = $instance;
}
return [
$statuses,
$instances,
$classes
];
} | [
"private",
"function",
"getInstancesList",
"(",
"array",
"$",
"ids",
")",
"{",
"$",
"statuses",
"=",
"$",
"instances",
"=",
"$",
"classes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"key",
"=>",
"$",
"instance",
")",
"{",
"$",
"ins... | Gets list of existing instances/classes
@param array $ids list of ids asked to be moved
@return array | [
"Gets",
"list",
"of",
"existing",
"instances",
"/",
"classes"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L1144-L1168 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.getInstancesToMove | private function getInstancesToMove(array $classes = [], array $instances = [], array &$statuses = [])
{
$movableInstances = [];
// Check if a class belong to class to move
/** @var core_kernel_classes_Resource|core_kernel_classes_Class $instance */
foreach ($instances as $instance) {
$isValid = true;
foreach ($classes as $class) {
if ($instance instanceof core_kernel_classes_Class) {
//Disallow moving a class to $class. True only for classes which are already subclasses of $class
if ($class->getUri() != $instance->getUri() && $instance->isSubClassOf($class)) {
$statuses[$instance->getUri()] = [
'success' => false,
'message' => sprintf('Instance "%s" cannot be moved to class to move "%s"', $instance->getUri(), $class->getUri()),
];
$isValid = false;
break;
}
} else {
//Disallow moving instances to $class. True only for instances which already belongs to $class
if ($instance->isInstanceOf($class)) {
$statuses[$instance->getUri()] = [
'success' => false,
'message' => sprintf('Instance "%s" cannot be moved to class to move "%s"', $instance->getUri(), $class->getUri()),
];
$isValid = false;
break;
}
}
}
if ($isValid) {
$movableInstances[$instance->getUri()] = $instance;
}
}
return $movableInstances;
} | php | private function getInstancesToMove(array $classes = [], array $instances = [], array &$statuses = [])
{
$movableInstances = [];
// Check if a class belong to class to move
/** @var core_kernel_classes_Resource|core_kernel_classes_Class $instance */
foreach ($instances as $instance) {
$isValid = true;
foreach ($classes as $class) {
if ($instance instanceof core_kernel_classes_Class) {
//Disallow moving a class to $class. True only for classes which are already subclasses of $class
if ($class->getUri() != $instance->getUri() && $instance->isSubClassOf($class)) {
$statuses[$instance->getUri()] = [
'success' => false,
'message' => sprintf('Instance "%s" cannot be moved to class to move "%s"', $instance->getUri(), $class->getUri()),
];
$isValid = false;
break;
}
} else {
//Disallow moving instances to $class. True only for instances which already belongs to $class
if ($instance->isInstanceOf($class)) {
$statuses[$instance->getUri()] = [
'success' => false,
'message' => sprintf('Instance "%s" cannot be moved to class to move "%s"', $instance->getUri(), $class->getUri()),
];
$isValid = false;
break;
}
}
}
if ($isValid) {
$movableInstances[$instance->getUri()] = $instance;
}
}
return $movableInstances;
} | [
"private",
"function",
"getInstancesToMove",
"(",
"array",
"$",
"classes",
"=",
"[",
"]",
",",
"array",
"$",
"instances",
"=",
"[",
"]",
",",
"array",
"&",
"$",
"statuses",
"=",
"[",
"]",
")",
"{",
"$",
"movableInstances",
"=",
"[",
"]",
";",
"// Che... | Get movable instances from the list of instances
@param array $classes
@param array $instances
@return array | [
"Get",
"movable",
"instances",
"from",
"the",
"list",
"of",
"instances"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L1178-L1215 |
oat-sa/tao-core | actions/class.RdfController.php | tao_actions_RdfController.move | private function move(\core_kernel_classes_Class $destinationClass, array $movableInstances = [], array $statuses = [])
{
/** @var core_kernel_classes_Resource $movableInstance */
foreach ($movableInstances as $movableInstance) {
$statuses[$movableInstance->getUri()] = [
'success' => $success = $this->getClassService()->changeClass($movableInstance, $destinationClass),
];
if ($success === true) {
$statuses[$movableInstance->getUri()]['message'] = sprintf(
'Instance "%s" has been successfully moved to "%s"', $movableInstance->getUri(), $destinationClass->getUri()
);
} else {
$statuses[$movableInstance->getUri()]['message'] = sprintf('An error has occurred while persisting instance "%s"', $movableInstance->getUri());
}
}
return $statuses;
} | php | private function move(\core_kernel_classes_Class $destinationClass, array $movableInstances = [], array $statuses = [])
{
/** @var core_kernel_classes_Resource $movableInstance */
foreach ($movableInstances as $movableInstance) {
$statuses[$movableInstance->getUri()] = [
'success' => $success = $this->getClassService()->changeClass($movableInstance, $destinationClass),
];
if ($success === true) {
$statuses[$movableInstance->getUri()]['message'] = sprintf(
'Instance "%s" has been successfully moved to "%s"', $movableInstance->getUri(), $destinationClass->getUri()
);
} else {
$statuses[$movableInstance->getUri()]['message'] = sprintf('An error has occurred while persisting instance "%s"', $movableInstance->getUri());
}
}
return $statuses;
} | [
"private",
"function",
"move",
"(",
"\\",
"core_kernel_classes_Class",
"$",
"destinationClass",
",",
"array",
"$",
"movableInstances",
"=",
"[",
"]",
",",
"array",
"$",
"statuses",
"=",
"[",
"]",
")",
"{",
"/** @var core_kernel_classes_Resource $movableInstance */",
... | Move movableInstances to the destinationClass
@param core_kernel_classes_Class $destinationClass class to move to
@param array $movableInstances list of instances available to move
@param array $statuses list of statuses for instances asked to be moved
@return array $statuses updated list of statuses | [
"Move",
"movableInstances",
"to",
"the",
"destinationClass"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RdfController.php#L1226-L1243 |
oat-sa/tao-core | models/classes/theme/ConfigurablePlatformTheme.php | ConfigurablePlatformTheme.getTemplate | public function getTemplate($id, $context = Theme::CONTEXT_BACKOFFICE)
{
$templates = $this->getOption(static::TEMPLATES);
if (is_null($templates) || empty($templates[$id])) {
return Template::getTemplate('blocks/' . $id . '.tpl', 'tao');
}
if ($templates[$id] === static::DEFAULT_PATH) {
return Template::getTemplate(
$this->defaultThemePath . '/' . $id . '.tpl',
$this->getOption(static::EXTENSION_ID)
);
}
// otherwise it will be assumed the template is already configured
return $templates[$id];
} | php | public function getTemplate($id, $context = Theme::CONTEXT_BACKOFFICE)
{
$templates = $this->getOption(static::TEMPLATES);
if (is_null($templates) || empty($templates[$id])) {
return Template::getTemplate('blocks/' . $id . '.tpl', 'tao');
}
if ($templates[$id] === static::DEFAULT_PATH) {
return Template::getTemplate(
$this->defaultThemePath . '/' . $id . '.tpl',
$this->getOption(static::EXTENSION_ID)
);
}
// otherwise it will be assumed the template is already configured
return $templates[$id];
} | [
"public",
"function",
"getTemplate",
"(",
"$",
"id",
",",
"$",
"context",
"=",
"Theme",
"::",
"CONTEXT_BACKOFFICE",
")",
"{",
"$",
"templates",
"=",
"$",
"this",
"->",
"getOption",
"(",
"static",
"::",
"TEMPLATES",
")",
";",
"if",
"(",
"is_null",
"(",
... | Get a template associated from a given $id
@param string $id
@param string $context
@return string | [
"Get",
"a",
"template",
"associated",
"from",
"a",
"given",
"$id"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/theme/ConfigurablePlatformTheme.php#L194-L211 |
oat-sa/tao-core | models/classes/theme/ConfigurablePlatformTheme.php | ConfigurablePlatformTheme.getOperatedBy | public function getOperatedBy() {
$operatedBy = $this->getOption(static::OPERATED_BY);
$operatedBy['name'] = empty($operatedBy['name']) ? '' : $operatedBy['name'];
$operatedBy['email'] = empty($operatedBy['email']) ? '' : $operatedBy['email'];
return $operatedBy;
} | php | public function getOperatedBy() {
$operatedBy = $this->getOption(static::OPERATED_BY);
$operatedBy['name'] = empty($operatedBy['name']) ? '' : $operatedBy['name'];
$operatedBy['email'] = empty($operatedBy['email']) ? '' : $operatedBy['email'];
return $operatedBy;
} | [
"public",
"function",
"getOperatedBy",
"(",
")",
"{",
"$",
"operatedBy",
"=",
"$",
"this",
"->",
"getOption",
"(",
"static",
"::",
"OPERATED_BY",
")",
";",
"$",
"operatedBy",
"[",
"'name'",
"]",
"=",
"empty",
"(",
"$",
"operatedBy",
"[",
"'name'",
"]",
... | Operated by info, make sure both fields contain a string
@return array | [
"Operated",
"by",
"info",
"make",
"sure",
"both",
"fields",
"contain",
"a",
"string"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/theme/ConfigurablePlatformTheme.php#L329-L334 |
oat-sa/tao-core | models/classes/theme/ConfigurablePlatformTheme.php | ConfigurablePlatformTheme.getTextFromArray | public function getTextFromArray(array $keys = [])
{
$values = [];
foreach ($keys as $key) {
$values[$key] = $this->getText($key);
}
return $values;
} | php | public function getTextFromArray(array $keys = [])
{
$values = [];
foreach ($keys as $key) {
$values[$key] = $this->getText($key);
}
return $values;
} | [
"public",
"function",
"getTextFromArray",
"(",
"array",
"$",
"keys",
"=",
"[",
"]",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->... | Retrieve all custom translatable strings for the given keys
@param array $keys
@return array | [
"Retrieve",
"all",
"custom",
"translatable",
"strings",
"for",
"the",
"given",
"keys"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/theme/ConfigurablePlatformTheme.php#L366-L373 |
oat-sa/tao-core | models/classes/theme/ConfigurablePlatformTheme.php | ConfigurablePlatformTheme.setupOptions | protected function setupOptions($options)
{
if(empty($options[static::EXTENSION_ID])) {
$cls = get_class($this);
strtok($cls, '\\');
$options[static::EXTENSION_ID] = strtok('\\');
}
$options = array_merge([
static::STYLESHEET => Template::css('tao-3.css', 'tao'),
static::LOGO_URL => Template::img('tao-logo.png', 'tao'),
static::LABEL => $options[static::LABEL],
static::EXTENSION_ID => $options[static::EXTENSION_ID],
static::ID => $options[static::EXTENSION_ID]
. StringUtils::camelize(StringUtils::removeSpecChars($options[static::LABEL]), true)
],
$options
);
if($options[static::LOGO_URL] === static::DEFAULT_PATH) {
$options[static::LOGO_URL] = Template::img(
$this->defaultThemePath . '/' . static::DEFAULT_LOGO_NAME,
$options[static::EXTENSION_ID]
);
}
if($options[static::STYLESHEET] === static::DEFAULT_PATH) {
$options[static::STYLESHEET] = Template::css(
$this->defaultThemePath . '/' . static::DEFAULT_STYLESHEET_NAME,
$options[static::EXTENSION_ID]
);
}
$this->setOptions($options);
return true;
} | php | protected function setupOptions($options)
{
if(empty($options[static::EXTENSION_ID])) {
$cls = get_class($this);
strtok($cls, '\\');
$options[static::EXTENSION_ID] = strtok('\\');
}
$options = array_merge([
static::STYLESHEET => Template::css('tao-3.css', 'tao'),
static::LOGO_URL => Template::img('tao-logo.png', 'tao'),
static::LABEL => $options[static::LABEL],
static::EXTENSION_ID => $options[static::EXTENSION_ID],
static::ID => $options[static::EXTENSION_ID]
. StringUtils::camelize(StringUtils::removeSpecChars($options[static::LABEL]), true)
],
$options
);
if($options[static::LOGO_URL] === static::DEFAULT_PATH) {
$options[static::LOGO_URL] = Template::img(
$this->defaultThemePath . '/' . static::DEFAULT_LOGO_NAME,
$options[static::EXTENSION_ID]
);
}
if($options[static::STYLESHEET] === static::DEFAULT_PATH) {
$options[static::STYLESHEET] = Template::css(
$this->defaultThemePath . '/' . static::DEFAULT_STYLESHEET_NAME,
$options[static::EXTENSION_ID]
);
}
$this->setOptions($options);
return true;
} | [
"protected",
"function",
"setupOptions",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"static",
"::",
"EXTENSION_ID",
"]",
")",
")",
"{",
"$",
"cls",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"strtok",
"(",
"$",
... | This setup is used when configuring a theme for a custom extension.
In multi tenancy though the tenant id might be use instead of the extension id.
@param $options
@return bool | [
"This",
"setup",
"is",
"used",
"when",
"configuring",
"a",
"theme",
"for",
"a",
"custom",
"extension",
".",
"In",
"multi",
"tenancy",
"though",
"the",
"tenant",
"id",
"might",
"be",
"use",
"instead",
"of",
"the",
"extension",
"id",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/theme/ConfigurablePlatformTheme.php#L404-L439 |
oat-sa/tao-core | models/classes/taskQueue/TaskLog/Decorator/RedirectUrlEntityDecorator.php | RedirectUrlEntityDecorator.toArray | public function toArray()
{
$data = parent::toArray();
$deniedCategories = [
TaskLogInterface::CATEGORY_DELETE,
TaskLogInterface::CATEGORY_EXPORT,
TaskLogInterface::CATEGORY_UNKNOWN
];
if ( !in_array($this->taskLogService->getCategoryForTask($this->getTaskName()), $deniedCategories) &&
($this->getStatus()->isCompleted() || $this->getStatus()->isArchived()) ) {
$user = $this->user;
$params = [
'taskId' => $this->getId()
];
$hasAccess = $this->hasAccess(
$user,
Redirector::class,
'redirectTaskToInstance',
$params
);
if ($hasAccess) {
$data = array_merge($data, [
'redirectUrl' => _url('redirectTaskToInstance', 'Redirector', 'taoBackOffice', $params)
]);
} else {
\common_Logger::w('User \''.$user->getIdentifier().'\' does not have access to redirectTaskToInstance');
}
}
return $data;
} | php | public function toArray()
{
$data = parent::toArray();
$deniedCategories = [
TaskLogInterface::CATEGORY_DELETE,
TaskLogInterface::CATEGORY_EXPORT,
TaskLogInterface::CATEGORY_UNKNOWN
];
if ( !in_array($this->taskLogService->getCategoryForTask($this->getTaskName()), $deniedCategories) &&
($this->getStatus()->isCompleted() || $this->getStatus()->isArchived()) ) {
$user = $this->user;
$params = [
'taskId' => $this->getId()
];
$hasAccess = $this->hasAccess(
$user,
Redirector::class,
'redirectTaskToInstance',
$params
);
if ($hasAccess) {
$data = array_merge($data, [
'redirectUrl' => _url('redirectTaskToInstance', 'Redirector', 'taoBackOffice', $params)
]);
} else {
\common_Logger::w('User \''.$user->getIdentifier().'\' does not have access to redirectTaskToInstance');
}
}
return $data;
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"data",
"=",
"parent",
"::",
"toArray",
"(",
")",
";",
"$",
"deniedCategories",
"=",
"[",
"TaskLogInterface",
"::",
"CATEGORY_DELETE",
",",
"TaskLogInterface",
"::",
"CATEGORY_EXPORT",
",",
"TaskLogInterface",... | Add 'redirectUrl' to the result if the task has been processed
and it is not an export or delete task
@return array | [
"Add",
"redirectUrl",
"to",
"the",
"result",
"if",
"the",
"task",
"has",
"been",
"processed",
"and",
"it",
"is",
"not",
"an",
"export",
"or",
"delete",
"task"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/taskQueue/TaskLog/Decorator/RedirectUrlEntityDecorator.php#L71-L104 |
oat-sa/tao-core | helpers/translation/class.RDFUtils.php | tao_helpers_translation_RDFUtils.unserializeAnnotations | public static function unserializeAnnotations($annotations)
{
$returnValue = array();
$reg = "/\s*@(subject|predicate|sourceLanguage|targetLanguage|source)[\t ]+(.+)(?:\s*|$)/u";
$matches = array();
if (false !== preg_match_all($reg, $annotations, $matches)){
// No problems with $reg.
if (isset($matches[1])){
// We got some annotations.
for ($i = 0; $i < count($matches[1]); $i++){
// Annotation name $i processing. Do we have a value for it?
$name = $matches[1][$i];
if (isset($matches[2][$i])){
// We have an annotation with a name and a value.
// Do not forget to unescape '--' that is not accepted in XML comments (see spec).
// (str_replace is unicode safe ;)!)
$value = $matches[2][$i];
$value = str_replace("\\-\\-", '--', $value);
$value = str_replace("\\\\", "\\", $value);
$returnValue[$name] = $value;
}
}
}
}else{
throw new tao_helpers_translation_TranslationException("A fatal error occured while parsing annotations '${annotations}.'");
}
return (array) $returnValue;
} | php | public static function unserializeAnnotations($annotations)
{
$returnValue = array();
$reg = "/\s*@(subject|predicate|sourceLanguage|targetLanguage|source)[\t ]+(.+)(?:\s*|$)/u";
$matches = array();
if (false !== preg_match_all($reg, $annotations, $matches)){
// No problems with $reg.
if (isset($matches[1])){
// We got some annotations.
for ($i = 0; $i < count($matches[1]); $i++){
// Annotation name $i processing. Do we have a value for it?
$name = $matches[1][$i];
if (isset($matches[2][$i])){
// We have an annotation with a name and a value.
// Do not forget to unescape '--' that is not accepted in XML comments (see spec).
// (str_replace is unicode safe ;)!)
$value = $matches[2][$i];
$value = str_replace("\\-\\-", '--', $value);
$value = str_replace("\\\\", "\\", $value);
$returnValue[$name] = $value;
}
}
}
}else{
throw new tao_helpers_translation_TranslationException("A fatal error occured while parsing annotations '${annotations}.'");
}
return (array) $returnValue;
} | [
"public",
"static",
"function",
"unserializeAnnotations",
"(",
"$",
"annotations",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"$",
"reg",
"=",
"\"/\\s*@(subject|predicate|sourceLanguage|targetLanguage|source)[\\t ]+(.+)(?:\\s*|$)/u\"",
";",
"$",
"matches",... | Unserialize an RDFTranslationUnit annotation and returns an associative
where keys are annotation names, and values are the annotation values.
Throws TranslationException.
@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@param string annotations The annotations string.
@return array | [
"Unserialize",
"an",
"RDFTranslationUnit",
"annotation",
"and",
"returns",
"an",
"associative",
"where",
"keys",
"are",
"annotation",
"names",
"and",
"values",
"are",
"the",
"annotation",
"values",
".",
"Throws",
"TranslationException",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.RDFUtils.php#L53-L82 |
oat-sa/tao-core | helpers/translation/class.RDFUtils.php | tao_helpers_translation_RDFUtils.serializeAnnotations | public static function serializeAnnotations($annotations, $glue = '')
{
$returnValue = (string) '';
// Set default glue.
if ($glue == ''){
$glue = "\n ";
}
$a = array();
foreach ($annotations as $n => $v){
$v = str_replace("\\", "\\\\", $v);
$v = str_replace('--', "\\-\\-", $v);
$a[] = '@' . trim($n) . " ${v}";
}
$returnValue = implode($glue, $a);
return (string) $returnValue;
} | php | public static function serializeAnnotations($annotations, $glue = '')
{
$returnValue = (string) '';
// Set default glue.
if ($glue == ''){
$glue = "\n ";
}
$a = array();
foreach ($annotations as $n => $v){
$v = str_replace("\\", "\\\\", $v);
$v = str_replace('--', "\\-\\-", $v);
$a[] = '@' . trim($n) . " ${v}";
}
$returnValue = implode($glue, $a);
return (string) $returnValue;
} | [
"public",
"static",
"function",
"serializeAnnotations",
"(",
"$",
"annotations",
",",
"$",
"glue",
"=",
"''",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"// Set default glue.",
"if",
"(",
"$",
"glue",
"==",
"''",
")",
"{",
"$",
"... | Serializes an associative array of annotations where keys are annotation
and values are annotation values.
@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@param array annotations An associative array that represents a collection of annotations, where keys are the annotation names and values the annotation values.
@param string glue Indicates what is the glue between serialized annotations.
@return string | [
"Serializes",
"an",
"associative",
"array",
"of",
"annotations",
"where",
"keys",
"are",
"annotation",
"and",
"values",
"are",
"annotation",
"values",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.RDFUtils.php#L94-L112 |
oat-sa/tao-core | helpers/translation/class.RDFUtils.php | tao_helpers_translation_RDFUtils.createLanguageDescription | public static function createLanguageDescription($code, $label)
{
$returnValue = null;
$languageType = tao_models_classes_LanguageService::CLASS_URI_LANGUAGES;
$languagePrefix = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang';
$rdfNs = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
$rdfsNs = 'http://www.w3.org/2000/01/rdf-schema#';
$xmlNs = 'http://www.w3.org/XML/1998/namespace';
$xmlnsNs = 'http://www.w3.org/2000/xmlns/';
$base = 'http://www.tao.lu/Ontologies/TAO.rdf#';
$doc = new DomDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$rdfNode = $doc->createElementNS($rdfNs, 'rdf:RDF');
$rdfNode->setAttributeNS($xmlNs, 'xml:base', $base);
$doc->appendChild($rdfNode);
$descriptionNode = $doc->createElementNS($rdfNs, 'rdf:Description');
$descriptionNode->setAttributeNS($rdfNs, 'rdf:about', $languagePrefix . $code);
$rdfNode->appendChild($descriptionNode);
$typeNode = $doc->createElementNS($rdfNs, 'rdf:type');
$typeNode->setAttributeNS($rdfNs, 'rdf:resource', $languageType);
$descriptionNode->appendChild($typeNode);
$labelNode = $doc->createElementNS($rdfsNs, 'rdfs:label');
$labelNode->setAttributeNS($xmlNs, 'xml:lang', DEFAULT_LANG);
$labelNode->appendChild($doc->createCDATASection($label));
$descriptionNode->appendChild($labelNode);
$valueNode = $doc->createElementNS($rdfNs, 'rdf:value');
$valueNode->appendChild($doc->createCDATASection($code));
$descriptionNode->appendChild($valueNode);
$guiUsageNode = $doc->createElementNS($base, 'tao:LanguageUsages');
$guiUsageNode->setAttributeNs($rdfNs, 'rdf:resource', tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_GUI);
$descriptionNode->appendChild($guiUsageNode);
$dataUsageNode = $doc->createElementNS($base, 'tao:LanguageUsages');
$dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA);
$descriptionNode->appendChild($dataUsageNode);
$dataUsageNode = $doc->createElementNS($base, 'tao:LanguageOrientation');
$dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR);
$descriptionNode->appendChild($dataUsageNode);
$returnValue = $doc;
return $returnValue;
} | php | public static function createLanguageDescription($code, $label)
{
$returnValue = null;
$languageType = tao_models_classes_LanguageService::CLASS_URI_LANGUAGES;
$languagePrefix = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang';
$rdfNs = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';
$rdfsNs = 'http://www.w3.org/2000/01/rdf-schema#';
$xmlNs = 'http://www.w3.org/XML/1998/namespace';
$xmlnsNs = 'http://www.w3.org/2000/xmlns/';
$base = 'http://www.tao.lu/Ontologies/TAO.rdf#';
$doc = new DomDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$rdfNode = $doc->createElementNS($rdfNs, 'rdf:RDF');
$rdfNode->setAttributeNS($xmlNs, 'xml:base', $base);
$doc->appendChild($rdfNode);
$descriptionNode = $doc->createElementNS($rdfNs, 'rdf:Description');
$descriptionNode->setAttributeNS($rdfNs, 'rdf:about', $languagePrefix . $code);
$rdfNode->appendChild($descriptionNode);
$typeNode = $doc->createElementNS($rdfNs, 'rdf:type');
$typeNode->setAttributeNS($rdfNs, 'rdf:resource', $languageType);
$descriptionNode->appendChild($typeNode);
$labelNode = $doc->createElementNS($rdfsNs, 'rdfs:label');
$labelNode->setAttributeNS($xmlNs, 'xml:lang', DEFAULT_LANG);
$labelNode->appendChild($doc->createCDATASection($label));
$descriptionNode->appendChild($labelNode);
$valueNode = $doc->createElementNS($rdfNs, 'rdf:value');
$valueNode->appendChild($doc->createCDATASection($code));
$descriptionNode->appendChild($valueNode);
$guiUsageNode = $doc->createElementNS($base, 'tao:LanguageUsages');
$guiUsageNode->setAttributeNs($rdfNs, 'rdf:resource', tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_GUI);
$descriptionNode->appendChild($guiUsageNode);
$dataUsageNode = $doc->createElementNS($base, 'tao:LanguageUsages');
$dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA);
$descriptionNode->appendChild($dataUsageNode);
$dataUsageNode = $doc->createElementNS($base, 'tao:LanguageOrientation');
$dataUsageNode->setAttributeNs($rdfNs, 'rdf:resource', tao_models_classes_LanguageService::INSTANCE_ORIENTATION_LTR);
$descriptionNode->appendChild($dataUsageNode);
$returnValue = $doc;
return $returnValue;
} | [
"public",
"static",
"function",
"createLanguageDescription",
"(",
"$",
"code",
",",
"$",
"label",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"$",
"languageType",
"=",
"tao_models_classes_LanguageService",
"::",
"CLASS_URI_LANGUAGES",
";",
"$",
"languagePrefix",... | Creates a language description file for TAO using the RDF-XML language.
@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@param string code string code The language code e.g. fr-FR.
@param string label string label The language label e.g. French in english.
@return DomDocument | [
"Creates",
"a",
"language",
"description",
"file",
"for",
"TAO",
"using",
"the",
"RDF",
"-",
"XML",
"language",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.RDFUtils.php#L123-L174 |
oat-sa/tao-core | helpers/form/data/class.FileDescription.php | tao_helpers_form_data_FileDescription.getName | public function getName()
{
if (is_null($this->name)) {
$this->name = is_null($this->getFile()) ? '' : $this->getFile()->getBasename();
}
return $this->name;
} | php | public function getName()
{
if (is_null($this->name)) {
$this->name = is_null($this->getFile()) ? '' : $this->getFile()->getBasename();
}
return $this->name;
} | [
"public",
"function",
"getName",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"name",
")",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"is_null",
"(",
"$",
"this",
"->",
"getFile",
"(",
")",
")",
"?",
"''",
":",
"$",
"this",
"->",... | Returns the name of the file e.g. test.xml.
@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@return string | [
"Returns",
"the",
"name",
"of",
"the",
"file",
"e",
".",
"g",
".",
"test",
".",
"xml",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/data/class.FileDescription.php#L98-L104 |
oat-sa/tao-core | helpers/form/data/class.FileDescription.php | tao_helpers_form_data_FileDescription.getSize | public function getSize()
{
if (is_null($this->size)) {
$this->size = is_null($this->getFile()) ? 0 : $this->getFile()->getSize();
}
return $this->size;
} | php | public function getSize()
{
if (is_null($this->size)) {
$this->size = is_null($this->getFile()) ? 0 : $this->getFile()->getSize();
}
return $this->size;
} | [
"public",
"function",
"getSize",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"size",
")",
")",
"{",
"$",
"this",
"->",
"size",
"=",
"is_null",
"(",
"$",
"this",
"->",
"getFile",
"(",
")",
")",
"?",
"0",
":",
"$",
"this",
"->",
... | Returns the size of the file in bytes.
@access public
@author Jerome Bogaerts <jerome@taotesting.com>
@return int | [
"Returns",
"the",
"size",
"of",
"the",
"file",
"in",
"bytes",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/data/class.FileDescription.php#L113-L119 |
oat-sa/tao-core | helpers/form/data/class.FileDescription.php | tao_helpers_form_data_FileDescription.getFile | public function getFile()
{
if (is_null($this->file)) {
$referencer = $this->getServiceLocator()->get(FileReferenceSerializer::SERVICE_ID);
$this->file = $referencer->unserialize($this->getFileSerial());
}
return $this->file;
} | php | public function getFile()
{
if (is_null($this->file)) {
$referencer = $this->getServiceLocator()->get(FileReferenceSerializer::SERVICE_ID);
$this->file = $referencer->unserialize($this->getFileSerial());
}
return $this->file;
} | [
"public",
"function",
"getFile",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"file",
")",
")",
"{",
"$",
"referencer",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"FileReferenceSerializer",
"::",
"SERVICE_ID"... | Gets the file bound to the FileDescription (returns null if not file
in persistent memory).
@access public
@author Jerome Bogaerts, <jerome@taotesting.com>
@return File | [
"Gets",
"the",
"file",
"bound",
"to",
"the",
"FileDescription",
"(",
"returns",
"null",
"if",
"not",
"file",
"in",
"persistent",
"memory",
")",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/data/class.FileDescription.php#L129-L136 |
oat-sa/tao-core | models/classes/menu/Section.php | Section.migrateDataFromLegacyFormat | private function migrateDataFromLegacyFormat(){
if(count($this->trees) > 0){
//tree attributes to be migrated.
$mapping = array(
'editClassUrl' => array(
'attr' => 'selectClass',
'action' => array(
'id' => 'edit_class',
'name' => 'edit class',
'group' => 'none',
'context' => 'class',
'binding' => 'load'
)
),
'editInstanceUrl' => array(
'attr' => 'selectInstance',
'action' => array(
'id' => 'edit_instance',
'name' => 'edit instance',
'group' => 'none',
'context' => 'instance',
'binding' => 'load'
)
),
'addInstanceUrl' => array(
'attr' => 'addInstance',
'action' => array(
'id' => 'add_instance',
'name' => 'add instance',
'group' => 'none',
'context' => 'instance',
'binding' => 'instantiate'
)
),
'addSubClassUrl' => array(
'attr' => 'addClass',
'action' => array(
'id' => 'add_class',
'name' => 'add class',
'group' => 'none',
'context' => 'class',
'binding' => 'subClass'
)
),
'deleteUrl' => array(
'attr' => 'addClass',
'action' => array(
'id' => 'add_class',
'name' => 'add class',
'group' => 'none',
'context' => 'class',
'binding' => 'subClass'
)
),
'moveInstanceUrl' => array(
'attr' => 'moveInstance',
'action' => array(
'id' => 'move',
'name' => 'move',
'group' => 'none',
'context' => 'instance',
'binding' => 'moveNode'
)
)
);
foreach($this->trees as $index => $tree){
$needMigration = false;
$treeAttributes = $tree->getAttributes();
//check if this attribute needs a migration
foreach($treeAttributes as $attr){
if(array_key_exists($attr, $mapping)){
$needMigration = true;
break;
}
}
if($needMigration){
$newData = array();
//migrate the tree
foreach($treeAttributes as $attr){
//if the attribute belongs to the mapping
if(array_key_exists($attr, $mapping)){
$url = $tree->get($attr);
$actionName = false;
//try to find an action with the same url
foreach($this->actions as $action){
if($action->getRelativeUrl() == $url){
$actionName = $action->getId();
break;
}
}
if($actionName){
$newData[$mapping[$attr]['attr']] = $actionName;
} else {
//otherwise create a new action from the mapping
$newData[$mapping[$attr]['attr']] = $mapping[$attr]['action']['id'];
$actionData = $mapping[$attr]['action'];
$actionData['url'] = $url;
list($extension, $controller, $action) = explode('/', trim($url, '/'));
$actionData['extension'] = $extension;
$actionData['controller'] = $controller;
$actionData['action'] = $action;
$this->actions[] = new Action($actionData);
}
} else {
$newData[$attr] = $tree->get($attr);
}
}
//the tree is replaced
$this->trees[$index] = new Tree($newData);
}
}
}
} | php | private function migrateDataFromLegacyFormat(){
if(count($this->trees) > 0){
//tree attributes to be migrated.
$mapping = array(
'editClassUrl' => array(
'attr' => 'selectClass',
'action' => array(
'id' => 'edit_class',
'name' => 'edit class',
'group' => 'none',
'context' => 'class',
'binding' => 'load'
)
),
'editInstanceUrl' => array(
'attr' => 'selectInstance',
'action' => array(
'id' => 'edit_instance',
'name' => 'edit instance',
'group' => 'none',
'context' => 'instance',
'binding' => 'load'
)
),
'addInstanceUrl' => array(
'attr' => 'addInstance',
'action' => array(
'id' => 'add_instance',
'name' => 'add instance',
'group' => 'none',
'context' => 'instance',
'binding' => 'instantiate'
)
),
'addSubClassUrl' => array(
'attr' => 'addClass',
'action' => array(
'id' => 'add_class',
'name' => 'add class',
'group' => 'none',
'context' => 'class',
'binding' => 'subClass'
)
),
'deleteUrl' => array(
'attr' => 'addClass',
'action' => array(
'id' => 'add_class',
'name' => 'add class',
'group' => 'none',
'context' => 'class',
'binding' => 'subClass'
)
),
'moveInstanceUrl' => array(
'attr' => 'moveInstance',
'action' => array(
'id' => 'move',
'name' => 'move',
'group' => 'none',
'context' => 'instance',
'binding' => 'moveNode'
)
)
);
foreach($this->trees as $index => $tree){
$needMigration = false;
$treeAttributes = $tree->getAttributes();
//check if this attribute needs a migration
foreach($treeAttributes as $attr){
if(array_key_exists($attr, $mapping)){
$needMigration = true;
break;
}
}
if($needMigration){
$newData = array();
//migrate the tree
foreach($treeAttributes as $attr){
//if the attribute belongs to the mapping
if(array_key_exists($attr, $mapping)){
$url = $tree->get($attr);
$actionName = false;
//try to find an action with the same url
foreach($this->actions as $action){
if($action->getRelativeUrl() == $url){
$actionName = $action->getId();
break;
}
}
if($actionName){
$newData[$mapping[$attr]['attr']] = $actionName;
} else {
//otherwise create a new action from the mapping
$newData[$mapping[$attr]['attr']] = $mapping[$attr]['action']['id'];
$actionData = $mapping[$attr]['action'];
$actionData['url'] = $url;
list($extension, $controller, $action) = explode('/', trim($url, '/'));
$actionData['extension'] = $extension;
$actionData['controller'] = $controller;
$actionData['action'] = $action;
$this->actions[] = new Action($actionData);
}
} else {
$newData[$attr] = $tree->get($attr);
}
}
//the tree is replaced
$this->trees[$index] = new Tree($newData);
}
}
}
} | [
"private",
"function",
"migrateDataFromLegacyFormat",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"trees",
")",
">",
"0",
")",
"{",
"//tree attributes to be migrated.",
"$",
"mapping",
"=",
"array",
"(",
"'editClassUrl'",
"=>",
"array",
"(",
"... | Enables sections to be backward compatible with the structure format
(before some actions were missing as they were defined in the tree part).
legacy format : tao <= 2.6.x
this method should be deprecated from 2.8.0 / 3.0.0 | [
"Enables",
"sections",
"to",
"be",
"backward",
"compatible",
"with",
"the",
"structure",
"format",
"(",
"before",
"some",
"actions",
"were",
"missing",
"as",
"they",
"were",
"defined",
"in",
"the",
"tree",
"part",
")",
".",
"legacy",
"format",
":",
"tao",
... | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/menu/Section.php#L218-L340 |
oat-sa/tao-core | actions/form/class.Translate.php | tao_actions_form_Translate.initElements | protected function initElements()
{
parent::initElements();
$elements = $this->form->getElements();
$this->form->setElements(array());
$currentLangElt = tao_helpers_form_FormFactory::getElement('current_lang', 'Textbox');
$currentLangElt->setDescription(__('Current language'));
$currentLangElt->setAttributes(array('readonly' => 'true'));
$currentLangElt->setValue(\common_session_SessionManager::getSession()->getDataLanguage()); //API lang /data lang
$this->form->addElement($currentLangElt);
$dataLangElement = tao_helpers_form_FormFactory::getElement('translate_lang', 'Combobox');
$dataLangElement->setDescription(__('Translate to'));
$dataLangElement->setOptions(tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA)));
$dataLangElement->setEmptyOption(__('Select a language'));
$dataLangElement->addValidator( tao_helpers_form_FormFactory::getValidator('NotEmpty') );
$this->form->addElement($dataLangElement);
$this->form->createGroup('translation_info', __('Translation parameters'), array('current_lang', 'translate_lang'));
$dataGroup = array();
foreach($elements as $element){
if( $element instanceof tao_helpers_form_elements_Hidden ||
$element->getName() == 'uri' || $element->getName() == 'classUri'){
$this->form->addElement($element);
}
else{
$propertyUri = tao_helpers_Uri::decode($element->getName());
$property = new core_kernel_classes_Property($propertyUri);
//translate only language dependent properties or Labels
//supported widget are: Textbox, TextArea, HtmlArea
//@todo support other widgets
if( ( $property->isLgDependent() &&
($element instanceof tao_helpers_form_elements_Textbox ||
$element instanceof tao_helpers_form_elements_TextArea ||
$element instanceof tao_helpers_form_elements_HtmlArea
) ) ||
$propertyUri == OntologyRdfs::RDFS_LABEL){
$translatedElt = clone $element;
$viewElt = tao_helpers_form_FormFactory::getElement('view_'.$element->getName(), 'Label');
$viewElt->setDescription($element->getDescription());
$viewElt->setValue($element->getValue());
$viewElt->setAttribute('no-format', true);
if ($element instanceof tao_helpers_form_elements_HtmlArea){
$viewElt->setAttribute('htmlentities', false);
}
$this->form->addElement($viewElt);
$dataGroup[] = $viewElt->getName();
$translatedElt->setDescription(' ');
$translatedElt->setValue('');
if($propertyUri == OntologyRdfs::RDFS_LABEL){
$translatedElt->setForcedValid();
}
$this->form->addElement($translatedElt);
$dataGroup[] = $translatedElt->getName();
}
}
}
$this->form->createGroup('translation_form', __('Translate'), $dataGroup);
} | php | protected function initElements()
{
parent::initElements();
$elements = $this->form->getElements();
$this->form->setElements(array());
$currentLangElt = tao_helpers_form_FormFactory::getElement('current_lang', 'Textbox');
$currentLangElt->setDescription(__('Current language'));
$currentLangElt->setAttributes(array('readonly' => 'true'));
$currentLangElt->setValue(\common_session_SessionManager::getSession()->getDataLanguage()); //API lang /data lang
$this->form->addElement($currentLangElt);
$dataLangElement = tao_helpers_form_FormFactory::getElement('translate_lang', 'Combobox');
$dataLangElement->setDescription(__('Translate to'));
$dataLangElement->setOptions(tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA)));
$dataLangElement->setEmptyOption(__('Select a language'));
$dataLangElement->addValidator( tao_helpers_form_FormFactory::getValidator('NotEmpty') );
$this->form->addElement($dataLangElement);
$this->form->createGroup('translation_info', __('Translation parameters'), array('current_lang', 'translate_lang'));
$dataGroup = array();
foreach($elements as $element){
if( $element instanceof tao_helpers_form_elements_Hidden ||
$element->getName() == 'uri' || $element->getName() == 'classUri'){
$this->form->addElement($element);
}
else{
$propertyUri = tao_helpers_Uri::decode($element->getName());
$property = new core_kernel_classes_Property($propertyUri);
//translate only language dependent properties or Labels
//supported widget are: Textbox, TextArea, HtmlArea
//@todo support other widgets
if( ( $property->isLgDependent() &&
($element instanceof tao_helpers_form_elements_Textbox ||
$element instanceof tao_helpers_form_elements_TextArea ||
$element instanceof tao_helpers_form_elements_HtmlArea
) ) ||
$propertyUri == OntologyRdfs::RDFS_LABEL){
$translatedElt = clone $element;
$viewElt = tao_helpers_form_FormFactory::getElement('view_'.$element->getName(), 'Label');
$viewElt->setDescription($element->getDescription());
$viewElt->setValue($element->getValue());
$viewElt->setAttribute('no-format', true);
if ($element instanceof tao_helpers_form_elements_HtmlArea){
$viewElt->setAttribute('htmlentities', false);
}
$this->form->addElement($viewElt);
$dataGroup[] = $viewElt->getName();
$translatedElt->setDescription(' ');
$translatedElt->setValue('');
if($propertyUri == OntologyRdfs::RDFS_LABEL){
$translatedElt->setForcedValid();
}
$this->form->addElement($translatedElt);
$dataGroup[] = $translatedElt->getName();
}
}
}
$this->form->createGroup('translation_form', __('Translate'), $dataGroup);
} | [
"protected",
"function",
"initElements",
"(",
")",
"{",
"parent",
"::",
"initElements",
"(",
")",
";",
"$",
"elements",
"=",
"$",
"this",
"->",
"form",
"->",
"getElements",
"(",
")",
";",
"$",
"this",
"->",
"form",
"->",
"setElements",
"(",
"array",
"(... | Initialize the form elements
@access protected
@author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
@return mixed | [
"Initialize",
"the",
"form",
"elements"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/form/class.Translate.php#L71-L150 |
oat-sa/tao-core | models/classes/modules/DynamicModule.php | DynamicModule.toArray | public function toArray()
{
return [
'id' => $this->id,
'module' => $this->module,
'bundle' => $this->bundle,
'position' => $this->position,
'name' => $this->name,
'description' => $this->description,
'category' => $this->category,
'active' => $this->active,
'tags' => $this->tags
];
} | php | public function toArray()
{
return [
'id' => $this->id,
'module' => $this->module,
'bundle' => $this->bundle,
'position' => $this->position,
'name' => $this->name,
'description' => $this->description,
'category' => $this->category,
'active' => $this->active,
'tags' => $this->tags
];
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'module'",
"=>",
"$",
"this",
"->",
"module",
",",
"'bundle'",
"=>",
"$",
"this",
"->",
"bundle",
",",
"'position'",
"=>",
"$",
"this",
"->",
... | Convenient method to convert the members to an assoc array
@return array the data | [
"Convenient",
"method",
"to",
"convert",
"the",
"members",
"to",
"an",
"assoc",
"array"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/DynamicModule.php#L182-L195 |
oat-sa/tao-core | models/classes/modules/DynamicModule.php | DynamicModule.fromArray | public static function fromArray( array $data )
{
if( !isset($data['id']) || !isset($data['module']) || !isset($data['category']) ) {
throw new common_exception_InconsistentData('The module requires an id, a module and a category');
}
return new static($data['id'], $data['module'], $data['category'], $data);
} | php | public static function fromArray( array $data )
{
if( !isset($data['id']) || !isset($data['module']) || !isset($data['category']) ) {
throw new common_exception_InconsistentData('The module requires an id, a module and a category');
}
return new static($data['id'], $data['module'], $data['category'], $data);
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"data",
"[",
"'module'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"... | Create a test module from an assoc array
@param array $data
@return DynamicModule the new instance
@throws common_exception_InconsistentData | [
"Create",
"a",
"test",
"module",
"from",
"an",
"assoc",
"array"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/DynamicModule.php#L203-L210 |
oat-sa/tao-core | models/classes/modules/DynamicModule.php | DynamicModule.validateRequiredData | private static function validateRequiredData($id, $module, $category)
{
if(! is_string($id) || empty($id)) {
throw new common_exception_InconsistentData('The module needs an id');
}
if(! is_string($module) || empty($module)) {
throw new common_exception_InconsistentData('The module needs a path');
}
if(! is_string($category) || empty($category)) {
throw new common_exception_InconsistentData('The module needs a category');
}
return true;
} | php | private static function validateRequiredData($id, $module, $category)
{
if(! is_string($id) || empty($id)) {
throw new common_exception_InconsistentData('The module needs an id');
}
if(! is_string($module) || empty($module)) {
throw new common_exception_InconsistentData('The module needs a path');
}
if(! is_string($category) || empty($category)) {
throw new common_exception_InconsistentData('The module needs a category');
}
return true;
} | [
"private",
"static",
"function",
"validateRequiredData",
"(",
"$",
"id",
",",
"$",
"module",
",",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"id",
")",
"||",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"common_excep... | Validate required data to construct a module
@param mixed $id
@param mixed $module
@param mixed $category
@return boolean true
@throws common_exception_InconsistentData | [
"Validate",
"required",
"data",
"to",
"construct",
"a",
"module"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/DynamicModule.php#L220-L234 |
oat-sa/tao-core | helpers/form/validators/CspHeaderValidator.php | CspHeaderValidator.evaluate | public function evaluate($values)
{
// Only validate if the source is set to 'list'
$sourceElement = $this->getOption('sourceElement');
$sourceElementValue = $sourceElement->getEvaluatedValue();
if ($sourceElementValue !== 'list') {
return true;
}
$this->invalidValues = [];
$values = trim(str_replace("\r", '', $values));
if (!$values) {
$this->setMessage('Please add at least one domain or directive.');
return false;
}
$sources = explode("\n", $values);
foreach ($sources as $key => $source) {
if ($source === '') {
unset($sources[$key]);
}
if (in_array($source, self::DIRECTIVES, true)) {
if ($this->isValidDirective($source) === false) {
$this->invalidValues['domain'][] = $source;
}
$sources[$key] = $this->getNormalizedDirective($source);
continue;
}
if ($this->isValidDomain($source) === false) {
$this->invalidValues['domain'][] = $source;
}
}
$isValid = empty($this->invalidValues);
if (!$isValid) {
$this->setMessage($this->getErrorMessage());
}
return $isValid;
} | php | public function evaluate($values)
{
// Only validate if the source is set to 'list'
$sourceElement = $this->getOption('sourceElement');
$sourceElementValue = $sourceElement->getEvaluatedValue();
if ($sourceElementValue !== 'list') {
return true;
}
$this->invalidValues = [];
$values = trim(str_replace("\r", '', $values));
if (!$values) {
$this->setMessage('Please add at least one domain or directive.');
return false;
}
$sources = explode("\n", $values);
foreach ($sources as $key => $source) {
if ($source === '') {
unset($sources[$key]);
}
if (in_array($source, self::DIRECTIVES, true)) {
if ($this->isValidDirective($source) === false) {
$this->invalidValues['domain'][] = $source;
}
$sources[$key] = $this->getNormalizedDirective($source);
continue;
}
if ($this->isValidDomain($source) === false) {
$this->invalidValues['domain'][] = $source;
}
}
$isValid = empty($this->invalidValues);
if (!$isValid) {
$this->setMessage($this->getErrorMessage());
}
return $isValid;
} | [
"public",
"function",
"evaluate",
"(",
"$",
"values",
")",
"{",
"// Only validate if the source is set to 'list'",
"$",
"sourceElement",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'sourceElement'",
")",
";",
"$",
"sourceElementValue",
"=",
"$",
"sourceElement",
"->"... | Validates the list of domains and directives for the CSP Header.
@param string $values
@return bool | [
"Validates",
"the",
"list",
"of",
"domains",
"and",
"directives",
"for",
"the",
"CSP",
"Header",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/validators/CspHeaderValidator.php#L58-L102 |
oat-sa/tao-core | helpers/form/validators/CspHeaderValidator.php | CspHeaderValidator.getNormalizedDirective | private function getNormalizedDirective($directive)
{
$directive = strtolower($directive);
if (ctype_alpha($directive) === true) {
$directive = "'" . $directive . "'";
}
return $directive;
} | php | private function getNormalizedDirective($directive)
{
$directive = strtolower($directive);
if (ctype_alpha($directive) === true) {
$directive = "'" . $directive . "'";
}
return $directive;
} | [
"private",
"function",
"getNormalizedDirective",
"(",
"$",
"directive",
")",
"{",
"$",
"directive",
"=",
"strtolower",
"(",
"$",
"directive",
")",
";",
"if",
"(",
"ctype_alpha",
"(",
"$",
"directive",
")",
"===",
"true",
")",
"{",
"$",
"directive",
"=",
... | Check if the given directive need to be converted.
@param string $directive
@return string | [
"Check",
"if",
"the",
"given",
"directive",
"need",
"to",
"be",
"converted",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/validators/CspHeaderValidator.php#L110-L119 |
oat-sa/tao-core | helpers/form/validators/CspHeaderValidator.php | CspHeaderValidator.isValidDomain | private function isValidDomain($domain)
{
if (filter_var($domain, FILTER_VALIDATE_URL)) {
return true;
}
$regex = '~^(https?:\/\/|(\*\.){1})?(\w.+)(\.)(?!\s)(?!\.\*)(\w{2,})$~i';
return (bool) preg_match($regex, $domain);
} | php | private function isValidDomain($domain)
{
if (filter_var($domain, FILTER_VALIDATE_URL)) {
return true;
}
$regex = '~^(https?:\/\/|(\*\.){1})?(\w.+)(\.)(?!\s)(?!\.\*)(\w{2,})$~i';
return (bool) preg_match($regex, $domain);
} | [
"private",
"function",
"isValidDomain",
"(",
"$",
"domain",
")",
"{",
"if",
"(",
"filter_var",
"(",
"$",
"domain",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"regex",
"=",
"'~^(https?:\\/\\/|(\\*\\.){1})?(\\w.+)(\\.)(?!\\s)(?!\\.\\... | Check if the given domain is valid.
@param string $domain
@return bool | [
"Check",
"if",
"the",
"given",
"domain",
"is",
"valid",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/validators/CspHeaderValidator.php#L141-L149 |
oat-sa/tao-core | helpers/form/validators/CspHeaderValidator.php | CspHeaderValidator.getErrorMessage | private function getErrorMessage()
{
$directivesMessage = '';
$domainsMessage = '';
if (!empty($this->invalidValues['directives'])) {
$directivesMessage = "The following directives are invalid:\n- ";
$directivesMessage .= implode("\n- ", $this->invalidValues['directives']);
}
if (!empty($this->invalidValues['domain'])) {
$domainsMessage = "The following domains are invalid:\n- ";
$domainsMessage .= implode("\n- ", $this->invalidValues['domain']);
}
return $domainsMessage . "\n" . $directivesMessage;
} | php | private function getErrorMessage()
{
$directivesMessage = '';
$domainsMessage = '';
if (!empty($this->invalidValues['directives'])) {
$directivesMessage = "The following directives are invalid:\n- ";
$directivesMessage .= implode("\n- ", $this->invalidValues['directives']);
}
if (!empty($this->invalidValues['domain'])) {
$domainsMessage = "The following domains are invalid:\n- ";
$domainsMessage .= implode("\n- ", $this->invalidValues['domain']);
}
return $domainsMessage . "\n" . $directivesMessage;
} | [
"private",
"function",
"getErrorMessage",
"(",
")",
"{",
"$",
"directivesMessage",
"=",
"''",
";",
"$",
"domainsMessage",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"invalidValues",
"[",
"'directives'",
"]",
")",
")",
"{",
"$",
"d... | Get the error messages. | [
"Get",
"the",
"error",
"messages",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/validators/CspHeaderValidator.php#L154-L170 |
oat-sa/tao-core | helpers/class.Array.php | tao_helpers_Array.sortByField | public static function sortByField($input, $field, $descending = false)
{
$returnValue = array();
$sorted = array();
foreach($input as $key => $value ){
$sorted[$key] = $value[$field];
}
if($descending){
arsort($sorted);
}
else{
asort($sorted);
}
foreach ($sorted as $key => $value ){
$returnValue[$key] = $input[$key];
}
return (array) $returnValue;
} | php | public static function sortByField($input, $field, $descending = false)
{
$returnValue = array();
$sorted = array();
foreach($input as $key => $value ){
$sorted[$key] = $value[$field];
}
if($descending){
arsort($sorted);
}
else{
asort($sorted);
}
foreach ($sorted as $key => $value ){
$returnValue[$key] = $input[$key];
}
return (array) $returnValue;
} | [
"public",
"static",
"function",
"sortByField",
"(",
"$",
"input",
",",
"$",
"field",
",",
"$",
"descending",
"=",
"false",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"$",
"sorted",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"... | Sort an associative array on a key criterion. Uses sort or asort PHP
functions to implement the sort depending on the value of the descending
parameter.
@author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
@param array input The associative array to sort.
@param string field The key criterion.
@param boolean (optional, default = Ascending sort) descending Descending or Ascending order.
@return array An associative array. | [
"Sort",
"an",
"associative",
"array",
"on",
"a",
"key",
"criterion",
".",
"Uses",
"sort",
"or",
"asort",
"PHP",
"functions",
"to",
"implement",
"the",
"sort",
"depending",
"on",
"the",
"value",
"of",
"the",
"descending",
"parameter",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Array.php#L42-L63 |
oat-sa/tao-core | helpers/class.Array.php | tao_helpers_Array.array_unique | public static function array_unique($array)
{
$keys = array_keys($array);
$toDrop = array();
for ($i = count($keys) - 1; $i >=0 ; $i-- ) {
for ($j = $i - 1; $j >=0 ; $j--) {
if ($array[$keys[$i]]->__equals($array[$keys[$j]])) {
$toDrop[] = $keys[$i];
break;
}
}
}
foreach ($toDrop as $key) {
unset($array[$key]);
}
return $array;
} | php | public static function array_unique($array)
{
$keys = array_keys($array);
$toDrop = array();
for ($i = count($keys) - 1; $i >=0 ; $i-- ) {
for ($j = $i - 1; $j >=0 ; $j--) {
if ($array[$keys[$i]]->__equals($array[$keys[$j]])) {
$toDrop[] = $keys[$i];
break;
}
}
}
foreach ($toDrop as $key) {
unset($array[$key]);
}
return $array;
} | [
"public",
"static",
"function",
"array_unique",
"(",
"$",
"array",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"array",
")",
";",
"$",
"toDrop",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"count",
"(",
"$",
"keys",
")",
"-",
... | remove duplicate from array of objects implementing the __equal() function
@param array $array
@return array $array | [
"remove",
"duplicate",
"from",
"array",
"of",
"objects",
"implementing",
"the",
"__equal",
"()",
"function"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Array.php#L71-L87 |
oat-sa/tao-core | helpers/class.Array.php | tao_helpers_Array.containsOnlyValue | public static function containsOnlyValue($value, array $container, $strict = false, $exceptAtIndex = array())
{
if (!is_scalar($value)) {
return false;
}
if (empty($container)) {
return false;
}
$matchCount = 0;
foreach ($container as $key => $val) {
if (in_array($key, $exceptAtIndex, true)) {
continue;
}
$match = ($strict === false) ? $value == $val : $value === $val;
if (!$match) {
return false;
} else {
$matchCount++;
}
}
return $matchCount !== 0;
} | php | public static function containsOnlyValue($value, array $container, $strict = false, $exceptAtIndex = array())
{
if (!is_scalar($value)) {
return false;
}
if (empty($container)) {
return false;
}
$matchCount = 0;
foreach ($container as $key => $val) {
if (in_array($key, $exceptAtIndex, true)) {
continue;
}
$match = ($strict === false) ? $value == $val : $value === $val;
if (!$match) {
return false;
} else {
$matchCount++;
}
}
return $matchCount !== 0;
} | [
"public",
"static",
"function",
"containsOnlyValue",
"(",
"$",
"value",
",",
"array",
"$",
"container",
",",
"$",
"strict",
"=",
"false",
",",
"$",
"exceptAtIndex",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
... | Does an array contains only a given value.
Whether or not a given array contains only a given value.
<code>
// Example 1
$container = [1, 1, 1]; $value = 1; // true
$container = [1, 1, 2]; $value = 1; // false
</code>
When the $strict parameter is false, values contained in the $container array
will be compared with $value using the PHP == operator. Otherwise, the comparison
will be proceed with the PHP === operator.
Some particular indexes of $container can be ignored with the help of the $exceptAtIndex parameter.
<code>
// Example 2
$container = [1, 1, 2]; $value = 1; $exceptAtIndex = [2]; // true
$container = [1, 1, 2]; $value = 1; $exceptAtIndex = [1]; // false
</code>
* When $value is not a scalar value, the method returns false.
* When $container is empty, the method returns false.
@param mixed $value
@param array $container
@param boolean $strict
@param array $exceptAtIndex
@return boolean | [
"Does",
"an",
"array",
"contains",
"only",
"a",
"given",
"value",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Array.php#L134-L161 |
oat-sa/tao-core | helpers/class.Array.php | tao_helpers_Array.arraysContainOnlyValue | public static function arraysContainOnlyValue(array $containers, $value, $exceptNContainers = 0, array $exceptAtIndex = [], array &$invalidContainers = [], array &$validContainers = [])
{
if ($exceptNContainers < 0) {
$exceptNContainers = 0;
} else {
$exceptNContainers = intval($exceptNContainers);
}
$validCount = 0;
$rowCount = 0;
$expectedValidCount = count($containers) - intval($exceptNContainers);
foreach ($containers as $row) {
if (!is_array($row)) {
return false;
}
$valid = true;
$exceptCount = 0;
for ($i = 0; $i < count($row); $i++) {
if (in_array($i, $exceptAtIndex, true)) {
$exceptCount++;
continue;
} else if ($row[$i] !== $value) {
$valid = false;
break;
}
}
if ($exceptCount !== 0 && $exceptCount === count($row)) {
$valid = false;
}
if ($valid == true) {
$validContainers[] = $rowCount;
$validCount++;
} else {
$invalidContainers[] = $rowCount;
}
$rowCount++;
}
return $validCount === $expectedValidCount;
} | php | public static function arraysContainOnlyValue(array $containers, $value, $exceptNContainers = 0, array $exceptAtIndex = [], array &$invalidContainers = [], array &$validContainers = [])
{
if ($exceptNContainers < 0) {
$exceptNContainers = 0;
} else {
$exceptNContainers = intval($exceptNContainers);
}
$validCount = 0;
$rowCount = 0;
$expectedValidCount = count($containers) - intval($exceptNContainers);
foreach ($containers as $row) {
if (!is_array($row)) {
return false;
}
$valid = true;
$exceptCount = 0;
for ($i = 0; $i < count($row); $i++) {
if (in_array($i, $exceptAtIndex, true)) {
$exceptCount++;
continue;
} else if ($row[$i] !== $value) {
$valid = false;
break;
}
}
if ($exceptCount !== 0 && $exceptCount === count($row)) {
$valid = false;
}
if ($valid == true) {
$validContainers[] = $rowCount;
$validCount++;
} else {
$invalidContainers[] = $rowCount;
}
$rowCount++;
}
return $validCount === $expectedValidCount;
} | [
"public",
"static",
"function",
"arraysContainOnlyValue",
"(",
"array",
"$",
"containers",
",",
"$",
"value",
",",
"$",
"exceptNContainers",
"=",
"0",
",",
"array",
"$",
"exceptAtIndex",
"=",
"[",
"]",
",",
"array",
"&",
"$",
"invalidContainers",
"=",
"[",
... | Does a collection of arrays contain only a given value.
Whether or not a given collection of arrays contain only a given $value.
* You can specify that some indexes of contained arrays do not have to match $value by setting the $exceptAtIndex array with the indexes to be ignored.
* When $exceptNContainers > 0, it is allowed that $containers contains $exceptNContainers arrays not matching $value.
* The $invalidContainers parameter is an optional reference that will be filled with the index of arrays from $containers that do not contain the $value value only.
* The $validContainers parameter is an optional reference that will be filled with the index of array from $containers that do contain the $value value only.
@param array $containers
@param mixed $value
@param integer $exceptNContainers
@param array $exceptAtIndex
@param array $invalidContainers
@param array $validContainers
@return boolean | [
"Does",
"a",
"collection",
"of",
"arrays",
"contain",
"only",
"a",
"given",
"value",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Array.php#L181-L229 |
oat-sa/tao-core | helpers/class.Array.php | tao_helpers_Array.minArrayCountValues | public static function minArrayCountValues($values, array $arrays, $returnAll = false)
{
if (!is_array($values)) {
$values = [$values];
}
$counts = [];
foreach ($arrays as $index => $arr) {
$counts[$index] = 0;
if (!is_array($arr)) {
return false;
}
$arrayCountValues = array_count_values($arr);
foreach ($values as $value) {
$keys = array_keys($arrayCountValues);
if (($search = array_search($value, $keys)) !== false) {
$counts[$index] += $arrayCountValues[$keys[$search]];
}
}
}
if (count($counts) > 0) {
$mins = array_keys($counts, min($counts));
return ($returnAll) ? $mins : $mins[0];
} else {
return false;
}
} | php | public static function minArrayCountValues($values, array $arrays, $returnAll = false)
{
if (!is_array($values)) {
$values = [$values];
}
$counts = [];
foreach ($arrays as $index => $arr) {
$counts[$index] = 0;
if (!is_array($arr)) {
return false;
}
$arrayCountValues = array_count_values($arr);
foreach ($values as $value) {
$keys = array_keys($arrayCountValues);
if (($search = array_search($value, $keys)) !== false) {
$counts[$index] += $arrayCountValues[$keys[$search]];
}
}
}
if (count($counts) > 0) {
$mins = array_keys($counts, min($counts));
return ($returnAll) ? $mins : $mins[0];
} else {
return false;
}
} | [
"public",
"static",
"function",
"minArrayCountValues",
"(",
"$",
"values",
",",
"array",
"$",
"arrays",
",",
"$",
"returnAll",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"[",
"$",
"value... | Detect Row with Minimum of Value(s)
This method helps you to dectect which is the array contained in $arrays containing
the less amount of specific value(s).
Pleae note that the detection comparison is NOT strict (using the == PHP operator).
@param mixed $values Can be either scalar or array.
@param array $arrays An array of arrays.
@param boolean $returnAll Wheter or not return an array of keys when some amounts of specific values are similar accross $arrays.
@return mixed Key(s) of the array(s) containing the less amount of $values. or false if it not possible to designate a row. | [
"Detect",
"Row",
"with",
"Minimum",
"of",
"Value",
"(",
"s",
")"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Array.php#L244-L278 |
oat-sa/tao-core | helpers/class.Array.php | tao_helpers_Array.countConsistentColumns | public static function countConsistentColumns(array $matrix, array $ignoreValues = [], $emptyIsConsistent = false)
{
$consistentCount = 0;
if (!self::isValidMatrix($matrix)) {
return $consistentCount;
}
for ($i = 0; $i < count($matrix[0]); $i++) {
$column = array_column($matrix, $i);
if (count($column) !== count($matrix)) {
// Malformed matrix.
return false;
}
$column = array_unique($column);
foreach ($ignoreValues as $ignoreVal) {
if (($search = array_search($ignoreVal, $column, true)) !== false) {
unset($column[$search]);
}
}
if (count($column) === 1) {
$consistentCount++;
} elseif (count($column) === 0 && $emptyIsConsistent) {
$consistentCount++;
}
}
return $consistentCount;
} | php | public static function countConsistentColumns(array $matrix, array $ignoreValues = [], $emptyIsConsistent = false)
{
$consistentCount = 0;
if (!self::isValidMatrix($matrix)) {
return $consistentCount;
}
for ($i = 0; $i < count($matrix[0]); $i++) {
$column = array_column($matrix, $i);
if (count($column) !== count($matrix)) {
// Malformed matrix.
return false;
}
$column = array_unique($column);
foreach ($ignoreValues as $ignoreVal) {
if (($search = array_search($ignoreVal, $column, true)) !== false) {
unset($column[$search]);
}
}
if (count($column) === 1) {
$consistentCount++;
} elseif (count($column) === 0 && $emptyIsConsistent) {
$consistentCount++;
}
}
return $consistentCount;
} | [
"public",
"static",
"function",
"countConsistentColumns",
"(",
"array",
"$",
"matrix",
",",
"array",
"$",
"ignoreValues",
"=",
"[",
"]",
",",
"$",
"emptyIsConsistent",
"=",
"false",
")",
"{",
"$",
"consistentCount",
"=",
"0",
";",
"if",
"(",
"!",
"self",
... | Count the Amount of Consistent Columns in Matrix
This method aims at counting the number of columns in a $matrix containing strictly similar values.
@param array $matrix An array containing exclusively arrays.
@param array $ignoreValues An array of values to be ignored while comparing values within columns.
@param array $emptyIsConsistent (optional) Consider empty columns (after ignoring values) as consistent.
@return mixed The amount of consistent columns in $matrix or false if $matrix is not a well formed matrix. | [
"Count",
"the",
"Amount",
"of",
"Consistent",
"Columns",
"in",
"Matrix"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Array.php#L290-L321 |
oat-sa/tao-core | actions/class.Lock.php | tao_actions_Lock.locked | public function locked()
{
$this->defaultData();
$resource = $this->getResource($this->getRequestParameter('id'));
$lockData = LockManager::getImplementation()->getLockData($resource);
$this->setData('topclass-label',
$this->hasRequestParameter('topclass-label') ? $this->getRequestParameter('topclass-label') : __('Resource')
);
if (AclProxy::hasAccess($this->getSession()->getUser(), __CLASS__, 'forceRelease', array('uri' => $resource->getUri()))) {
$this->setData('id', $resource->getUri());
$this->setData('forceRelease', true);
}
$this->setData('lockDate', $lockData->getCreationTime());
$this->setData('ownerHtml', UserHelper::renderHtmlUser($lockData->getOwnerId()));
if ($this->hasRequestParameter('view') && $this->hasRequestParameter('ext')) {
$this->setView($this->getRequestParameter('view'), $this->getRequestParameter('ext'));
} else {
$this->setView('Lock/locked.tpl', 'tao');
}
} | php | public function locked()
{
$this->defaultData();
$resource = $this->getResource($this->getRequestParameter('id'));
$lockData = LockManager::getImplementation()->getLockData($resource);
$this->setData('topclass-label',
$this->hasRequestParameter('topclass-label') ? $this->getRequestParameter('topclass-label') : __('Resource')
);
if (AclProxy::hasAccess($this->getSession()->getUser(), __CLASS__, 'forceRelease', array('uri' => $resource->getUri()))) {
$this->setData('id', $resource->getUri());
$this->setData('forceRelease', true);
}
$this->setData('lockDate', $lockData->getCreationTime());
$this->setData('ownerHtml', UserHelper::renderHtmlUser($lockData->getOwnerId()));
if ($this->hasRequestParameter('view') && $this->hasRequestParameter('ext')) {
$this->setView($this->getRequestParameter('view'), $this->getRequestParameter('ext'));
} else {
$this->setView('Lock/locked.tpl', 'tao');
}
} | [
"public",
"function",
"locked",
"(",
")",
"{",
"$",
"this",
"->",
"defaultData",
"(",
")",
";",
"$",
"resource",
"=",
"$",
"this",
"->",
"getResource",
"(",
"$",
"this",
"->",
"getRequestParameter",
"(",
"'id'",
")",
")",
";",
"$",
"lockData",
"=",
"... | actions that get prevented by a lock are forwareded to this action
parameter view is currently ignored | [
"actions",
"that",
"get",
"prevented",
"by",
"a",
"lock",
"are",
"forwareded",
"to",
"this",
"action",
"parameter",
"view",
"is",
"currently",
"ignored"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.Lock.php#L41-L64 |
oat-sa/tao-core | helpers/DateIntervalMS.php | DateIntervalMS.format | public function format($format)
{
$format = str_replace('%U', sprintf("%06d", $this->u), $format);
$format = str_replace('%u', sprintf("%d", intval($this->u)), $format);
return parent::format($format);
} | php | public function format($format)
{
$format = str_replace('%U', sprintf("%06d", $this->u), $format);
$format = str_replace('%u', sprintf("%d", intval($this->u)), $format);
return parent::format($format);
} | [
"public",
"function",
"format",
"(",
"$",
"format",
")",
"{",
"$",
"format",
"=",
"str_replace",
"(",
"'%U'",
",",
"sprintf",
"(",
"\"%06d\"",
",",
"$",
"this",
"->",
"u",
")",
",",
"$",
"format",
")",
";",
"$",
"format",
"=",
"str_replace",
"(",
"... | Formatting for current date interval
@param $format
@return string | [
"Formatting",
"for",
"current",
"date",
"interval"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/DateIntervalMS.php#L55-L61 |
oat-sa/tao-core | helpers/DateIntervalMS.php | DateIntervalMS.getLegacySpec | private static function getLegacySpec(array $parts)
{
$spec = "P";
$spec .= $parts['y'] !== "" ? "{$parts['y']}Y" : "";
$spec .= $parts['m'] !== "" ? "{$parts['m']}M" : "";
$spec .= $parts['d'] !== "" ? "{$parts['d']}D" : "";
if ($parts['h'] . $parts['i'] . $parts['s'] !== "") {
$spec .= "T";
$spec .= $parts['h'] !== "" ? "{$parts['h']}H" : "";
$spec .= $parts['i'] !== "" ? "{$parts['i']}M" : "";
$spec .= $parts['s'] !== "" ? "{$parts['s']}S" : "";
}
if ($spec === "P") {
$spec = "";
}
return $spec;
} | php | private static function getLegacySpec(array $parts)
{
$spec = "P";
$spec .= $parts['y'] !== "" ? "{$parts['y']}Y" : "";
$spec .= $parts['m'] !== "" ? "{$parts['m']}M" : "";
$spec .= $parts['d'] !== "" ? "{$parts['d']}D" : "";
if ($parts['h'] . $parts['i'] . $parts['s'] !== "") {
$spec .= "T";
$spec .= $parts['h'] !== "" ? "{$parts['h']}H" : "";
$spec .= $parts['i'] !== "" ? "{$parts['i']}M" : "";
$spec .= $parts['s'] !== "" ? "{$parts['s']}S" : "";
}
if ($spec === "P") {
$spec = "";
}
return $spec;
} | [
"private",
"static",
"function",
"getLegacySpec",
"(",
"array",
"$",
"parts",
")",
"{",
"$",
"spec",
"=",
"\"P\"",
";",
"$",
"spec",
".=",
"$",
"parts",
"[",
"'y'",
"]",
"!==",
"\"\"",
"?",
"\"{$parts['y']}Y\"",
":",
"\"\"",
";",
"$",
"spec",
".=",
"... | Build valid DateInterval format
@param array $parts
@return string | [
"Build",
"valid",
"DateInterval",
"format"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/DateIntervalMS.php#L94-L111 |
oat-sa/tao-core | models/classes/class.Service.php | tao_models_classes_Service.getServiceByName | public static function getServiceByName($serviceName) {
$returnValue = null;
$className = (!class_exists($serviceName) || !preg_match("/^(tao|wf)/", $serviceName)) ? sprintf(self::namePattern, ucfirst(strtolower($serviceName))) : $serviceName;
// does the class exist
if (!class_exists($className)) {
throw new common_exception_Error('Tried to init abstract class ' . $className);
}
$class = new ReflectionClass($className);
// is it concrete
if ($class->isAbstract()) {
throw new common_exception_Error('Tried to init abstract class ' . $className . ' for param \'' . $serviceName . '\'');
}
// does it extend Service
if (!$class->isSubclassOf('tao_models_classes_Service')) {
throw new common_exception_Error("$className must referr to a class extending the tao_models_classes_Service");
}
//create the instance only once
if (!isset(self::$instances[$className])) {
self::$instances[$className] = new $className();
}
//get the instance
$returnValue = self::$instances[$className];
return $returnValue;
} | php | public static function getServiceByName($serviceName) {
$returnValue = null;
$className = (!class_exists($serviceName) || !preg_match("/^(tao|wf)/", $serviceName)) ? sprintf(self::namePattern, ucfirst(strtolower($serviceName))) : $serviceName;
// does the class exist
if (!class_exists($className)) {
throw new common_exception_Error('Tried to init abstract class ' . $className);
}
$class = new ReflectionClass($className);
// is it concrete
if ($class->isAbstract()) {
throw new common_exception_Error('Tried to init abstract class ' . $className . ' for param \'' . $serviceName . '\'');
}
// does it extend Service
if (!$class->isSubclassOf('tao_models_classes_Service')) {
throw new common_exception_Error("$className must referr to a class extending the tao_models_classes_Service");
}
//create the instance only once
if (!isset(self::$instances[$className])) {
self::$instances[$className] = new $className();
}
//get the instance
$returnValue = self::$instances[$className];
return $returnValue;
} | [
"public",
"static",
"function",
"getServiceByName",
"(",
"$",
"serviceName",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"$",
"className",
"=",
"(",
"!",
"class_exists",
"(",
"$",
"serviceName",
")",
"||",
"!",
"preg_match",
"(",
"\"/^(tao|wf)/\"",
",",
... | returns an instance of the service defined by servicename. Always returns
same instance for a class
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@deprecated
@param string $serviceName
@return tao_models_classes_Service
@throws common_exception_Error | [
"returns",
"an",
"instance",
"of",
"the",
"service",
"defined",
"by",
"servicename",
".",
"Always",
"returns",
"same",
"instance",
"for",
"a",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.Service.php#L85-L116 |
oat-sa/tao-core | models/classes/class.Service.php | tao_models_classes_Service.singleton | public static function singleton() {
$returnValue = null;
$serviceName = get_called_class();
if (!isset(self::$instances[$serviceName])) {
self::$instances[$serviceName] = new $serviceName();
}
$returnValue = self::$instances[$serviceName];
return $returnValue;
} | php | public static function singleton() {
$returnValue = null;
$serviceName = get_called_class();
if (!isset(self::$instances[$serviceName])) {
self::$instances[$serviceName] = new $serviceName();
}
$returnValue = self::$instances[$serviceName];
return $returnValue;
} | [
"public",
"static",
"function",
"singleton",
"(",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"$",
"serviceName",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"serviceName",
"]",
")... | returns an instance of the service the function was called from. Always
the same instance for a class
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return $this | [
"returns",
"an",
"instance",
"of",
"the",
"service",
"the",
"function",
"was",
"called",
"from",
".",
"Always",
"the",
"same",
"instance",
"for",
"a",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.Service.php#L126-L139 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.