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.RestResource.php | tao_actions_RestResource.returnSuccess | protected function returnSuccess($rawData = array(), $withMessage=true)
{
$data = array();
if ($withMessage) {
$data['success'] = true;
$data['data'] = $rawData;
$data['version'] = TAO_VERSION;
} else {
$data = $rawData;
}
$this->returnJson($data);
// exit(0);
} | php | protected function returnSuccess($rawData = array(), $withMessage=true)
{
$data = array();
if ($withMessage) {
$data['success'] = true;
$data['data'] = $rawData;
$data['version'] = TAO_VERSION;
} else {
$data = $rawData;
}
$this->returnJson($data);
// exit(0);
} | [
"protected",
"function",
"returnSuccess",
"(",
"$",
"rawData",
"=",
"array",
"(",
")",
",",
"$",
"withMessage",
"=",
"true",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"withMessage",
")",
"{",
"$",
"data",
"[",
"'success'",
... | Return a successful http response
@param array $rawData
@param bool $withMessage | [
"Return",
"a",
"successful",
"http",
"response"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RestResource.php#L338-L351 |
oat-sa/tao-core | actions/class.PasswordRecovery.php | tao_actions_PasswordRecovery.index | public function index()
{
$this->defaultData();
$formContainer = new tao_actions_form_PasswordRecovery();
$form = $formContainer->getForm();
if ($form->isSubmited() && $form->isValid()) {
$mail = $form->getValue('userMail');
$user = $this->getPasswordRecovery()->getUser(GenerisRdf::PROPERTY_USER_MAIL, $mail);
if ($user !== null) {
$this->logInfo("User requests a password (user URI: {$user->getUri()})");
$this->sendMessage($user);
} else {
$this->logInfo("Unsuccessful recovery password. Entered e-mail address: {$mail}.");
$this->setData('header', __('An email has been sent'));
$this->setData('info', __('A message with further instructions has been sent to your email address: %s', $mail));
}
$this->setData('content-template', array('passwordRecovery/password-recovery-info.tpl', 'tao'));
} else {
$this->setData('form', $form->render());
$this->setData('content-template', array('passwordRecovery/index.tpl', 'tao'));
}
$this->setView('layout.tpl', 'tao');
} | php | public function index()
{
$this->defaultData();
$formContainer = new tao_actions_form_PasswordRecovery();
$form = $formContainer->getForm();
if ($form->isSubmited() && $form->isValid()) {
$mail = $form->getValue('userMail');
$user = $this->getPasswordRecovery()->getUser(GenerisRdf::PROPERTY_USER_MAIL, $mail);
if ($user !== null) {
$this->logInfo("User requests a password (user URI: {$user->getUri()})");
$this->sendMessage($user);
} else {
$this->logInfo("Unsuccessful recovery password. Entered e-mail address: {$mail}.");
$this->setData('header', __('An email has been sent'));
$this->setData('info', __('A message with further instructions has been sent to your email address: %s', $mail));
}
$this->setData('content-template', array('passwordRecovery/password-recovery-info.tpl', 'tao'));
} else {
$this->setData('form', $form->render());
$this->setData('content-template', array('passwordRecovery/index.tpl', 'tao'));
}
$this->setView('layout.tpl', 'tao');
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"this",
"->",
"defaultData",
"(",
")",
";",
"$",
"formContainer",
"=",
"new",
"tao_actions_form_PasswordRecovery",
"(",
")",
";",
"$",
"form",
"=",
"$",
"formContainer",
"->",
"getForm",
"(",
")",
";",
"... | Show password recovery request form
@author Aleh Hutnikau <hutnikau@1pt.com>
@return void | [
"Show",
"password",
"recovery",
"request",
"form"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PasswordRecovery.php#L40-L65 |
oat-sa/tao-core | actions/class.PasswordRecovery.php | tao_actions_PasswordRecovery.resetPassword | public function resetPassword()
{
$this->defaultData();
$token = $this->getRequestParameter('token');
$formContainer = new tao_actions_form_ResetUserPassword();
$form = $formContainer->getForm();
$form->setValues(array('token'=>$token));
$user = $this->getPasswordRecovery()->getUser(PasswordRecoveryService::PROPERTY_PASSWORD_RECOVERY_TOKEN, $token);
if ($user === null) {
$this->logInfo("Password recovery token not found. Token value: {$token}");
$this->setData('header', __('User not found'));
$this->setData('error', __('This password reset link is no longer valid. It may have already been used. If you still wish to reset your password please request a new link'));
$this->setData('content-template', array('passwordRecovery/password-recovery-info.tpl', 'tao'));
} else {
if ($form->isSubmited() && $form->isValid()) {
$this->getPasswordRecovery()->setPassword($user, $form->getValue('newpassword'));
$this->logInfo("User {$user->getUri()} has changed the password.");
$this->setData('info', __("Password successfully changed"));
$this->setData('content-template', array('passwordRecovery/password-recovery-info.tpl', 'tao'));
} else {
$this->setData('form', $form->render());
$this->setData('content-template', array('passwordRecovery/password-reset.tpl', 'tao'));
}
}
$this->setView('layout.tpl', 'tao');
} | php | public function resetPassword()
{
$this->defaultData();
$token = $this->getRequestParameter('token');
$formContainer = new tao_actions_form_ResetUserPassword();
$form = $formContainer->getForm();
$form->setValues(array('token'=>$token));
$user = $this->getPasswordRecovery()->getUser(PasswordRecoveryService::PROPERTY_PASSWORD_RECOVERY_TOKEN, $token);
if ($user === null) {
$this->logInfo("Password recovery token not found. Token value: {$token}");
$this->setData('header', __('User not found'));
$this->setData('error', __('This password reset link is no longer valid. It may have already been used. If you still wish to reset your password please request a new link'));
$this->setData('content-template', array('passwordRecovery/password-recovery-info.tpl', 'tao'));
} else {
if ($form->isSubmited() && $form->isValid()) {
$this->getPasswordRecovery()->setPassword($user, $form->getValue('newpassword'));
$this->logInfo("User {$user->getUri()} has changed the password.");
$this->setData('info', __("Password successfully changed"));
$this->setData('content-template', array('passwordRecovery/password-recovery-info.tpl', 'tao'));
} else {
$this->setData('form', $form->render());
$this->setData('content-template', array('passwordRecovery/password-reset.tpl', 'tao'));
}
}
$this->setView('layout.tpl', 'tao');
} | [
"public",
"function",
"resetPassword",
"(",
")",
"{",
"$",
"this",
"->",
"defaultData",
"(",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"'token'",
")",
";",
"$",
"formContainer",
"=",
"new",
"tao_actions_form_ResetUserPassword"... | Password resrt form
@author Aleh Hutnikau <hutnikau@1pt.com>
@return void | [
"Password",
"resrt",
"form"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PasswordRecovery.php#L73-L102 |
oat-sa/tao-core | actions/class.PasswordRecovery.php | tao_actions_PasswordRecovery.sendMessage | private function sendMessage(core_kernel_classes_Resource $user)
{
try {
$messageSent = $this->getPasswordRecovery()->sendMail($user);
} catch (Exception $e) {
$messageSent = false;
$this->logWarning("Unsuccessful recovery password. {$e->getMessage()}.");
}
if ($messageSent) {
$mail = $this->getPasswordRecovery()->getUserMail($user);
$this->setData('header', __('An email has been sent'));
$this->setData('info', __('A message with further instructions has been sent to your email address: %s', $mail));
} else {
$this->setData('error', __('Unable to send the password reset request'));
}
} | php | private function sendMessage(core_kernel_classes_Resource $user)
{
try {
$messageSent = $this->getPasswordRecovery()->sendMail($user);
} catch (Exception $e) {
$messageSent = false;
$this->logWarning("Unsuccessful recovery password. {$e->getMessage()}.");
}
if ($messageSent) {
$mail = $this->getPasswordRecovery()->getUserMail($user);
$this->setData('header', __('An email has been sent'));
$this->setData('info', __('A message with further instructions has been sent to your email address: %s', $mail));
} else {
$this->setData('error', __('Unable to send the password reset request'));
}
} | [
"private",
"function",
"sendMessage",
"(",
"core_kernel_classes_Resource",
"$",
"user",
")",
"{",
"try",
"{",
"$",
"messageSent",
"=",
"$",
"this",
"->",
"getPasswordRecovery",
"(",
")",
"->",
"sendMail",
"(",
"$",
"user",
")",
";",
"}",
"catch",
"(",
"Exc... | Send message with password recovery instructions
@author Aleh Hutnikau <hutnikau@1pt.com>
@param User $user
@return void | [
"Send",
"message",
"with",
"password",
"recovery",
"instructions"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.PasswordRecovery.php#L111-L127 |
oat-sa/tao-core | helpers/translation/class.POTranslationUnit.php | tao_helpers_translation_POTranslationUnit.addFlag | public function addFlag($flag)
{
$currentAnnotations = $this->getAnnotations();
if (!isset($currentAnnotations[self::FLAGS])){
$currentAnnotations[self::FLAGS] = $flag;
}
else if (!(mb_strpos($currentAnnotations[self::FLAGS], $flag, 0, TAO_DEFAULT_ENCODING) !== false)){
$currentAnnotations[self::FLAGS] .= " ${flag}";
}
$this->setAnnotations($currentAnnotations);
} | php | public function addFlag($flag)
{
$currentAnnotations = $this->getAnnotations();
if (!isset($currentAnnotations[self::FLAGS])){
$currentAnnotations[self::FLAGS] = $flag;
}
else if (!(mb_strpos($currentAnnotations[self::FLAGS], $flag, 0, TAO_DEFAULT_ENCODING) !== false)){
$currentAnnotations[self::FLAGS] .= " ${flag}";
}
$this->setAnnotations($currentAnnotations);
} | [
"public",
"function",
"addFlag",
"(",
"$",
"flag",
")",
"{",
"$",
"currentAnnotations",
"=",
"$",
"this",
"->",
"getAnnotations",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"currentAnnotations",
"[",
"self",
"::",
"FLAGS",
"]",
")",
")",
"{",
... | Add a PO compliant flag to the TranslationUnit. The FLAGS annotation will
created if no flags were added before.
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param string flag A flag string.
@return void | [
"Add",
"a",
"PO",
"compliant",
"flag",
"to",
"the",
"TranslationUnit",
".",
"The",
"FLAGS",
"annotation",
"will",
"created",
"if",
"no",
"flags",
"were",
"added",
"before",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.POTranslationUnit.php#L105-L118 |
oat-sa/tao-core | helpers/translation/class.POTranslationUnit.php | tao_helpers_translation_POTranslationUnit.removeFlag | public function removeFlag($flag)
{
$currentFlags = $this->getFlags();
for ($i = 0; $i < count($currentFlags); $i++){
if ($currentFlags[$i] == $flag){
break;
}
}
if ($i <= count($currentFlags)){
// The flag is found.
unset($currentFlags[$i]);
$this->setFlags($currentFlags);
}
} | php | public function removeFlag($flag)
{
$currentFlags = $this->getFlags();
for ($i = 0; $i < count($currentFlags); $i++){
if ($currentFlags[$i] == $flag){
break;
}
}
if ($i <= count($currentFlags)){
// The flag is found.
unset($currentFlags[$i]);
$this->setFlags($currentFlags);
}
} | [
"public",
"function",
"removeFlag",
"(",
"$",
"flag",
")",
"{",
"$",
"currentFlags",
"=",
"$",
"this",
"->",
"getFlags",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"currentFlags",
")",
";",
"$",
"i",
"... | Remove a given PO compliant flag from the TranslationUnit. The FLAGS
will be removed from the TranslationUnit if it was the last one of the
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param string flag A flag string.
@return void | [
"Remove",
"a",
"given",
"PO",
"compliant",
"flag",
"from",
"the",
"TranslationUnit",
".",
"The",
"FLAGS",
"will",
"be",
"removed",
"from",
"the",
"TranslationUnit",
"if",
"it",
"was",
"the",
"last",
"one",
"of",
"the"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.POTranslationUnit.php#L129-L145 |
oat-sa/tao-core | helpers/translation/class.POTranslationUnit.php | tao_helpers_translation_POTranslationUnit.hasFlag | public function hasFlag($flag)
{
$returnValue = (bool) false;
foreach ($this->getFlags() as $f){
if ($f == $flag){
$returnValue = true;
break;
}
}
return (bool) $returnValue;
} | php | public function hasFlag($flag)
{
$returnValue = (bool) false;
foreach ($this->getFlags() as $f){
if ($f == $flag){
$returnValue = true;
break;
}
}
return (bool) $returnValue;
} | [
"public",
"function",
"hasFlag",
"(",
"$",
"flag",
")",
"{",
"$",
"returnValue",
"=",
"(",
"bool",
")",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFlags",
"(",
")",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"f",
"==",
"$",
"flag",
")"... | Short description of method hasFlag
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param string flag A PO flag string.
@return boolean | [
"Short",
"description",
"of",
"method",
"hasFlag"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.POTranslationUnit.php#L155-L169 |
oat-sa/tao-core | helpers/translation/class.POTranslationUnit.php | tao_helpers_translation_POTranslationUnit.getFlags | public function getFlags()
{
$returnValue = array();
$currentAnnotations = $this->getAnnotations();
if (isset($currentAnnotations[self::FLAGS])){
$returnValue = explode(" ", $currentAnnotations[self::FLAGS]);
}
return (array) $returnValue;
} | php | public function getFlags()
{
$returnValue = array();
$currentAnnotations = $this->getAnnotations();
if (isset($currentAnnotations[self::FLAGS])){
$returnValue = explode(" ", $currentAnnotations[self::FLAGS]);
}
return (array) $returnValue;
} | [
"public",
"function",
"getFlags",
"(",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"$",
"currentAnnotations",
"=",
"$",
"this",
"->",
"getAnnotations",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"currentAnnotations",
"[",
"self",
"::",
... | Get the flags associated to the TranslationUnit. If there are no flags,
empty array is returned. Otherwise, a collection of strings is returned.
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@return array | [
"Get",
"the",
"flags",
"associated",
"to",
"the",
"TranslationUnit",
".",
"If",
"there",
"are",
"no",
"flags",
"empty",
"array",
"is",
"returned",
".",
"Otherwise",
"a",
"collection",
"of",
"strings",
"is",
"returned",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.POTranslationUnit.php#L179-L191 |
oat-sa/tao-core | helpers/translation/class.POTranslationUnit.php | tao_helpers_translation_POTranslationUnit.setFlags | public function setFlags($flags)
{
$currentAnnotations = $this->getAnnotations();
$currentAnnotations[self::FLAGS] = implode(" ", $flags);
$this->setAnnotations($currentAnnotations);
} | php | public function setFlags($flags)
{
$currentAnnotations = $this->getAnnotations();
$currentAnnotations[self::FLAGS] = implode(" ", $flags);
$this->setAnnotations($currentAnnotations);
} | [
"public",
"function",
"setFlags",
"(",
"$",
"flags",
")",
"{",
"$",
"currentAnnotations",
"=",
"$",
"this",
"->",
"getAnnotations",
"(",
")",
";",
"$",
"currentAnnotations",
"[",
"self",
"::",
"FLAGS",
"]",
"=",
"implode",
"(",
"\" \"",
",",
"$",
"flags"... | Associate a collection of PO flags to the TranslationUnit. A FLAGS
will be added to the TranslationUnit will be added consequently to the
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param array flags An array of PO string flags. | [
"Associate",
"a",
"collection",
"of",
"PO",
"flags",
"to",
"the",
"TranslationUnit",
".",
"A",
"FLAGS",
"will",
"be",
"added",
"to",
"the",
"TranslationUnit",
"will",
"be",
"added",
"consequently",
"to",
"the"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.POTranslationUnit.php#L201-L208 |
oat-sa/tao-core | models/classes/controllerMap/Factory.php | Factory.getActionDescription | public function getActionDescription($controllerClassName, $actionName) {
if (!class_exists($controllerClassName) || !method_exists($controllerClassName, $actionName)) {
throw new ActionNotFoundException('Unknown '.$controllerClassName.'@'.$actionName);
}
$reflector = new \ReflectionMethod($controllerClassName, $actionName);
return new ActionDescription($reflector);
} | php | public function getActionDescription($controllerClassName, $actionName) {
if (!class_exists($controllerClassName) || !method_exists($controllerClassName, $actionName)) {
throw new ActionNotFoundException('Unknown '.$controllerClassName.'@'.$actionName);
}
$reflector = new \ReflectionMethod($controllerClassName, $actionName);
return new ActionDescription($reflector);
} | [
"public",
"function",
"getActionDescription",
"(",
"$",
"controllerClassName",
",",
"$",
"actionName",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"controllerClassName",
")",
"||",
"!",
"method_exists",
"(",
"$",
"controllerClassName",
",",
"$",
"actionN... | Get a description of the action
@param string $controllerClassName
@param string $actionName
@return ActionDescription
@throws ActionNotFoundException | [
"Get",
"a",
"description",
"of",
"the",
"action"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/controllerMap/Factory.php#L76-L84 |
oat-sa/tao-core | models/classes/controllerMap/Factory.php | Factory.getControllerClasses | private function getControllerClasses(\common_ext_Extension $extension) {
$returnValue = array();
// routes
$namespaces = array();
foreach ($extension->getManifest()->getRoutes() as $mapedPath => $ns) {
if (is_string($ns)) {
$namespaces[] = trim($ns, '\\');
}
}
if (!empty($namespaces)) {
common_Logger::t('Namespace found in routes for extension '. $extension->getId() );
$classes = array();
$recDir = new RecursiveDirectoryIterator($extension->getDir());
$recIt = new RecursiveIteratorIterator($recDir);
$regexIt = new RegexIterator($recIt, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($regexIt as $entry) {
$info = helpers_PhpTools::getClassInfo($entry[0]);
if (!empty($info['ns'])) {
$ns = trim($info['ns'], '\\');
if (!empty($info['ns']) && in_array($ns, $namespaces)) {
$returnValue[$info['class']] = $ns.'\\'.$info['class'];
}
}
}
}
// legacy
if ($extension->hasConstant('DIR_ACTIONS') && file_exists($extension->getConstant('DIR_ACTIONS'))) {
$dir = new DirectoryIterator($extension->getConstant('DIR_ACTIONS'));
foreach ($dir as $fileinfo) {
if(preg_match('/^class\.[^.]*\.php$/', $fileinfo->getFilename())) {
$module = substr($fileinfo->getFilename(), 6, -4);
$returnValue[$module] = $extension->getId().'_actions_'.$module;
}
}
}
$returnValue = array_filter( $returnValue, array($this, 'isControllerClassNameValid') );
return (array) $returnValue;
} | php | private function getControllerClasses(\common_ext_Extension $extension) {
$returnValue = array();
// routes
$namespaces = array();
foreach ($extension->getManifest()->getRoutes() as $mapedPath => $ns) {
if (is_string($ns)) {
$namespaces[] = trim($ns, '\\');
}
}
if (!empty($namespaces)) {
common_Logger::t('Namespace found in routes for extension '. $extension->getId() );
$classes = array();
$recDir = new RecursiveDirectoryIterator($extension->getDir());
$recIt = new RecursiveIteratorIterator($recDir);
$regexIt = new RegexIterator($recIt, '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH);
foreach ($regexIt as $entry) {
$info = helpers_PhpTools::getClassInfo($entry[0]);
if (!empty($info['ns'])) {
$ns = trim($info['ns'], '\\');
if (!empty($info['ns']) && in_array($ns, $namespaces)) {
$returnValue[$info['class']] = $ns.'\\'.$info['class'];
}
}
}
}
// legacy
if ($extension->hasConstant('DIR_ACTIONS') && file_exists($extension->getConstant('DIR_ACTIONS'))) {
$dir = new DirectoryIterator($extension->getConstant('DIR_ACTIONS'));
foreach ($dir as $fileinfo) {
if(preg_match('/^class\.[^.]*\.php$/', $fileinfo->getFilename())) {
$module = substr($fileinfo->getFilename(), 6, -4);
$returnValue[$module] = $extension->getId().'_actions_'.$module;
}
}
}
$returnValue = array_filter( $returnValue, array($this, 'isControllerClassNameValid') );
return (array) $returnValue;
} | [
"private",
"function",
"getControllerClasses",
"(",
"\\",
"common_ext_Extension",
"$",
"extension",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"// routes",
"$",
"namespaces",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"extension",
"->"... | Helper to find all controllers
@param \common_ext_Extension $extension
@return array
@ignore | [
"Helper",
"to",
"find",
"all",
"controllers"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/controllerMap/Factory.php#L93-L134 |
oat-sa/tao-core | models/classes/controllerMap/Factory.php | Factory.isControllerClassNameValid | private function isControllerClassNameValid($controllerClassName)
{
$returnValue = true;
if (!class_exists($controllerClassName)) {
common_Logger::w($controllerClassName.' not found');
$returnValue = false;
} elseif (!is_subclass_of($controllerClassName, 'Module') && !is_subclass_of($controllerClassName, Controller::class)) {
common_Logger::w($controllerClassName.' is not a valid Controller.');
$returnValue = false;
} else {
// abstract so just move along
$reflection = new \ReflectionClass($controllerClassName);
if ($reflection->isAbstract()) {
common_Logger::i($controllerClassName.' is abstract');
$returnValue = false;
}
}
return $returnValue;
} | php | private function isControllerClassNameValid($controllerClassName)
{
$returnValue = true;
if (!class_exists($controllerClassName)) {
common_Logger::w($controllerClassName.' not found');
$returnValue = false;
} elseif (!is_subclass_of($controllerClassName, 'Module') && !is_subclass_of($controllerClassName, Controller::class)) {
common_Logger::w($controllerClassName.' is not a valid Controller.');
$returnValue = false;
} else {
// abstract so just move along
$reflection = new \ReflectionClass($controllerClassName);
if ($reflection->isAbstract()) {
common_Logger::i($controllerClassName.' is abstract');
$returnValue = false;
}
}
return $returnValue;
} | [
"private",
"function",
"isControllerClassNameValid",
"(",
"$",
"controllerClassName",
")",
"{",
"$",
"returnValue",
"=",
"true",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"controllerClassName",
")",
")",
"{",
"common_Logger",
"::",
"w",
"(",
"$",
"control... | Validates controller class name to:
- exist
- have valid base class
- be not abstract
@param string $controllerClassName
@return bool | [
"Validates",
"controller",
"class",
"name",
"to",
":",
"-",
"exist",
"-",
"have",
"valid",
"base",
"class",
"-",
"be",
"not",
"abstract"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/controllerMap/Factory.php#L146-L166 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.getPublicAccessUrl | public function getPublicAccessUrl()
{
if (is_null($this->accessProvider)) {
common_Logger::e('accessss');
throw new common_Exception('Tried obtaining access to private directory with ID ' . $this->getId());
}
return $this->accessProvider->getAccessUrl($this->prefix . DIRECTORY_SEPARATOR);
} | php | public function getPublicAccessUrl()
{
if (is_null($this->accessProvider)) {
common_Logger::e('accessss');
throw new common_Exception('Tried obtaining access to private directory with ID ' . $this->getId());
}
return $this->accessProvider->getAccessUrl($this->prefix . DIRECTORY_SEPARATOR);
} | [
"public",
"function",
"getPublicAccessUrl",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"accessProvider",
")",
")",
"{",
"common_Logger",
"::",
"e",
"(",
"'accessss'",
")",
";",
"throw",
"new",
"common_Exception",
"(",
"'Tried obtaining access... | Returns a URL that allows you to access the files in a directory
preserving the relative paths
@return string
@throws common_Exception | [
"Returns",
"a",
"URL",
"that",
"allows",
"you",
"to",
"access",
"the",
"files",
"in",
"a",
"directory",
"preserving",
"the",
"relative",
"paths"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L86-L93 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.getPath | public function getPath()
{
$adapter = $this->getFileSystem()->getAdapter();
if (!$adapter instanceof Local) {
throw new common_exception_InconsistentData(__CLASS__.' can only handle local files');
}
return $adapter->getPathPrefix() . $this->getPrefix();
} | php | public function getPath()
{
$adapter = $this->getFileSystem()->getAdapter();
if (!$adapter instanceof Local) {
throw new common_exception_InconsistentData(__CLASS__.' can only handle local files');
}
return $adapter->getPathPrefix() . $this->getPrefix();
} | [
"public",
"function",
"getPath",
"(",
")",
"{",
"$",
"adapter",
"=",
"$",
"this",
"->",
"getFileSystem",
"(",
")",
"->",
"getAdapter",
"(",
")",
";",
"if",
"(",
"!",
"$",
"adapter",
"instanceof",
"Local",
")",
"{",
"throw",
"new",
"common_exception_Incon... | Returned the absolute path to this directory
Please use read and write to access files
@deprecated
@return mixed
@throws common_exception_InconsistentData | [
"Returned",
"the",
"absolute",
"path",
"to",
"this",
"directory",
"Please",
"use",
"read",
"and",
"write",
"to",
"access",
"files"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L112-L119 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.write | public function write($path, $string, $mimeType = null)
{
return $this->getFile($path)->write($string, $mimeType);
} | php | public function write($path, $string, $mimeType = null)
{
return $this->getFile($path)->write($string, $mimeType);
} | [
"public",
"function",
"write",
"(",
"$",
"path",
",",
"$",
"string",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getFile",
"(",
"$",
"path",
")",
"->",
"write",
"(",
"$",
"string",
",",
"$",
"mimeType",
")",
";",
"}... | @deprecated use File->write instead
@param $path
@param $string
@param null $mimeType
@return bool
@throws FileNotFoundException
@throws common_Exception | [
"@deprecated",
"use",
"File",
"-",
">",
"write",
"instead"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L131-L134 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.writeStream | public function writeStream($path, $resource, $mimeType = null)
{
return $this->getFile($path)->write($resource, $mimeType);
} | php | public function writeStream($path, $resource, $mimeType = null)
{
return $this->getFile($path)->write($resource, $mimeType);
} | [
"public",
"function",
"writeStream",
"(",
"$",
"path",
",",
"$",
"resource",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getFile",
"(",
"$",
"path",
")",
"->",
"write",
"(",
"$",
"resource",
",",
"$",
"mimeType",
")",
... | @deprecated use File->write instead
@param $path
@param $resource
@param null $mimeType
@return bool
@throws FileNotFoundException
@throws common_Exception | [
"@deprecated",
"use",
"File",
"-",
">",
"write",
"instead"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L146-L149 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.writePsrStream | public function writePsrStream($path, $stream, $mimeType = null)
{
return $this->getFile($path)->write($stream, $mimeType);
} | php | public function writePsrStream($path, $stream, $mimeType = null)
{
return $this->getFile($path)->write($stream, $mimeType);
} | [
"public",
"function",
"writePsrStream",
"(",
"$",
"path",
",",
"$",
"stream",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getFile",
"(",
"$",
"path",
")",
"->",
"write",
"(",
"$",
"stream",
",",
"$",
"mimeType",
")",
... | @deprecated use File->write instead
@param $path
@param $stream
@param null $mimeType
@return bool
@throws FileNotFoundException
@throws common_Exception | [
"@deprecated",
"use",
"File",
"-",
">",
"write",
"instead"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L161-L164 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.update | public function update($path, $content, $mimeType = null)
{
return $this->getFile($path)->update($content, $mimeType);
} | php | public function update($path, $content, $mimeType = null)
{
return $this->getFile($path)->update($content, $mimeType);
} | [
"public",
"function",
"update",
"(",
"$",
"path",
",",
"$",
"content",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getFile",
"(",
"$",
"path",
")",
"->",
"update",
"(",
"$",
"content",
",",
"$",
"mimeType",
")",
";",
... | @deprecated use File->update instead
@param $path
@param $content
@param null $mimeType
@return bool
@throws common_Exception | [
"@deprecated",
"use",
"File",
"-",
">",
"update",
"instead"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L208-L211 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.updateStream | public function updateStream($path, $resource, $mimeType = null)
{
return $this->getFile($path)->update($resource, $mimeType);
} | php | public function updateStream($path, $resource, $mimeType = null)
{
return $this->getFile($path)->update($resource, $mimeType);
} | [
"public",
"function",
"updateStream",
"(",
"$",
"path",
",",
"$",
"resource",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getFile",
"(",
"$",
"path",
")",
"->",
"update",
"(",
"$",
"resource",
",",
"$",
"mimeType",
")",... | @deprecated use File->update instead
@param $path
@param $resource
@param null $mimeType
@return bool
@throws common_Exception | [
"@deprecated",
"use",
"File",
"-",
">",
"update",
"instead"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L222-L225 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.updatePsrStream | public function updatePsrStream($path, StreamInterface $stream, $mimeType = null)
{
return $this->getFile($path)->update($stream, $mimeType);
} | php | public function updatePsrStream($path, StreamInterface $stream, $mimeType = null)
{
return $this->getFile($path)->update($stream, $mimeType);
} | [
"public",
"function",
"updatePsrStream",
"(",
"$",
"path",
",",
"StreamInterface",
"$",
"stream",
",",
"$",
"mimeType",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"getFile",
"(",
"$",
"path",
")",
"->",
"update",
"(",
"$",
"stream",
",",
"$",
... | @deprecated use File->update instead
@param $path
@param StreamInterface $stream
@param null $mimeType
@return bool
@throws common_Exception | [
"@deprecated",
"use",
"File",
"-",
">",
"update",
"instead"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L236-L239 |
oat-sa/tao-core | models/classes/service/class.StorageDirectory.php | tao_models_classes_service_StorageDirectory.getIterator | public function getIterator()
{
$files = array();
$iterator = $this->getFlyIterator(Directory::ITERATOR_FILE | Directory::ITERATOR_RECURSIVE);
foreach ($iterator as $file) {
$files[] = $this->getRelPath($file);
}
return new ArrayIterator($files);
} | php | public function getIterator()
{
$files = array();
$iterator = $this->getFlyIterator(Directory::ITERATOR_FILE | Directory::ITERATOR_RECURSIVE);
foreach ($iterator as $file) {
$files[] = $this->getRelPath($file);
}
return new ArrayIterator($files);
} | [
"public",
"function",
"getIterator",
"(",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"iterator",
"=",
"$",
"this",
"->",
"getFlyIterator",
"(",
"Directory",
"::",
"ITERATOR_FILE",
"|",
"Directory",
"::",
"ITERATOR_RECURSIVE",
")",
";",
"fore... | @deprecated use $this->getFlyIterator instead
@return ArrayIterator | [
"@deprecated",
"use",
"$this",
"-",
">",
"getFlyIterator",
"instead"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/service/class.StorageDirectory.php#L268-L276 |
oat-sa/tao-core | actions/class.ServiceModule.php | tao_actions_ServiceModule.getState | protected function getState()
{
$serviceService = $this->getServiceLocator()->get(StateStorage::SERVICE_ID);
$userUri = $this->getSession()->getUserUri();
return is_null($userUri) ? null : $serviceService->get($userUri, $this->getServiceCallId());
} | php | protected function getState()
{
$serviceService = $this->getServiceLocator()->get(StateStorage::SERVICE_ID);
$userUri = $this->getSession()->getUserUri();
return is_null($userUri) ? null : $serviceService->get($userUri, $this->getServiceCallId());
} | [
"protected",
"function",
"getState",
"(",
")",
"{",
"$",
"serviceService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"StateStorage",
"::",
"SERVICE_ID",
")",
";",
"$",
"userUri",
"=",
"$",
"this",
"->",
"getSession",
"(",
"... | Returns the state stored or NULL ifs none was found
@return string | [
"Returns",
"the",
"state",
"stored",
"or",
"NULL",
"ifs",
"none",
"was",
"found"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.ServiceModule.php#L53-L58 |
oat-sa/tao-core | actions/class.ServiceModule.php | tao_actions_ServiceModule.setState | protected function setState($state)
{
$serviceService = $this->getServiceLocator()->get(StateStorage::SERVICE_ID);
$userUri = $this->getSession()->getUserUri();
return is_null($userUri) ? false : $serviceService->set($userUri, $this->getServiceCallId(), $state);
} | php | protected function setState($state)
{
$serviceService = $this->getServiceLocator()->get(StateStorage::SERVICE_ID);
$userUri = $this->getSession()->getUserUri();
return is_null($userUri) ? false : $serviceService->set($userUri, $this->getServiceCallId(), $state);
} | [
"protected",
"function",
"setState",
"(",
"$",
"state",
")",
"{",
"$",
"serviceService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"StateStorage",
"::",
"SERVICE_ID",
")",
";",
"$",
"userUri",
"=",
"$",
"this",
"->",
"getSe... | Stores the state of the current service call
@param string $state
@return boolean | [
"Stores",
"the",
"state",
"of",
"the",
"current",
"service",
"call"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.ServiceModule.php#L66-L71 |
oat-sa/tao-core | install/services/class.SyncService.php | tao_install_services_SyncService.execute | public function execute(){
$ext = common_configuration_ComponentFactory::buildPHPExtension('json');
$report = $ext->check();
// We fake JSON encoding for a gracefull response in any case.
$json = $report->getStatus() == common_configuration_Report::VALID;
if (!$json){
$data = '{"type": "SyncReport", "value": { "json": '. (($json) ? 'true' : 'false') . '}}';
}
else{
$localesDir = dirname(__FILE__) . '/../../locales';
$data = json_encode(array('type' => 'SyncReport', 'value' => array(
'json' => true,
'rootURL' => self::getRootUrl(),
'availableDrivers' => self::getAvailableDrivers(),
'availableLanguages' => self::getAvailableLanguages($localesDir),
'availableTimezones' => self::getAvailableTimezones()
)));
}
$this->setResult(new tao_install_services_Data($data));
} | php | public function execute(){
$ext = common_configuration_ComponentFactory::buildPHPExtension('json');
$report = $ext->check();
// We fake JSON encoding for a gracefull response in any case.
$json = $report->getStatus() == common_configuration_Report::VALID;
if (!$json){
$data = '{"type": "SyncReport", "value": { "json": '. (($json) ? 'true' : 'false') . '}}';
}
else{
$localesDir = dirname(__FILE__) . '/../../locales';
$data = json_encode(array('type' => 'SyncReport', 'value' => array(
'json' => true,
'rootURL' => self::getRootUrl(),
'availableDrivers' => self::getAvailableDrivers(),
'availableLanguages' => self::getAvailableLanguages($localesDir),
'availableTimezones' => self::getAvailableTimezones()
)));
}
$this->setResult(new tao_install_services_Data($data));
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"ext",
"=",
"common_configuration_ComponentFactory",
"::",
"buildPHPExtension",
"(",
"'json'",
")",
";",
"$",
"report",
"=",
"$",
"ext",
"->",
"check",
"(",
")",
";",
"// We fake JSON encoding for a gracefull re... | Executes the main logic of the service.
@return tao_install_services_Data The result of the service execution. | [
"Executes",
"the",
"main",
"logic",
"of",
"the",
"service",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/install/services/class.SyncService.php#L50-L71 |
oat-sa/tao-core | install/services/class.SyncService.php | tao_install_services_SyncService.getRootUrl | private static function getRootUrl(){
// Returns TAO ROOT url based on a call to the API.
$isHTTPS = common_http_Request::isHttps();
$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
$currentUrl = ($isHTTPS ? 'https' : 'http' ). '://' . $host . $uri;
$parsed = parse_url($currentUrl);
$port = (empty($parsed['port'])) ? '' : ':' . $parsed['port'];
$rootUrl = $parsed['scheme'] . '://' . $parsed['host'] . $port . $parsed['path'];
return str_replace('/tao/install/api.php', '', $rootUrl);
} | php | private static function getRootUrl(){
// Returns TAO ROOT url based on a call to the API.
$isHTTPS = common_http_Request::isHttps();
$host = $_SERVER['HTTP_HOST'];
$uri = $_SERVER['REQUEST_URI'];
$currentUrl = ($isHTTPS ? 'https' : 'http' ). '://' . $host . $uri;
$parsed = parse_url($currentUrl);
$port = (empty($parsed['port'])) ? '' : ':' . $parsed['port'];
$rootUrl = $parsed['scheme'] . '://' . $parsed['host'] . $port . $parsed['path'];
return str_replace('/tao/install/api.php', '', $rootUrl);
} | [
"private",
"static",
"function",
"getRootUrl",
"(",
")",
"{",
"// Returns TAO ROOT url based on a call to the API.\r",
"$",
"isHTTPS",
"=",
"common_http_Request",
"::",
"isHttps",
"(",
")",
";",
"$",
"host",
"=",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
";",
"$",
... | Computes the root URL of the platform based on the current
request.
@return mixed | [
"Computes",
"the",
"root",
"URL",
"of",
"the",
"platform",
"based",
"on",
"the",
"current",
"request",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/install/services/class.SyncService.php#L79-L89 |
oat-sa/tao-core | install/services/class.SyncService.php | tao_install_services_SyncService.getAvailableLanguages | private static function getAvailableLanguages($localesPath, $sort = true){
$languages = array();
try{
$languages = tao_install_utils_System::getAvailableLocales($localesPath);
if (true == $sort){
asort($languages);
}
}
catch (Exception $e){
// Do nothing and return gracefully.
}
return $languages;
} | php | private static function getAvailableLanguages($localesPath, $sort = true){
$languages = array();
try{
$languages = tao_install_utils_System::getAvailableLocales($localesPath);
if (true == $sort){
asort($languages);
}
}
catch (Exception $e){
// Do nothing and return gracefully.
}
return $languages;
} | [
"private",
"static",
"function",
"getAvailableLanguages",
"(",
"$",
"localesPath",
",",
"$",
"sort",
"=",
"true",
")",
"{",
"$",
"languages",
"=",
"array",
"(",
")",
";",
"try",
"{",
"$",
"languages",
"=",
"tao_install_utils_System",
"::",
"getAvailableLocales... | Get the list of available languages in terms of locales in the /tao meta-extension folder.
@param string $localesPath The path to the /locales directory to scan into.
@param boolean $sort Sort by alphetical order.
@return array an array of languages where keys are language tags and values are language labels in english (EN). | [
"Get",
"the",
"list",
"of",
"available",
"languages",
"in",
"terms",
"of",
"locales",
"in",
"the",
"/",
"tao",
"meta",
"-",
"extension",
"folder",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/install/services/class.SyncService.php#L114-L128 |
oat-sa/tao-core | install/services/class.SyncService.php | tao_install_services_SyncService.getAvailableTimezones | private static function getAvailableTimezones() {
return DateTimeZone::listIdentifiers();
// get full list of timezone identifiers and add UTC value with the display
$timezone_identifiers = DateTimeZone::listIdentifiers();
$timezones = array();
foreach ($timezone_identifiers as $timezone_identifier) {
$now = new DateTime(null, new DateTimeZone( $timezone_identifier ));
str_replace('_', ' ', $timezone_identifier);
$utcValue = $now->getOffset() / 3600;
$utcHours = floor($utcValue);
$utcMinutes = ($utcValue - $utcHours) * 60;
$utcPrint = sprintf('%d:%02d', $utcHours, $utcMinutes);
$utcValue = ($utcHours>0) ? (' +'.$utcPrint) : (($utcHours==0)?'':' '.$utcPrint);
array_push( $timezones, $timezone_identifier." (UTC".$utcValue.")" );
}
return $timezones;
} | php | private static function getAvailableTimezones() {
return DateTimeZone::listIdentifiers();
// get full list of timezone identifiers and add UTC value with the display
$timezone_identifiers = DateTimeZone::listIdentifiers();
$timezones = array();
foreach ($timezone_identifiers as $timezone_identifier) {
$now = new DateTime(null, new DateTimeZone( $timezone_identifier ));
str_replace('_', ' ', $timezone_identifier);
$utcValue = $now->getOffset() / 3600;
$utcHours = floor($utcValue);
$utcMinutes = ($utcValue - $utcHours) * 60;
$utcPrint = sprintf('%d:%02d', $utcHours, $utcMinutes);
$utcValue = ($utcHours>0) ? (' +'.$utcPrint) : (($utcHours==0)?'':' '.$utcPrint);
array_push( $timezones, $timezone_identifier." (UTC".$utcValue.")" );
}
return $timezones;
} | [
"private",
"static",
"function",
"getAvailableTimezones",
"(",
")",
"{",
"return",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
")",
";",
"// get full list of timezone identifiers and add UTC value with the display\r",
"$",
"timezone_identifiers",
"=",
"DateTimeZone",
"::",
... | Get available timezones on the server side. The returned value
corresponds to the value returned by DateTimeZone::listIdentifiers()'s PHP
method.
@return array An array where keys are integers and values are PHP timezone identifiers.
@see http://www.php.net/manual/en/datetimezone.listidentifiers.php PHP's DateTimeZone::listIdentifiers method.
@see http://php.net/manual/en/timezones.php For the list of PHP's timezone identifiers. | [
"Get",
"available",
"timezones",
"on",
"the",
"server",
"side",
".",
"The",
"returned",
"value",
"corresponds",
"to",
"the",
"value",
"returned",
"by",
"DateTimeZone",
"::",
"listIdentifiers",
"()",
"s",
"PHP",
"method",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/install/services/class.SyncService.php#L139-L158 |
oat-sa/tao-core | models/classes/taskQueue/TaskLog.php | TaskLog.getBroker | public function getBroker()
{
if (is_null($this->broker)) {
$this->broker = $this->getOption(self::OPTION_TASK_LOG_BROKER);
$this->broker->setServiceLocator($this->getServiceLocator());
}
return $this->broker;
} | php | public function getBroker()
{
if (is_null($this->broker)) {
$this->broker = $this->getOption(self::OPTION_TASK_LOG_BROKER);
$this->broker->setServiceLocator($this->getServiceLocator());
}
return $this->broker;
} | [
"public",
"function",
"getBroker",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"broker",
")",
")",
"{",
"$",
"this",
"->",
"broker",
"=",
"$",
"this",
"->",
"getOption",
"(",
"self",
"::",
"OPTION_TASK_LOG_BROKER",
")",
";",
"$",
"th... | Gets the task log broker. It will be created if it has not been initialized.
@return TaskLogBrokerInterface | [
"Gets",
"the",
"task",
"log",
"broker",
".",
"It",
"will",
"be",
"created",
"if",
"it",
"has",
"not",
"been",
"initialized",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/taskQueue/TaskLog.php#L77-L85 |
oat-sa/tao-core | models/classes/metadata/reader/KeyReader.php | KeyReader.getValue | public function getValue(array $data)
{
$key = strtolower($this->key);
if ($this->hasValue($data, $key)) {
return $data[$key];
}
throw new MetadataReaderNotFoundException(__CLASS__ . ' cannot found value associated to key "' . $this->key . '".');
} | php | public function getValue(array $data)
{
$key = strtolower($this->key);
if ($this->hasValue($data, $key)) {
return $data[$key];
}
throw new MetadataReaderNotFoundException(__CLASS__ . ' cannot found value associated to key "' . $this->key . '".');
} | [
"public",
"function",
"getValue",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"this",
"->",
"key",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasValue",
"(",
"$",
"data",
",",
"$",
"key",
")",
")",
"{",
"return",
... | Get value of $data using $key
@param array $data A CSV line
@return string
@throws MetadataReaderNotFoundException | [
"Get",
"value",
"of",
"$data",
"using",
"$key"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/metadata/reader/KeyReader.php#L67-L75 |
oat-sa/tao-core | models/classes/ClientLibConfigRegistry.php | ClientLibConfigRegistry.register | public function register($id, $newLibConfig)
{
$registry = self::getRegistry();
$libConfig = array();
if ($registry->isRegistered($id)) {
$libConfig = $registry->get($id);
}
$libConfig = array_replace_recursive($libConfig, $newLibConfig);
$registry->set($id, $libConfig);
} | php | public function register($id, $newLibConfig)
{
$registry = self::getRegistry();
$libConfig = array();
if ($registry->isRegistered($id)) {
$libConfig = $registry->get($id);
}
$libConfig = array_replace_recursive($libConfig, $newLibConfig);
$registry->set($id, $libConfig);
} | [
"public",
"function",
"register",
"(",
"$",
"id",
",",
"$",
"newLibConfig",
")",
"{",
"$",
"registry",
"=",
"self",
"::",
"getRegistry",
"(",
")",
";",
"$",
"libConfig",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"registry",
"->",
"isRegistered",
"... | Register a new path for given alias, trigger a warning if path already register
@author Sam, sam@taotesting.com
@param string $id
@param string $newLibConfig | [
"Register",
"a",
"new",
"path",
"for",
"given",
"alias",
"trigger",
"a",
"warning",
"if",
"path",
"already",
"register"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/ClientLibConfigRegistry.php#L58-L68 |
oat-sa/tao-core | models/classes/search/strategy/GenerisSearch.php | GenerisSearch.query | public function query($queryString, $type, $start = 0, $count = 10, $order = 'id', $dir = 'DESC') {
$rootClass = $this->getClass($type);
$results = $rootClass->searchInstances([
OntologyRdfs::RDFS_LABEL => $queryString
], array(
'recursive' => true,
'like' => true,
'offset' => $start,
'limit' => $count,
));
$ids = array();
foreach ($results as $resource) {
$ids[] = $resource->getUri();
}
return new ResultSet($ids, $this->getTotalCount($queryString, $rootClass));
} | php | public function query($queryString, $type, $start = 0, $count = 10, $order = 'id', $dir = 'DESC') {
$rootClass = $this->getClass($type);
$results = $rootClass->searchInstances([
OntologyRdfs::RDFS_LABEL => $queryString
], array(
'recursive' => true,
'like' => true,
'offset' => $start,
'limit' => $count,
));
$ids = array();
foreach ($results as $resource) {
$ids[] = $resource->getUri();
}
return new ResultSet($ids, $this->getTotalCount($queryString, $rootClass));
} | [
"public",
"function",
"query",
"(",
"$",
"queryString",
",",
"$",
"type",
",",
"$",
"start",
"=",
"0",
",",
"$",
"count",
"=",
"10",
",",
"$",
"order",
"=",
"'id'",
",",
"$",
"dir",
"=",
"'DESC'",
")",
"{",
"$",
"rootClass",
"=",
"$",
"this",
"... | (non-PHPdoc)
@see \oat\tao\model\search\Search::query() | [
"(",
"non",
"-",
"PHPdoc",
")"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/search/strategy/GenerisSearch.php#L44-L60 |
oat-sa/tao-core | models/classes/search/strategy/GenerisSearch.php | GenerisSearch.getTotalCount | private function getTotalCount( $queryString, $rootClass = null )
{
return $rootClass->countInstances(
array(
OntologyRdfs::RDFS_LABEL => $queryString
),
array(
'recursive' => true,
'like' => true,
)
);
} | php | private function getTotalCount( $queryString, $rootClass = null )
{
return $rootClass->countInstances(
array(
OntologyRdfs::RDFS_LABEL => $queryString
),
array(
'recursive' => true,
'like' => true,
)
);
} | [
"private",
"function",
"getTotalCount",
"(",
"$",
"queryString",
",",
"$",
"rootClass",
"=",
"null",
")",
"{",
"return",
"$",
"rootClass",
"->",
"countInstances",
"(",
"array",
"(",
"OntologyRdfs",
"::",
"RDFS_LABEL",
"=>",
"$",
"queryString",
")",
",",
"arr... | Return total count of corresponded instances
@param string $queryString
@param core_kernel_classes_Class $rootClass
@return array | [
"Return",
"total",
"count",
"of",
"corresponded",
"instances"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/search/strategy/GenerisSearch.php#L87-L98 |
oat-sa/tao-core | helpers/translation/class.RDFTranslationFile.php | tao_helpers_translation_RDFTranslationFile.addTranslationUnit | public function addTranslationUnit( tao_helpers_translation_TranslationUnit $translationUnit)
{
// We override the default behaviour because for RDFTranslationFiles, TranslationUnits are
// unique by concatening the following attributes:
// - RDFTranslationUnit::subject
// - RDFTranslationUnit::predicate
// - RDFTranslationUnit::targetLanguage
foreach ($this->getTranslationUnits() as $tu) {
if ($tu->hasSameTranslationUnitSubject($translationUnit) &&
$tu->hasSameTranslationUnitPredicate($translationUnit) &&
$tu->hasSameTranslationUnitTargetLanguage($translationUnit)) {
// This TU already exists. We change its target if the new one
// has one.
if ($translationUnit->getTarget() != $translationUnit->getSource()){
$tu->setTarget($translationUnit->getTarget());
}
return;
}
}
// If we are executing this, we can add the TranslationUnit to this TranslationFile.
$translationUnit->setSourceLanguage($this->getSourceLanguage());
$translationUnit->setTargetLanguage($this->getTargetLanguage());
$tus = $this->getTranslationUnits();
array_push($tus, $translationUnit);
$this->setTranslationUnits($tus);
} | php | public function addTranslationUnit( tao_helpers_translation_TranslationUnit $translationUnit)
{
// We override the default behaviour because for RDFTranslationFiles, TranslationUnits are
// unique by concatening the following attributes:
// - RDFTranslationUnit::subject
// - RDFTranslationUnit::predicate
// - RDFTranslationUnit::targetLanguage
foreach ($this->getTranslationUnits() as $tu) {
if ($tu->hasSameTranslationUnitSubject($translationUnit) &&
$tu->hasSameTranslationUnitPredicate($translationUnit) &&
$tu->hasSameTranslationUnitTargetLanguage($translationUnit)) {
// This TU already exists. We change its target if the new one
// has one.
if ($translationUnit->getTarget() != $translationUnit->getSource()){
$tu->setTarget($translationUnit->getTarget());
}
return;
}
}
// If we are executing this, we can add the TranslationUnit to this TranslationFile.
$translationUnit->setSourceLanguage($this->getSourceLanguage());
$translationUnit->setTargetLanguage($this->getTargetLanguage());
$tus = $this->getTranslationUnits();
array_push($tus, $translationUnit);
$this->setTranslationUnits($tus);
} | [
"public",
"function",
"addTranslationUnit",
"(",
"tao_helpers_translation_TranslationUnit",
"$",
"translationUnit",
")",
"{",
"// We override the default behaviour because for RDFTranslationFiles, TranslationUnits are",
"// unique by concatening the following attributes:",
"// - RDFTranslation... | Short description of method addTranslationUnit
@access public
@author Jerome Bogaerts, <jerome.bogaerts@tudor.lu>
@param TranslationUnit translationUnit
@return mixed | [
"Short",
"description",
"of",
"method",
"addTranslationUnit"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/translation/class.RDFTranslationFile.php#L64-L92 |
oat-sa/tao-core | actions/form/class.Export.php | tao_actions_form_Export.initElements | public function initElements()
{
if (count($this->exportHandlers) > 1) {
//create the element to select the import format
$formatElt = tao_helpers_form_FormFactory::getElement('exportHandler', 'Radiobox');
$formatElt->setDescription(__('Choose export format'));
//mandatory field
$formatElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
$formatElt->setOptions($this->getFormats());
if (isset($_POST['exportHandler'])) {
if (array_key_exists($_POST['exportHandler'], $this->getFormats())) {
$formatElt->setValue($_POST['exportHandler']);
}
}
$this->form->addElement($formatElt);
$this->form->createGroup('formats', '<h3>'.__('Supported export formats').'</h3>', array('exportHandler'));
}
if(isset($this->data['instance'])){
$item = $this->data['instance'];
if($item instanceof core_kernel_classes_Resource){
//add an hidden elt for the instance Uri
$uriElt = tao_helpers_form_FormFactory::getElement('uri', 'Hidden');
$uriElt->setValue($item->getUri());
$this->form->addElement($uriElt);
}
}
if(isset($this->data['class'])){
$class = $this->data['class'];
if($class instanceof core_kernel_classes_Class){
//add an hidden elt for the class uri
$classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
$classUriElt->setValue($class->getUri());
$this->form->addElement($classUriElt);
}
}
$idElt = tao_helpers_form_FormFactory::getElement('id', 'Hidden');
$this->form->addElement($idElt);
foreach ($this->subForm->getElements() as $element) {
$this->form->addElement($element);
}
foreach ($this->subForm->getGroups() as $group) {
$this->form->createGroup($group['title'],$group['title'],$group['elements'],$group['options']);
}
} | php | public function initElements()
{
if (count($this->exportHandlers) > 1) {
//create the element to select the import format
$formatElt = tao_helpers_form_FormFactory::getElement('exportHandler', 'Radiobox');
$formatElt->setDescription(__('Choose export format'));
//mandatory field
$formatElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
$formatElt->setOptions($this->getFormats());
if (isset($_POST['exportHandler'])) {
if (array_key_exists($_POST['exportHandler'], $this->getFormats())) {
$formatElt->setValue($_POST['exportHandler']);
}
}
$this->form->addElement($formatElt);
$this->form->createGroup('formats', '<h3>'.__('Supported export formats').'</h3>', array('exportHandler'));
}
if(isset($this->data['instance'])){
$item = $this->data['instance'];
if($item instanceof core_kernel_classes_Resource){
//add an hidden elt for the instance Uri
$uriElt = tao_helpers_form_FormFactory::getElement('uri', 'Hidden');
$uriElt->setValue($item->getUri());
$this->form->addElement($uriElt);
}
}
if(isset($this->data['class'])){
$class = $this->data['class'];
if($class instanceof core_kernel_classes_Class){
//add an hidden elt for the class uri
$classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
$classUriElt->setValue($class->getUri());
$this->form->addElement($classUriElt);
}
}
$idElt = tao_helpers_form_FormFactory::getElement('id', 'Hidden');
$this->form->addElement($idElt);
foreach ($this->subForm->getElements() as $element) {
$this->form->addElement($element);
}
foreach ($this->subForm->getGroups() as $group) {
$this->form->createGroup($group['title'],$group['title'],$group['elements'],$group['options']);
}
} | [
"public",
"function",
"initElements",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"exportHandlers",
")",
">",
"1",
")",
"{",
"//create the element to select the import format",
"$",
"formatElt",
"=",
"tao_helpers_form_FormFactory",
"::",
"getElement",... | Short description of method initElements
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return mixed | [
"Short",
"description",
"of",
"method",
"initElements"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/form/class.Export.php#L85-L137 |
oat-sa/tao-core | helpers/RestExceptionHandler.php | RestExceptionHandler.sendHeader | public function sendHeader(Exception $exception)
{
switch (get_class($exception)) {
case \common_exception_BadRequest::class:
case \common_exception_MissingParameter::class:
case \common_exception_InvalidArgumentType::class:
case \common_exception_InconsistentData::class:
case \common_exception_ValidationFailed::class:
case \common_exception_RestApi::class:
header("HTTP/1.0 400 Bad Request");
break;
case \common_exception_Unauthorized::class:
header("HTTP/1.0 401 Unauthorized");
break;
case \common_exception_NotFound::class:
header("HTTP/1.0 404 Not Found");
break;
case \common_exception_MethodNotAllowed::class:
header("HTTP/1.0 405 Method Not Allowed");
break;
case \common_exception_NotAcceptable::class:
header("HTTP/1.0 406 Not Acceptable");
break;
case "common_exception_TimeOut":
header("HTTP/1.0 408 Request Timeout");
break;
case "common_exception_Conflict":
header("HTTP/1.0 409 Conflict");
break;
case "common_exception_UnsupportedMediaType":
header("HTTP/1.0 415 Unsupported Media Type");
break;
case \common_exception_NotImplemented::class:
header("HTTP/1.0 501 Not Implemented" );
break;
case \common_exception_PreConditionFailure::class:
header("HTTP/1.0 412 Precondition Failed");
break;
case \common_exception_NoContent::class:
header("HTTP/1.0 204 No Content" );
break;
case "common_exception_teapotAprilFirst":
header("HTTP/1.0 418 I'm a teapot (RFC 2324)");
break;
default:
header("HTTP/1.0 500 Internal Server Error");
}
} | php | public function sendHeader(Exception $exception)
{
switch (get_class($exception)) {
case \common_exception_BadRequest::class:
case \common_exception_MissingParameter::class:
case \common_exception_InvalidArgumentType::class:
case \common_exception_InconsistentData::class:
case \common_exception_ValidationFailed::class:
case \common_exception_RestApi::class:
header("HTTP/1.0 400 Bad Request");
break;
case \common_exception_Unauthorized::class:
header("HTTP/1.0 401 Unauthorized");
break;
case \common_exception_NotFound::class:
header("HTTP/1.0 404 Not Found");
break;
case \common_exception_MethodNotAllowed::class:
header("HTTP/1.0 405 Method Not Allowed");
break;
case \common_exception_NotAcceptable::class:
header("HTTP/1.0 406 Not Acceptable");
break;
case "common_exception_TimeOut":
header("HTTP/1.0 408 Request Timeout");
break;
case "common_exception_Conflict":
header("HTTP/1.0 409 Conflict");
break;
case "common_exception_UnsupportedMediaType":
header("HTTP/1.0 415 Unsupported Media Type");
break;
case \common_exception_NotImplemented::class:
header("HTTP/1.0 501 Not Implemented" );
break;
case \common_exception_PreConditionFailure::class:
header("HTTP/1.0 412 Precondition Failed");
break;
case \common_exception_NoContent::class:
header("HTTP/1.0 204 No Content" );
break;
case "common_exception_teapotAprilFirst":
header("HTTP/1.0 418 I'm a teapot (RFC 2324)");
break;
default:
header("HTTP/1.0 500 Internal Server Error");
}
} | [
"public",
"function",
"sendHeader",
"(",
"Exception",
"$",
"exception",
")",
"{",
"switch",
"(",
"get_class",
"(",
"$",
"exception",
")",
")",
"{",
"case",
"\\",
"common_exception_BadRequest",
"::",
"class",
":",
"case",
"\\",
"common_exception_MissingParameter",
... | Set response header according exception type
@param Exception $exception | [
"Set",
"response",
"header",
"according",
"exception",
"type"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/RestExceptionHandler.php#L32-L93 |
oat-sa/tao-core | actions/form/class.CreateInstance.php | tao_actions_form_CreateInstance.initForm | public function initForm()
{
$name = isset($this->options['name']) ? $this->options['name'] : 'form_'.(count(self::$forms)+1);
unset($this->options['name']);
$this->form = tao_helpers_form_FormFactory::getForm($name, $this->options);
//add create action in toolbar
$action = tao_helpers_form_FormFactory::getElement('save', 'Free');
$value = '<a href="#" class="form-submitter btn-success small"><span class="icon-save"></span> ' .__('Create').'</a>';
$action->setValue($value);
$this->form->setActions(array($action), 'top');
$this->form->setActions(array($action), 'bottom');
} | php | public function initForm()
{
$name = isset($this->options['name']) ? $this->options['name'] : 'form_'.(count(self::$forms)+1);
unset($this->options['name']);
$this->form = tao_helpers_form_FormFactory::getForm($name, $this->options);
//add create action in toolbar
$action = tao_helpers_form_FormFactory::getElement('save', 'Free');
$value = '<a href="#" class="form-submitter btn-success small"><span class="icon-save"></span> ' .__('Create').'</a>';
$action->setValue($value);
$this->form->setActions(array($action), 'top');
$this->form->setActions(array($action), 'bottom');
} | [
"public",
"function",
"initForm",
"(",
")",
"{",
"$",
"name",
"=",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'name'",
"]",
")",
"?",
"$",
"this",
"->",
"options",
"[",
"'name'",
"]",
":",
"'form_'",
".",
"(",
"count",
"(",
"self",
"::",
"... | Short description of method initForm
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return mixed | [
"Short",
"description",
"of",
"method",
"initForm"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/form/class.CreateInstance.php#L79-L96 |
oat-sa/tao-core | actions/form/class.CreateInstance.php | tao_actions_form_CreateInstance.initElements | public function initElements()
{
$guiOrderProperty = new core_kernel_classes_Property(TaoOntology::PROPERTY_GUI_ORDER);
//get the list of properties to set in the form
$defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties();
$editedProperties = $defaultProperties;
$excludedProperties = (isset($this->options['excludedProperties']) && is_array($this->options['excludedProperties']))?$this->options['excludedProperties']:array();
$additionalProperties = (isset($this->options['additionalProperties']) && is_array($this->options['additionalProperties']))?$this->options['additionalProperties']:array();
$finalElements = array();
$classProperties = array();
foreach ($this->classes as $class) {
$classProperties = array_merge(tao_helpers_form_GenerisFormFactory::getClassProperties($class));
}
if(!empty($additionalProperties)){
$classProperties = array_merge($classProperties, $additionalProperties);
}
foreach($classProperties as $property){
if(!isset($editedProperties[$property->getUri()]) && !in_array($property->getUri(), $excludedProperties)){
$editedProperties[$property->getUri()] = $property;
}
}
foreach($editedProperties as $property){
$property->feed();
$widget = $property->getWidget();
if($widget == null || $widget instanceof core_kernel_classes_Literal) {
continue;
}
else if ($widget instanceof core_kernel_classes_Resource && $widget->getUri() == WidgetRdf::PROPERTY_WIDGET_TREEVIEW){
continue;
}
//map properties widgets to form elments
$element = tao_helpers_form_GenerisFormFactory::elementMap($property);
if(!is_null($element)){
//set label validator
if($property->getUri() == OntologyRdfs::RDFS_LABEL){
$element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
}
// don't show empty labels
if($element instanceof tao_helpers_form_elements_Label && strlen($element->getRawValue()) == 0) {
continue;
}
//set file element validator:
if($element instanceof tao_helpers_form_elements_AsyncFile){
}
if ($property->getUri() == OntologyRdfs::RDFS_LABEL){
// Label will not be a TAO Property. However, it should
// be always first.
array_splice($finalElements, 0, 0, array(array($element, 1)));
}
else if (count($guiOrderPropertyValues = $property->getPropertyValues($guiOrderProperty))){
// get position of this property if it has one.
$position = intval($guiOrderPropertyValues[0]);
// insert the element at the right place.
$i = 0;
while ($i < count($finalElements) && ($position >= $finalElements[$i][1] && $finalElements[$i][1] !== null)){
$i++;
}
array_splice($finalElements, $i, 0, array(array($element, $position)));
}
else{
// Unordered properties will go at the end of the form.
$finalElements[] = array($element, null);
}
}
}
// Add elements related to class properties to the form.
foreach ($finalElements as $element){
$this->form->addElement($element[0]);
}
// @todo currently tao cannot handle multiple classes
/*
$classUriElt = tao_helpers_form_FormFactory::getElement('classes', 'Hidden');
$uris = array();
foreach ($this->classes as $class) {
$uris[] = $class->getUri();
}
$classUriElt->setValue($uris);
*/
//add an hidden elt for the class uri
$classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
$classUriElt->setValue(tao_helpers_Uri::encode($class->getUri()));
$this->form->addElement($classUriElt);
$this->form->addElement($classUriElt);
$this->addSignature();
} | php | public function initElements()
{
$guiOrderProperty = new core_kernel_classes_Property(TaoOntology::PROPERTY_GUI_ORDER);
//get the list of properties to set in the form
$defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties();
$editedProperties = $defaultProperties;
$excludedProperties = (isset($this->options['excludedProperties']) && is_array($this->options['excludedProperties']))?$this->options['excludedProperties']:array();
$additionalProperties = (isset($this->options['additionalProperties']) && is_array($this->options['additionalProperties']))?$this->options['additionalProperties']:array();
$finalElements = array();
$classProperties = array();
foreach ($this->classes as $class) {
$classProperties = array_merge(tao_helpers_form_GenerisFormFactory::getClassProperties($class));
}
if(!empty($additionalProperties)){
$classProperties = array_merge($classProperties, $additionalProperties);
}
foreach($classProperties as $property){
if(!isset($editedProperties[$property->getUri()]) && !in_array($property->getUri(), $excludedProperties)){
$editedProperties[$property->getUri()] = $property;
}
}
foreach($editedProperties as $property){
$property->feed();
$widget = $property->getWidget();
if($widget == null || $widget instanceof core_kernel_classes_Literal) {
continue;
}
else if ($widget instanceof core_kernel_classes_Resource && $widget->getUri() == WidgetRdf::PROPERTY_WIDGET_TREEVIEW){
continue;
}
//map properties widgets to form elments
$element = tao_helpers_form_GenerisFormFactory::elementMap($property);
if(!is_null($element)){
//set label validator
if($property->getUri() == OntologyRdfs::RDFS_LABEL){
$element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
}
// don't show empty labels
if($element instanceof tao_helpers_form_elements_Label && strlen($element->getRawValue()) == 0) {
continue;
}
//set file element validator:
if($element instanceof tao_helpers_form_elements_AsyncFile){
}
if ($property->getUri() == OntologyRdfs::RDFS_LABEL){
// Label will not be a TAO Property. However, it should
// be always first.
array_splice($finalElements, 0, 0, array(array($element, 1)));
}
else if (count($guiOrderPropertyValues = $property->getPropertyValues($guiOrderProperty))){
// get position of this property if it has one.
$position = intval($guiOrderPropertyValues[0]);
// insert the element at the right place.
$i = 0;
while ($i < count($finalElements) && ($position >= $finalElements[$i][1] && $finalElements[$i][1] !== null)){
$i++;
}
array_splice($finalElements, $i, 0, array(array($element, $position)));
}
else{
// Unordered properties will go at the end of the form.
$finalElements[] = array($element, null);
}
}
}
// Add elements related to class properties to the form.
foreach ($finalElements as $element){
$this->form->addElement($element[0]);
}
// @todo currently tao cannot handle multiple classes
/*
$classUriElt = tao_helpers_form_FormFactory::getElement('classes', 'Hidden');
$uris = array();
foreach ($this->classes as $class) {
$uris[] = $class->getUri();
}
$classUriElt->setValue($uris);
*/
//add an hidden elt for the class uri
$classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
$classUriElt->setValue(tao_helpers_Uri::encode($class->getUri()));
$this->form->addElement($classUriElt);
$this->form->addElement($classUriElt);
$this->addSignature();
} | [
"public",
"function",
"initElements",
"(",
")",
"{",
"$",
"guiOrderProperty",
"=",
"new",
"core_kernel_classes_Property",
"(",
"TaoOntology",
"::",
"PROPERTY_GUI_ORDER",
")",
";",
"//get the list of properties to set in the form",
"$",
"defaultProperties",
"=",
"tao_helpers... | Short description of method initElements
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return mixed | [
"Short",
"description",
"of",
"method",
"initElements"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/form/class.CreateInstance.php#L105-L211 |
oat-sa/tao-core | models/classes/mvc/error/ExceptionInterpreterService.php | ExceptionInterpreterService.getClassesHierarchy | protected function getClassesHierarchy(\Exception $e)
{
$exceptionClass = get_class($e);
$exceptionClassesHierarchy = array_values(class_parents($exceptionClass));
array_unshift($exceptionClassesHierarchy, $exceptionClass);
$exceptionClassesHierarchy = array_flip($exceptionClassesHierarchy);
return $exceptionClassesHierarchy;
} | php | protected function getClassesHierarchy(\Exception $e)
{
$exceptionClass = get_class($e);
$exceptionClassesHierarchy = array_values(class_parents($exceptionClass));
array_unshift($exceptionClassesHierarchy, $exceptionClass);
$exceptionClassesHierarchy = array_flip($exceptionClassesHierarchy);
return $exceptionClassesHierarchy;
} | [
"protected",
"function",
"getClassesHierarchy",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionClass",
"=",
"get_class",
"(",
"$",
"e",
")",
";",
"$",
"exceptionClassesHierarchy",
"=",
"array_values",
"(",
"class_parents",
"(",
"$",
"exceptionClass",... | Function calculates exception classes hierarchy
Example:
Given hierarchy:
class B extends A {}
class A extends Exception {}
//B => A => Exception
$this->getClassesHierarchy(new B)
Result:
[
'B' => 0,
'A' => 1,
'Exception' => 2,
]
@param \Exception $e
@return array where key is class name and value is index in the hierarchy | [
"Function",
"calculates",
"exception",
"classes",
"hierarchy"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/mvc/error/ExceptionInterpreterService.php#L89-L96 |
oat-sa/tao-core | actions/class.RestUser.php | tao_actions_RestUser.getResourceParameter | protected function getResourceParameter()
{
$resource = parent::getResourceParameter();
if ($resource->isInstanceOf($this->getClass(GenerisRdf::CLASS_GENERIS_USER))) {
return $resource;
}
throw new InvalidArgumentException('Only user resource are allowed.');
} | php | protected function getResourceParameter()
{
$resource = parent::getResourceParameter();
if ($resource->isInstanceOf($this->getClass(GenerisRdf::CLASS_GENERIS_USER))) {
return $resource;
}
throw new InvalidArgumentException('Only user resource are allowed.');
} | [
"protected",
"function",
"getResourceParameter",
"(",
")",
"{",
"$",
"resource",
"=",
"parent",
"::",
"getResourceParameter",
"(",
")",
";",
"if",
"(",
"$",
"resource",
"->",
"isInstanceOf",
"(",
"$",
"this",
"->",
"getClass",
"(",
"GenerisRdf",
"::",
"CLASS... | Return the resource parameter
@return core_kernel_classes_Resource
@InvalidArgumentException If resource does not belong to GenerisRdf::CLASS_GENERIS_USER | [
"Return",
"the",
"resource",
"parameter"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RestUser.php#L64-L72 |
oat-sa/tao-core | actions/class.RestUser.php | tao_actions_RestUser.getClassParameter | protected function getClassParameter()
{
$class = parent::getClassParameter();
$rootUserClass = $this->getClass(GenerisRdf::CLASS_GENERIS_USER);
if ($class->getUri() == $rootUserClass->getUri()) {
return $class;
}
/** @var core_kernel_classes_Class $instance */
foreach ($rootUserClass->getSubClasses(true) as $instance) {
if ($instance->getUri() == $class->getUri()) {
return $class;
}
}
throw new InvalidArgumentException('Only user classes are allowed as classUri.');
} | php | protected function getClassParameter()
{
$class = parent::getClassParameter();
$rootUserClass = $this->getClass(GenerisRdf::CLASS_GENERIS_USER);
if ($class->getUri() == $rootUserClass->getUri()) {
return $class;
}
/** @var core_kernel_classes_Class $instance */
foreach ($rootUserClass->getSubClasses(true) as $instance) {
if ($instance->getUri() == $class->getUri()) {
return $class;
}
}
throw new InvalidArgumentException('Only user classes are allowed as classUri.');
} | [
"protected",
"function",
"getClassParameter",
"(",
")",
"{",
"$",
"class",
"=",
"parent",
"::",
"getClassParameter",
"(",
")",
";",
"$",
"rootUserClass",
"=",
"$",
"this",
"->",
"getClass",
"(",
"GenerisRdf",
"::",
"CLASS_GENERIS_USER",
")",
";",
"if",
"(",
... | Return the class parameter
@return core_kernel_classes_Resource
@InvalidArgumentException If class is not an instance GenerisRdf::CLASS_GENERIS_USER | [
"Return",
"the",
"class",
"parameter"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.RestUser.php#L80-L97 |
oat-sa/tao-core | models/classes/taskQueue/Task/AbstractTask.php | AbstractTask.getMetadata | public function getMetadata($key, $default = null)
{
if (!is_string($key)) {
throw new \InvalidArgumentException('Non-string argument provided as a metadata key');
}
if (array_key_exists($key, $this->metadata)) {
return $this->metadata[$key];
}
return $default;
} | php | public function getMetadata($key, $default = null)
{
if (!is_string($key)) {
throw new \InvalidArgumentException('Non-string argument provided as a metadata key');
}
if (array_key_exists($key, $this->metadata)) {
return $this->metadata[$key];
}
return $default;
} | [
"public",
"function",
"getMetadata",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Non-string argument provided as a metadata k... | Retrieve a single metadata as specified by key
@param string $key
@param null|mixed $default
@throws \InvalidArgumentException
@return mixed | [
"Retrieve",
"a",
"single",
"metadata",
"as",
"specified",
"by",
"key"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/taskQueue/Task/AbstractTask.php#L150-L161 |
oat-sa/tao-core | models/classes/taskQueue/Task/AbstractTask.php | AbstractTask.setParameter | public function setParameter($spec, $value = null)
{
if (is_string($spec)) {
$this->parameters[$spec] = $value;
return $this;
}
if (!is_array($spec) && !$spec instanceof \Traversable) {
throw new \InvalidArgumentException(sprintf(
'Expected a string, array, or Traversable argument in first position; received "%s"',
(is_object($spec) ? get_class($spec) : gettype($spec))
));
}
foreach ($spec as $key => $value) {
$this->parameters[$key] = $value;
}
return $this;
} | php | public function setParameter($spec, $value = null)
{
if (is_string($spec)) {
$this->parameters[$spec] = $value;
return $this;
}
if (!is_array($spec) && !$spec instanceof \Traversable) {
throw new \InvalidArgumentException(sprintf(
'Expected a string, array, or Traversable argument in first position; received "%s"',
(is_object($spec) ? get_class($spec) : gettype($spec))
));
}
foreach ($spec as $key => $value) {
$this->parameters[$key] = $value;
}
return $this;
} | [
"public",
"function",
"setParameter",
"(",
"$",
"spec",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"spec",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"[",
"$",
"spec",
"]",
"=",
"$",
"value",
";",
"return",
"... | Set task parameter
@param string|array|\Traversable $spec
@param mixed $value
@throws \InvalidArgumentException
@return TaskInterface | [
"Set",
"task",
"parameter"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/taskQueue/Task/AbstractTask.php#L171-L190 |
oat-sa/tao-core | models/classes/taskQueue/Task/AbstractTask.php | AbstractTask.getParameter | public function getParameter($key, $default = null)
{
if (!is_string($key)) {
throw new \InvalidArgumentException('Non-string argument provided as a parameter key');
}
if (array_key_exists($key, $this->parameters)) {
return $this->parameters[$key];
}
return $default;
} | php | public function getParameter($key, $default = null)
{
if (!is_string($key)) {
throw new \InvalidArgumentException('Non-string argument provided as a parameter key');
}
if (array_key_exists($key, $this->parameters)) {
return $this->parameters[$key];
}
return $default;
} | [
"public",
"function",
"getParameter",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Non-string argument provided as a parameter... | Retrieve a single parameter as specified by key
@param string $key
@param null|mixed $default
@throws \InvalidArgumentException
@return mixed | [
"Retrieve",
"a",
"single",
"parameter",
"as",
"specified",
"by",
"key"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/taskQueue/Task/AbstractTask.php#L200-L211 |
oat-sa/tao-core | models/classes/table/class.PropertyDP.php | tao_models_classes_table_PropertyDP.getValue | public function getValue( core_kernel_classes_Resource $resource, tao_models_classes_table_Column $column)
{
$returnValue = (string) '';
$result = $resource->getOnePropertyValue($column->getProperty());
$returnValue = $result instanceof core_kernel_classes_Resource ? $result->getLabel() : (string)$result;
return (string) $returnValue;
} | php | public function getValue( core_kernel_classes_Resource $resource, tao_models_classes_table_Column $column)
{
$returnValue = (string) '';
$result = $resource->getOnePropertyValue($column->getProperty());
$returnValue = $result instanceof core_kernel_classes_Resource ? $result->getLabel() : (string)$result;
return (string) $returnValue;
} | [
"public",
"function",
"getValue",
"(",
"core_kernel_classes_Resource",
"$",
"resource",
",",
"tao_models_classes_table_Column",
"$",
"column",
")",
"{",
"$",
"returnValue",
"=",
"(",
"string",
")",
"''",
";",
"$",
"result",
"=",
"$",
"resource",
"->",
"getOnePro... | Short description of method getValue
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Resource resource
@param Column column
@return string | [
"Short",
"description",
"of",
"method",
"getValue"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/table/class.PropertyDP.php#L81-L91 |
oat-sa/tao-core | models/classes/table/class.PropertyDP.php | tao_models_classes_table_PropertyDP.singleton | public static function singleton()
{
$returnValue = null;
if (is_null(self::$singleton)) {
self::$singleton = new self();
}
$returnValue = self::$singleton;
return $returnValue;
} | php | public static function singleton()
{
$returnValue = null;
if (is_null(self::$singleton)) {
self::$singleton = new self();
}
$returnValue = self::$singleton;
return $returnValue;
} | [
"public",
"static",
"function",
"singleton",
"(",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"singleton",
")",
")",
"{",
"self",
"::",
"$",
"singleton",
"=",
"new",
"self",
"(",
")",
";",
"}",
"$",... | Short description of method singleton
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return tao_models_classes_table_PropertyDP | [
"Short",
"description",
"of",
"method",
"singleton"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/table/class.PropertyDP.php#L100-L112 |
oat-sa/tao-core | models/classes/import/service/AbstractImportService.php | AbstractImportService.getCsvControls | protected function getCsvControls(array $options)
{
$csvControls = $this->csvControls;
if (isset($options['delimiter'])) {
$csvControls['delimiter'] = $options['delimiter'];
}
if (isset($options['enclosure'])) {
$csvControls['enclosure'] = $options['enclosure'];
}
if (isset($options['escape'])) {
$csvControls['escape'] = $options['escape'];
}
return $csvControls;
} | php | protected function getCsvControls(array $options)
{
$csvControls = $this->csvControls;
if (isset($options['delimiter'])) {
$csvControls['delimiter'] = $options['delimiter'];
}
if (isset($options['enclosure'])) {
$csvControls['enclosure'] = $options['enclosure'];
}
if (isset($options['escape'])) {
$csvControls['escape'] = $options['escape'];
}
return $csvControls;
} | [
"protected",
"function",
"getCsvControls",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"csvControls",
"=",
"$",
"this",
"->",
"csvControls",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'delimiter'",
"]",
")",
")",
"{",
"$",
"csvControls",
"[",
... | Merge the given $options csv controls to default
@param array $options
@return array | [
"Merge",
"the",
"given",
"$options",
"csv",
"controls",
"to",
"default"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/import/service/AbstractImportService.php#L157-L170 |
oat-sa/tao-core | helpers/class.Date.php | tao_helpers_Date.getDateFormatter | static public function getDateFormatter()
{
if (is_null(self::$service)) {
$ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao');
$service = $ext->getConfig(self::CONFIG_KEY);
self::$service = $service instanceof DateFormatterInterface
? $service
: new EuropeanFormatter();
}
return self::$service;
} | php | static public function getDateFormatter()
{
if (is_null(self::$service)) {
$ext = common_ext_ExtensionsManager::singleton()->getExtensionById('tao');
$service = $ext->getConfig(self::CONFIG_KEY);
self::$service = $service instanceof DateFormatterInterface
? $service
: new EuropeanFormatter();
}
return self::$service;
} | [
"static",
"public",
"function",
"getDateFormatter",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"service",
")",
")",
"{",
"$",
"ext",
"=",
"common_ext_ExtensionsManager",
"::",
"singleton",
"(",
")",
"->",
"getExtensionById",
"(",
"'tao'",
... | Returns configured date formatter.
@return DateFormatterInterface | [
"Returns",
"configured",
"date",
"formatter",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Date.php#L59-L70 |
oat-sa/tao-core | helpers/class.Date.php | tao_helpers_Date.displayeDate | static public function displayeDate($timestamp, $format = self::FORMAT_LONG, DateTimeZone $timeZone = null)
{
if (is_object($timestamp) && $timestamp instanceof core_kernel_classes_Literal) {
$ts = $timestamp->__toString();
} elseif (is_object($timestamp) && $timestamp instanceof DateTimeInterface) {
$ts = self::getTimeStampWithMicroseconds($timestamp);
} elseif (is_numeric($timestamp)) {
$ts = $timestamp;
} elseif (is_string($timestamp) && preg_match('/.\+0000$/', $timestamp)) {
$ts = self::getTimeStampWithMicroseconds(new DateTime($timestamp, new DateTimeZone('UTC')));
} elseif (is_string($timestamp) && preg_match('/0\.[\d]+\s[\d]+/', $timestamp)) {
$ts = self::getTimeStamp($timestamp, true);
} else {
throw new common_Exception('Unexpected timestamp');
}
return self::getDateFormatter()->format($ts, $format, $timeZone);
} | php | static public function displayeDate($timestamp, $format = self::FORMAT_LONG, DateTimeZone $timeZone = null)
{
if (is_object($timestamp) && $timestamp instanceof core_kernel_classes_Literal) {
$ts = $timestamp->__toString();
} elseif (is_object($timestamp) && $timestamp instanceof DateTimeInterface) {
$ts = self::getTimeStampWithMicroseconds($timestamp);
} elseif (is_numeric($timestamp)) {
$ts = $timestamp;
} elseif (is_string($timestamp) && preg_match('/.\+0000$/', $timestamp)) {
$ts = self::getTimeStampWithMicroseconds(new DateTime($timestamp, new DateTimeZone('UTC')));
} elseif (is_string($timestamp) && preg_match('/0\.[\d]+\s[\d]+/', $timestamp)) {
$ts = self::getTimeStamp($timestamp, true);
} else {
throw new common_Exception('Unexpected timestamp');
}
return self::getDateFormatter()->format($ts, $format, $timeZone);
} | [
"static",
"public",
"function",
"displayeDate",
"(",
"$",
"timestamp",
",",
"$",
"format",
"=",
"self",
"::",
"FORMAT_LONG",
",",
"DateTimeZone",
"$",
"timeZone",
"=",
"null",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"timestamp",
")",
"&&",
"$",
"time... | Displays a date/time
Should in theory be dependant on the users locale and timezone
@param mixed $timestamp
@param int $format The date format. See tao_helpers_Date's constants.
@param DateTimeZone $timeZone user timezone
@return string The formatted date.
@throws common_Exception when timestamp is not recognized | [
"Displays",
"a",
"date",
"/",
"time",
"Should",
"in",
"theory",
"be",
"dependant",
"on",
"the",
"users",
"locale",
"and",
"timezone"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Date.php#L81-L98 |
oat-sa/tao-core | helpers/class.Date.php | tao_helpers_Date.getTimeKeys | public static function getTimeKeys(\DateInterval $interval, \DateTimeInterface $date = null, $amount = null)
{
$timeKeys = [];
if ($date === null) {
$date = new \DateTime('now', new \DateTimeZone('UTC'));
}
if ($interval->format('%i') > 0) {
$date->setTime($date->format('H'), $date->format('i')+1, 0);
$amount = $amount === null ? 60 : $amount;
}
if ($interval->format('%h') > 0) {
$date->setTime($date->format('H')+1, 0, 0);
$amount = $amount === null ? 24 : $amount;
}
if ($interval->format('%d') > 0) {
$date->setTime(0, 0, 0);
$date->setDate($date->format('Y'), $date->format('m'), $date->format('d')+1);
$amount = $amount === null ? cal_days_in_month(CAL_GREGORIAN, $date->format('m'), $date->format('Y')) : $amount;
}
if ($interval->format('%m') > 0) {
$date->setTime(0, 0, 0);
$date->setDate($date->format('Y'), $date->format('m')+1, 1);
$amount = $amount === null ? 12 : $amount;
}
while ($amount > 0) {
$timeKeys[] = new \DateTime($date->format(\DateTime::ISO8601), new \DateTimeZone('UTC'));
$date->sub($interval);
$amount--;
}
return $timeKeys;
} | php | public static function getTimeKeys(\DateInterval $interval, \DateTimeInterface $date = null, $amount = null)
{
$timeKeys = [];
if ($date === null) {
$date = new \DateTime('now', new \DateTimeZone('UTC'));
}
if ($interval->format('%i') > 0) {
$date->setTime($date->format('H'), $date->format('i')+1, 0);
$amount = $amount === null ? 60 : $amount;
}
if ($interval->format('%h') > 0) {
$date->setTime($date->format('H')+1, 0, 0);
$amount = $amount === null ? 24 : $amount;
}
if ($interval->format('%d') > 0) {
$date->setTime(0, 0, 0);
$date->setDate($date->format('Y'), $date->format('m'), $date->format('d')+1);
$amount = $amount === null ? cal_days_in_month(CAL_GREGORIAN, $date->format('m'), $date->format('Y')) : $amount;
}
if ($interval->format('%m') > 0) {
$date->setTime(0, 0, 0);
$date->setDate($date->format('Y'), $date->format('m')+1, 1);
$amount = $amount === null ? 12 : $amount;
}
while ($amount > 0) {
$timeKeys[] = new \DateTime($date->format(\DateTime::ISO8601), new \DateTimeZone('UTC'));
$date->sub($interval);
$amount--;
}
return $timeKeys;
} | [
"public",
"static",
"function",
"getTimeKeys",
"(",
"\\",
"DateInterval",
"$",
"interval",
",",
"\\",
"DateTimeInterface",
"$",
"date",
"=",
"null",
",",
"$",
"amount",
"=",
"null",
")",
"{",
"$",
"timeKeys",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"date",... | Get array of DateTime objects build from $date (or current time if not given) $amount times back with given interval
Example:
$timeKeys = $service->getTimeKeys(new \DateInterval('PT1H'), new \DateTime('now'), 24);
array (
0 =>
DateTime::__set_state(array(
'date' => '2017-04-24 08:00:00.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
)),
1 =>
DateTime::__set_state(array(
'date' => '2017-04-24 07:00:00.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
)),
2 =>
DateTime::__set_state(array(
'date' => '2017-04-24 06:00:00.000000',
'timezone_type' => 1,
'timezone' => '+00:00',
)),
...
)
@param \DateInterval $interval
@param \DateTimeInterface|null $date
@param null $amount
@return \DateTime[] | [
"Get",
"array",
"of",
"DateTime",
"objects",
"build",
"from",
"$date",
"(",
"or",
"current",
"time",
"if",
"not",
"given",
")",
"$amount",
"times",
"back",
"with",
"given",
"interval",
"Example",
":",
"$timeKeys",
"=",
"$service",
"-",
">",
"getTimeKeys",
... | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Date.php#L247-L279 |
oat-sa/tao-core | models/classes/class.Compiler.php | tao_models_classes_Compiler.subCompile | protected function subCompile(core_kernel_classes_Resource $resource) {
$compilerClass = $this->getSubCompilerClass($resource);
if (!class_exists($compilerClass)) {
common_Logger::e('Class '.$compilerClass.' not found while instanciating Compiler');
return $this->fail(__('%s is of a type that cannot be published', $resource->getLabel()));
}
if (!is_subclass_of($compilerClass, __CLASS__)) {
common_Logger::e('Compiler class '.$compilerClass.' is not a compiler');
return $this->fail(__('%s is of a type that cannot be published', $resource->getLabel()));
}
/** @var $compiler tao_models_classes_Compiler */
$compiler = new $compilerClass($resource, $this->getStorage());
$compiler->setServiceLocator($this->getServiceLocator());
$compiler->setContext($this->getContext());
$report = $compiler->compile();
return $report;
} | php | protected function subCompile(core_kernel_classes_Resource $resource) {
$compilerClass = $this->getSubCompilerClass($resource);
if (!class_exists($compilerClass)) {
common_Logger::e('Class '.$compilerClass.' not found while instanciating Compiler');
return $this->fail(__('%s is of a type that cannot be published', $resource->getLabel()));
}
if (!is_subclass_of($compilerClass, __CLASS__)) {
common_Logger::e('Compiler class '.$compilerClass.' is not a compiler');
return $this->fail(__('%s is of a type that cannot be published', $resource->getLabel()));
}
/** @var $compiler tao_models_classes_Compiler */
$compiler = new $compilerClass($resource, $this->getStorage());
$compiler->setServiceLocator($this->getServiceLocator());
$compiler->setContext($this->getContext());
$report = $compiler->compile();
return $report;
} | [
"protected",
"function",
"subCompile",
"(",
"core_kernel_classes_Resource",
"$",
"resource",
")",
"{",
"$",
"compilerClass",
"=",
"$",
"this",
"->",
"getSubCompilerClass",
"(",
"$",
"resource",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"compilerClass",... | Compile a subelement of the current resource
@param core_kernel_classes_Resource $resource
@return common_report_Report returns a report that if successful contains the service call | [
"Compile",
"a",
"subelement",
"of",
"the",
"current",
"resource"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.Compiler.php#L121-L137 |
oat-sa/tao-core | models/classes/search/index/IndexService.php | IndexService.runIndexing | public function runIndexing()
{
$iterator = $this->getResourceIterator();
$indexIterator = new IndexIterator($iterator);
$indexIterator->setServiceLocator($this->getServiceLocator());
$searchService = $this->getServiceLocator()->get(Search::SERVICE_ID);
$result = $searchService->index($indexIterator);
$this->logDebug($result . ' resources have been indexed by ' . static::class);
return $result;
} | php | public function runIndexing()
{
$iterator = $this->getResourceIterator();
$indexIterator = new IndexIterator($iterator);
$indexIterator->setServiceLocator($this->getServiceLocator());
$searchService = $this->getServiceLocator()->get(Search::SERVICE_ID);
$result = $searchService->index($indexIterator);
$this->logDebug($result . ' resources have been indexed by ' . static::class);
return $result;
} | [
"public",
"function",
"runIndexing",
"(",
")",
"{",
"$",
"iterator",
"=",
"$",
"this",
"->",
"getResourceIterator",
"(",
")",
";",
"$",
"indexIterator",
"=",
"new",
"IndexIterator",
"(",
"$",
"iterator",
")",
";",
"$",
"indexIterator",
"->",
"setServiceLocat... | Run a full reindexing
@return boolean
@throws | [
"Run",
"a",
"full",
"reindexing"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/search/index/IndexService.php#L55-L64 |
oat-sa/tao-core | models/classes/security/xsrf/TokenStoreSession.php | TokenStoreSession.getTokens | public function getTokens()
{
$pool = null;
$session = \PHPSession::singleton();
if($session->hasAttribute(self::TOKEN_KEY)){
$pool = $session->getAttribute(self::TOKEN_KEY);
}
if(is_null($pool)){
$pool = [];
}
return $pool;
} | php | public function getTokens()
{
$pool = null;
$session = \PHPSession::singleton();
if($session->hasAttribute(self::TOKEN_KEY)){
$pool = $session->getAttribute(self::TOKEN_KEY);
}
if(is_null($pool)){
$pool = [];
}
return $pool;
} | [
"public",
"function",
"getTokens",
"(",
")",
"{",
"$",
"pool",
"=",
"null",
";",
"$",
"session",
"=",
"\\",
"PHPSession",
"::",
"singleton",
"(",
")",
";",
"if",
"(",
"$",
"session",
"->",
"hasAttribute",
"(",
"self",
"::",
"TOKEN_KEY",
")",
")",
"{"... | Retrieve the pool of tokens
@return array the tokens | [
"Retrieve",
"the",
"pool",
"of",
"tokens"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/security/xsrf/TokenStoreSession.php#L35-L47 |
oat-sa/tao-core | models/classes/security/xsrf/TokenStoreSession.php | TokenStoreSession.setTokens | public function setTokens(array $tokens = [])
{
$session = \PHPSession::singleton();
$session->setAttribute(self::TOKEN_KEY, $tokens);
} | php | public function setTokens(array $tokens = [])
{
$session = \PHPSession::singleton();
$session->setAttribute(self::TOKEN_KEY, $tokens);
} | [
"public",
"function",
"setTokens",
"(",
"array",
"$",
"tokens",
"=",
"[",
"]",
")",
"{",
"$",
"session",
"=",
"\\",
"PHPSession",
"::",
"singleton",
"(",
")",
";",
"$",
"session",
"->",
"setAttribute",
"(",
"self",
"::",
"TOKEN_KEY",
",",
"$",
"tokens"... | Set the pool of tokens
@param array $tokens the poll | [
"Set",
"the",
"pool",
"of",
"tokens"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/security/xsrf/TokenStoreSession.php#L53-L57 |
oat-sa/tao-core | actions/form/class.Search.php | tao_actions_form_Search.initElements | protected function initElements()
{
$chainingElt = tao_helpers_form_FormFactory::getElement('chaining', 'Radiobox');
$chainingElt->setDescription(__('Filtering mode'));
$chainingElt->setOptions(array('or' => __('Exclusive (OR)'), 'and' => __('Inclusive (AND)')));
$chainingElt->setValue('or');
$this->form->addElement($chainingElt);
$recursiveElt = tao_helpers_form_FormFactory::getElement('recursive', 'Checkbox');
$recursiveElt->setDescription(__('Scope'));
$recursiveElt->setOptions(array('0' => __('Search sub-classes')));
$this->form->addElement($recursiveElt);
$searchClassUriElt = tao_helpers_form_FormFactory::getElement("clazzUri", "Hidden");
$searchClassUriElt->setValue(tao_helpers_Uri::encode($this->clazz->getUri()));
$this->form->addElement($searchClassUriElt);
$langElt = tao_helpers_form_FormFactory::getElement('lang', 'Combobox');
$langElt->setDescription(__('Language'));
$languages = array_merge(array('-- any --'), tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA)));
$langElt->setOptions($languages);
$langElt->setValue(0);
$this->form->addElement($langElt);
$this->form->createGroup('params', __('<del>Options</del>'), array('chaining', 'recursive', 'lang'));
$filters = array();
$defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties();
$classProperties = $this->getClassProperties();
$properties = array_merge($defaultProperties, $classProperties);
(isset($this->options['recursive'])) ? $recursive = $this->options['recursive'] : $recursive = false;
if($recursive){
foreach($this->clazz->getSubClasses(true) as $subClass){
$properties = array_merge($subClass->getProperties(false), $properties);
}
}
foreach($properties as $property){
$element = tao_helpers_form_GenerisFormFactory::elementMap($property);
if( ! is_null($element) &&
! $element instanceof tao_helpers_form_elements_Authoring &&
! $element instanceof tao_helpers_form_elements_Hiddenbox &&
! $element instanceof tao_helpers_form_elements_Hidden ){
if($element instanceof tao_helpers_form_elements_MultipleElement){
$newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Checkbox');
$newElement->setDescription($element->getDescription());
$newElement->setOptions($element->getOptions());
$element = $newElement;
}
if($element instanceof tao_helpers_form_elements_Htmlarea){
$newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Textarea');
$newElement->setDescription($element->getDescription());
$element = $newElement;
}
$this->form->addElement($element);
$filters[] = $element->getName();
}
}
$this->form->createGroup('filters', __('<del>Filters</del>'), $filters);
} | php | protected function initElements()
{
$chainingElt = tao_helpers_form_FormFactory::getElement('chaining', 'Radiobox');
$chainingElt->setDescription(__('Filtering mode'));
$chainingElt->setOptions(array('or' => __('Exclusive (OR)'), 'and' => __('Inclusive (AND)')));
$chainingElt->setValue('or');
$this->form->addElement($chainingElt);
$recursiveElt = tao_helpers_form_FormFactory::getElement('recursive', 'Checkbox');
$recursiveElt->setDescription(__('Scope'));
$recursiveElt->setOptions(array('0' => __('Search sub-classes')));
$this->form->addElement($recursiveElt);
$searchClassUriElt = tao_helpers_form_FormFactory::getElement("clazzUri", "Hidden");
$searchClassUriElt->setValue(tao_helpers_Uri::encode($this->clazz->getUri()));
$this->form->addElement($searchClassUriElt);
$langElt = tao_helpers_form_FormFactory::getElement('lang', 'Combobox');
$langElt->setDescription(__('Language'));
$languages = array_merge(array('-- any --'), tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(tao_models_classes_LanguageService::INSTANCE_LANGUAGE_USAGE_DATA)));
$langElt->setOptions($languages);
$langElt->setValue(0);
$this->form->addElement($langElt);
$this->form->createGroup('params', __('<del>Options</del>'), array('chaining', 'recursive', 'lang'));
$filters = array();
$defaultProperties = tao_helpers_form_GenerisFormFactory::getDefaultProperties();
$classProperties = $this->getClassProperties();
$properties = array_merge($defaultProperties, $classProperties);
(isset($this->options['recursive'])) ? $recursive = $this->options['recursive'] : $recursive = false;
if($recursive){
foreach($this->clazz->getSubClasses(true) as $subClass){
$properties = array_merge($subClass->getProperties(false), $properties);
}
}
foreach($properties as $property){
$element = tao_helpers_form_GenerisFormFactory::elementMap($property);
if( ! is_null($element) &&
! $element instanceof tao_helpers_form_elements_Authoring &&
! $element instanceof tao_helpers_form_elements_Hiddenbox &&
! $element instanceof tao_helpers_form_elements_Hidden ){
if($element instanceof tao_helpers_form_elements_MultipleElement){
$newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Checkbox');
$newElement->setDescription($element->getDescription());
$newElement->setOptions($element->getOptions());
$element = $newElement;
}
if($element instanceof tao_helpers_form_elements_Htmlarea){
$newElement = tao_helpers_form_FormFactory::getElement($element->getName(), 'Textarea');
$newElement->setDescription($element->getDescription());
$element = $newElement;
}
$this->form->addElement($element);
$filters[] = $element->getName();
}
}
$this->form->createGroup('filters', __('<del>Filters</del>'), $filters);
} | [
"protected",
"function",
"initElements",
"(",
")",
"{",
"$",
"chainingElt",
"=",
"tao_helpers_form_FormFactory",
"::",
"getElement",
"(",
"'chaining'",
",",
"'Radiobox'",
")",
";",
"$",
"chainingElt",
"->",
"setDescription",
"(",
"__",
"(",
"'Filtering mode'",
")"... | 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.Search.php#L87-L159 |
oat-sa/tao-core | models/classes/resources/ResourceIterator.php | ResourceIterator.loadResources | protected function loadResources(core_kernel_classes_Class $class, $offset)
{
$search = $this->getServiceLocator()->get(ComplexSearchService::SERVICE_ID);
$queryBuilder = $search->query()->setLimit(self::CACHE_SIZE)->setOffset($offset);
$criteria = $search->searchType($queryBuilder, $class->getUri(), false);
if ($this->criteria !== null) {
foreach ($this->criteria->getStoredQueryCriteria() as $storedQueryCriterion) {
$criteria->addCriterion(
$storedQueryCriterion->getName(),
$storedQueryCriterion->getOperator(),
$storedQueryCriterion->getValue()
);
}
}
$queryBuilder = $queryBuilder->setCriteria($criteria);
return $search->getGateway()->search($queryBuilder);
} | php | protected function loadResources(core_kernel_classes_Class $class, $offset)
{
$search = $this->getServiceLocator()->get(ComplexSearchService::SERVICE_ID);
$queryBuilder = $search->query()->setLimit(self::CACHE_SIZE)->setOffset($offset);
$criteria = $search->searchType($queryBuilder, $class->getUri(), false);
if ($this->criteria !== null) {
foreach ($this->criteria->getStoredQueryCriteria() as $storedQueryCriterion) {
$criteria->addCriterion(
$storedQueryCriterion->getName(),
$storedQueryCriterion->getOperator(),
$storedQueryCriterion->getValue()
);
}
}
$queryBuilder = $queryBuilder->setCriteria($criteria);
return $search->getGateway()->search($queryBuilder);
} | [
"protected",
"function",
"loadResources",
"(",
"core_kernel_classes_Class",
"$",
"class",
",",
"$",
"offset",
")",
"{",
"$",
"search",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"ComplexSearchService",
"::",
"SERVICE_ID",
")",
";"... | Load resources from storage
@param core_kernel_classes_Class $class
@param integer $offset
@return core_kernel_classes_Resource[] | [
"Load",
"resources",
"from",
"storage"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/resources/ResourceIterator.php#L62-L79 |
oat-sa/tao-core | models/classes/websource/FlyTokenWebSource.php | FlyTokenWebSource.getFilePathFromUrl | public function getFilePathFromUrl($url)
{
$url = parse_url($url)['path']; //remove query part from url.
$rel = substr($url, strpos($url, self::ENTRY_POINT) + strlen(self::ENTRY_POINT));
$parts = explode('/', $rel, 4);
list ($webSourceId, $timestamp, $token, $subPath) = $parts;
$parts = explode('*/', $subPath, 2);
if (count($parts) < 2) {
throw new \tao_models_classes_FileNotFoundException('`'.$subPath.'` - (wrong number of path parts)');
}
list ($subPath, $file) = $parts;
$secret = $this->getOption('secret');
$ttl = $this->getOption('ttl');
$correctToken = md5($timestamp . $subPath . $secret);
if (time() - $timestamp > $ttl) {
throw new \tao_models_classes_FileNotFoundException('`' . $subPath . $file . '` - (file link expired)');
}
if ($token != $correctToken) {
throw new \tao_models_classes_FileNotFoundException('`' . $subPath . $file . '` - (wrong token)');
}
$path = array();
foreach (explode('/', $subPath . $file) as $ele) {
$path[] = rawurldecode($ele);
}
$filename = implode('/', $path);
return $filename;
} | php | public function getFilePathFromUrl($url)
{
$url = parse_url($url)['path']; //remove query part from url.
$rel = substr($url, strpos($url, self::ENTRY_POINT) + strlen(self::ENTRY_POINT));
$parts = explode('/', $rel, 4);
list ($webSourceId, $timestamp, $token, $subPath) = $parts;
$parts = explode('*/', $subPath, 2);
if (count($parts) < 2) {
throw new \tao_models_classes_FileNotFoundException('`'.$subPath.'` - (wrong number of path parts)');
}
list ($subPath, $file) = $parts;
$secret = $this->getOption('secret');
$ttl = $this->getOption('ttl');
$correctToken = md5($timestamp . $subPath . $secret);
if (time() - $timestamp > $ttl) {
throw new \tao_models_classes_FileNotFoundException('`' . $subPath . $file . '` - (file link expired)');
}
if ($token != $correctToken) {
throw new \tao_models_classes_FileNotFoundException('`' . $subPath . $file . '` - (wrong token)');
}
$path = array();
foreach (explode('/', $subPath . $file) as $ele) {
$path[] = rawurldecode($ele);
}
$filename = implode('/', $path);
return $filename;
} | [
"public",
"function",
"getFilePathFromUrl",
"(",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"url",
")",
"[",
"'path'",
"]",
";",
"//remove query part from url.",
"$",
"rel",
"=",
"substr",
"(",
"$",
"url",
",",
"strpos",
"(",
"$",
"u... | Get file path from url.
@param null $url
@return string
@throws \tao_models_classes_FileNotFoundException | [
"Get",
"file",
"path",
"from",
"url",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/websource/FlyTokenWebSource.php#L47-L80 |
oat-sa/tao-core | helpers/form/elements/xhtml/class.Button.php | tao_helpers_form_elements_xhtml_Button.render | public function render()
{
$returnValue = $this->renderLabel();
$content = _dh($this->value);
if ($this->icon) {
$content = $this->iconPosition === 'before' ? $this->icon . ' ' . $content : $content . ' ' . $this->icon;
}
$returnValue .= "<button type='{$this->type}' name='{$this->name}' id='{$this->name}' ";
$returnValue .= $this->renderAttributes();
$returnValue .= ' value="' . _dh($this->value) . '">' . $content . '</button>';
return $returnValue;
} | php | public function render()
{
$returnValue = $this->renderLabel();
$content = _dh($this->value);
if ($this->icon) {
$content = $this->iconPosition === 'before' ? $this->icon . ' ' . $content : $content . ' ' . $this->icon;
}
$returnValue .= "<button type='{$this->type}' name='{$this->name}' id='{$this->name}' ";
$returnValue .= $this->renderAttributes();
$returnValue .= ' value="' . _dh($this->value) . '">' . $content . '</button>';
return $returnValue;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"returnValue",
"=",
"$",
"this",
"->",
"renderLabel",
"(",
")",
";",
"$",
"content",
"=",
"_dh",
"(",
"$",
"this",
"->",
"value",
")",
";",
"if",
"(",
"$",
"this",
"->",
"icon",
")",
"{",
"$",
... | Short description of method render
@access public
@author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
@return string | [
"Short",
"description",
"of",
"method",
"render"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/elements/xhtml/class.Button.php#L66-L81 |
oat-sa/tao-core | models/classes/extension/UpdateExtensions.php | UpdateExtensions.updateCacheBuster | private function updateCacheBuster(common_report_Report $report, $updateid)
{
try {
$assetService = $this->getServiceLocator()->get(AssetService::SERVICE_ID);
$assetService->setCacheBuster($updateid);
$this->getServiceLocator()->register(AssetService::SERVICE_ID, $assetService);
} catch (\Exception $e) {
\common_Logger::e($e->getMessage());
$report->add(new common_report_Report(common_report_Report::TYPE_WARNING,__('Unable to update the asset service')));
}
} | php | private function updateCacheBuster(common_report_Report $report, $updateid)
{
try {
$assetService = $this->getServiceLocator()->get(AssetService::SERVICE_ID);
$assetService->setCacheBuster($updateid);
$this->getServiceLocator()->register(AssetService::SERVICE_ID, $assetService);
} catch (\Exception $e) {
\common_Logger::e($e->getMessage());
$report->add(new common_report_Report(common_report_Report::TYPE_WARNING,__('Unable to update the asset service')));
}
} | [
"private",
"function",
"updateCacheBuster",
"(",
"common_report_Report",
"$",
"report",
",",
"$",
"updateid",
")",
"{",
"try",
"{",
"$",
"assetService",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"AssetService",
"::",
"SERVICE_ID"... | Update the asset service to save the cache buster value (the update id)
@param common_report_Report $report
@param string $updateid | [
"Update",
"the",
"asset",
"service",
"to",
"save",
"the",
"cache",
"buster",
"value",
"(",
"the",
"update",
"id",
")"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/extension/UpdateExtensions.php#L80-L90 |
oat-sa/tao-core | models/classes/oauth/OauthService.php | OauthService.sign | public function sign(common_http_Request $request, \common_http_Credentials $credentials, $authorizationHeader = false) {
if (!$credentials instanceof \tao_models_classes_oauth_Credentials) {
throw new \tao_models_classes_oauth_Exception('Invalid credentals: '.gettype($credentials));
}
$oauthRequest = $this->getOauthRequest($request);
$dataStore = $this->getDataStore();
$consumer = $dataStore->getOauthConsumer($credentials);
$token = $dataStore->new_request_token($consumer);
$allInitialParameters = array();
$allInitialParameters = array_merge($allInitialParameters, $request->getParams());
$allInitialParameters = array_merge($allInitialParameters, $request->getHeaders());
//oauth_body_hash is used for the signing computation
if ($authorizationHeader) {
$oauth_body_hash = base64_encode(sha1($request->getBody(), true));//the signature should be ciomputed from encoded versions
$allInitialParameters = array_merge($allInitialParameters, array("oauth_body_hash" =>$oauth_body_hash));
}
$signedRequest = OAuthRequest::from_consumer_and_token(
$consumer,
$token,
$oauthRequest->get_normalized_http_method(),
$oauthRequest->to_url(),
$allInitialParameters
);
$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$signedRequest->sign_request($signature_method, $consumer, $token);
//common_logger::d('Base string from TAO/Joel: '.$signedRequest->get_signature_base_string());
if ($authorizationHeader) {
$combinedParameters = $signedRequest->get_parameters();
$signatureParameters = array_diff_assoc($combinedParameters, $allInitialParameters);
$signatureParameters["oauth_body_hash"] = base64_encode(sha1($request->getBody(), true));
$signatureHeaders = array("Authorization" => $this->buildAuthorizationHeader($signatureParameters));
$signedRequest = new common_http_Request(
$signedRequest->to_url(),
$signedRequest->get_normalized_http_method(),
$request->getParams(),
array_merge($signatureHeaders, $request->getHeaders()),
$request->getBody()
);
} else {
$signedRequest = new common_http_Request(
$signedRequest->to_url(),
$signedRequest->get_normalized_http_method(),
$signedRequest->get_parameters(),
$request->getHeaders(),
$request->getBody()
);
}
return $signedRequest;
} | php | public function sign(common_http_Request $request, \common_http_Credentials $credentials, $authorizationHeader = false) {
if (!$credentials instanceof \tao_models_classes_oauth_Credentials) {
throw new \tao_models_classes_oauth_Exception('Invalid credentals: '.gettype($credentials));
}
$oauthRequest = $this->getOauthRequest($request);
$dataStore = $this->getDataStore();
$consumer = $dataStore->getOauthConsumer($credentials);
$token = $dataStore->new_request_token($consumer);
$allInitialParameters = array();
$allInitialParameters = array_merge($allInitialParameters, $request->getParams());
$allInitialParameters = array_merge($allInitialParameters, $request->getHeaders());
//oauth_body_hash is used for the signing computation
if ($authorizationHeader) {
$oauth_body_hash = base64_encode(sha1($request->getBody(), true));//the signature should be ciomputed from encoded versions
$allInitialParameters = array_merge($allInitialParameters, array("oauth_body_hash" =>$oauth_body_hash));
}
$signedRequest = OAuthRequest::from_consumer_and_token(
$consumer,
$token,
$oauthRequest->get_normalized_http_method(),
$oauthRequest->to_url(),
$allInitialParameters
);
$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$signedRequest->sign_request($signature_method, $consumer, $token);
//common_logger::d('Base string from TAO/Joel: '.$signedRequest->get_signature_base_string());
if ($authorizationHeader) {
$combinedParameters = $signedRequest->get_parameters();
$signatureParameters = array_diff_assoc($combinedParameters, $allInitialParameters);
$signatureParameters["oauth_body_hash"] = base64_encode(sha1($request->getBody(), true));
$signatureHeaders = array("Authorization" => $this->buildAuthorizationHeader($signatureParameters));
$signedRequest = new common_http_Request(
$signedRequest->to_url(),
$signedRequest->get_normalized_http_method(),
$request->getParams(),
array_merge($signatureHeaders, $request->getHeaders()),
$request->getBody()
);
} else {
$signedRequest = new common_http_Request(
$signedRequest->to_url(),
$signedRequest->get_normalized_http_method(),
$signedRequest->get_parameters(),
$request->getHeaders(),
$request->getBody()
);
}
return $signedRequest;
} | [
"public",
"function",
"sign",
"(",
"common_http_Request",
"$",
"request",
",",
"\\",
"common_http_Credentials",
"$",
"credentials",
",",
"$",
"authorizationHeader",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"credentials",
"instanceof",
"\\",
"tao_models_classes... | Adds a signature to the request
@access public
@author Joel Bout, <joel@taotesting.com>
@param $authorizationHeader Move the signature parameters into the Authorization header of the request
@return common_http_Request | [
"Adds",
"a",
"signature",
"to",
"the",
"request"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/oauth/OauthService.php#L49-L106 |
oat-sa/tao-core | models/classes/oauth/OauthService.php | OauthService.validate | public function validate(common_http_Request $request, \common_http_Credentials $credentials = null) {
$server = new OAuthServer($this->getDataStore());
$method = new OAuthSignatureMethod_HMAC_SHA1();
$server->add_signature_method($method);
try {
$oauthRequest = $this->getOauthRequest($request);
$server->verify_request($oauthRequest);
} catch (OAuthException $e) {
throw new \common_http_InvalidSignatureException('Validation failed: '.$e->getMessage());
}
} | php | public function validate(common_http_Request $request, \common_http_Credentials $credentials = null) {
$server = new OAuthServer($this->getDataStore());
$method = new OAuthSignatureMethod_HMAC_SHA1();
$server->add_signature_method($method);
try {
$oauthRequest = $this->getOauthRequest($request);
$server->verify_request($oauthRequest);
} catch (OAuthException $e) {
throw new \common_http_InvalidSignatureException('Validation failed: '.$e->getMessage());
}
} | [
"public",
"function",
"validate",
"(",
"common_http_Request",
"$",
"request",
",",
"\\",
"common_http_Credentials",
"$",
"credentials",
"=",
"null",
")",
"{",
"$",
"server",
"=",
"new",
"OAuthServer",
"(",
"$",
"this",
"->",
"getDataStore",
"(",
")",
")",
";... | Validates the signature of the current request
@access protected
@author Joel Bout, <joel@taotesting.com>
@param common_http_Request request
@throws common_Exception exception thrown if validation fails | [
"Validates",
"the",
"signature",
"of",
"the",
"current",
"request"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/oauth/OauthService.php#L116-L127 |
oat-sa/tao-core | models/classes/oauth/OauthService.php | OauthService.buildAuthorizationHeader | private function buildAuthorizationHeader($signatureParameters) {
$authorizationHeader = 'OAuth realm=""';
foreach ($signatureParameters as $key=>$value) {
$authorizationHeader.=','.$key."=".'"'.urlencode($value).'"';
}
return $authorizationHeader;
} | php | private function buildAuthorizationHeader($signatureParameters) {
$authorizationHeader = 'OAuth realm=""';
foreach ($signatureParameters as $key=>$value) {
$authorizationHeader.=','.$key."=".'"'.urlencode($value).'"';
}
return $authorizationHeader;
} | [
"private",
"function",
"buildAuthorizationHeader",
"(",
"$",
"signatureParameters",
")",
"{",
"$",
"authorizationHeader",
"=",
"'OAuth realm=\"\"'",
";",
"foreach",
"(",
"$",
"signatureParameters",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"authorizatio... | As per the OAuth body hashing specification, all of the OAuth parameters must be sent as part of the Authorization header.
In particular, OAuth parameters from the request URL and POST body will be ignored.
Return the Authorization header | [
"As",
"per",
"the",
"OAuth",
"body",
"hashing",
"specification",
"all",
"of",
"the",
"OAuth",
"parameters",
"must",
"be",
"sent",
"as",
"part",
"of",
"the",
"Authorization",
"header",
".",
"In",
"particular",
"OAuth",
"parameters",
"from",
"the",
"request",
... | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/oauth/OauthService.php#L141-L148 |
oat-sa/tao-core | models/classes/oauth/OauthService.php | OauthService.getOauthRequest | private function getOauthRequest(common_http_Request $request) {
$params = array();
$params = array_merge($params, $request->getParams());
//$params = array_merge($params, $request->getHeaders());
\common_Logger::d("OAuth Request created:".$request->getUrl()." using ".$request->getMethod());
$oauthRequest = new OAuthRequest($request->getMethod(), $request->getUrl(), $params);
return $oauthRequest;
} | php | private function getOauthRequest(common_http_Request $request) {
$params = array();
$params = array_merge($params, $request->getParams());
//$params = array_merge($params, $request->getHeaders());
\common_Logger::d("OAuth Request created:".$request->getUrl()." using ".$request->getMethod());
$oauthRequest = new OAuthRequest($request->getMethod(), $request->getUrl(), $params);
return $oauthRequest;
} | [
"private",
"function",
"getOauthRequest",
"(",
"common_http_Request",
"$",
"request",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"request",
"->",
"getParams",
"(",
")",
")",
";",... | Transform common_http_Request into an OAuth request
@param common_http_Request $request
@return \IMSGlobal\LTI\OAuth\OAuthRequest | [
"Transform",
"common_http_Request",
"into",
"an",
"OAuth",
"request"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/oauth/OauthService.php#L155-L163 |
oat-sa/tao-core | models/classes/modules/AbstractModuleService.php | AbstractModuleService.getAllModules | public function getAllModules()
{
$modules = array_map(function ($value) {
return $this->loadModule($value);
}, $this->registry->getMap());
return array_filter($modules, function ($module) {
return !is_null($module);
});
} | php | public function getAllModules()
{
$modules = array_map(function ($value) {
return $this->loadModule($value);
}, $this->registry->getMap());
return array_filter($modules, function ($module) {
return !is_null($module);
});
} | [
"public",
"function",
"getAllModules",
"(",
")",
"{",
"$",
"modules",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"this",
"->",
"loadModule",
"(",
"$",
"value",
")",
";",
"}",
",",
"$",
"this",
"->",
"registry",
"->... | Retrieve the list of all available modules (from the registry)
@return DynamicModule[] the available modules | [
"Retrieve",
"the",
"list",
"of",
"all",
"available",
"modules",
"(",
"from",
"the",
"registry",
")"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/AbstractModuleService.php#L62-L71 |
oat-sa/tao-core | models/classes/modules/AbstractModuleService.php | AbstractModuleService.getModule | public function getModule($id)
{
foreach ($this->registry->getMap() as $module) {
if ($module['id'] == $id) {
return $this->loadModule($module);
}
}
return null;
} | php | public function getModule($id)
{
foreach ($this->registry->getMap() as $module) {
if ($module['id'] == $id) {
return $this->loadModule($module);
}
}
return null;
} | [
"public",
"function",
"getModule",
"(",
"$",
"id",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"registry",
"->",
"getMap",
"(",
")",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"$",
"module",
"[",
"'id'",
"]",
"==",
"$",
"id",
")",
"{",
"return",
... | Retrieve the given module from the registry
@param string $id the identifier of the module to retrieve
@return DynamicModule|null the module | [
"Retrieve",
"the",
"given",
"module",
"from",
"the",
"registry"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/AbstractModuleService.php#L79-L87 |
oat-sa/tao-core | models/classes/modules/AbstractModuleService.php | AbstractModuleService.loadModule | private function loadModule(array $data)
{
$module = null;
try {
$module = $this->createFromArray($data);
} catch (\common_exception_InconsistentData $dataException) {
\common_Logger::w('Got inconsistent module data, skipping.');
}
return $module;
} | php | private function loadModule(array $data)
{
$module = null;
try {
$module = $this->createFromArray($data);
} catch (\common_exception_InconsistentData $dataException) {
\common_Logger::w('Got inconsistent module data, skipping.');
}
return $module;
} | [
"private",
"function",
"loadModule",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"module",
"=",
"null",
";",
"try",
"{",
"$",
"module",
"=",
"$",
"this",
"->",
"createFromArray",
"(",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"\\",
"common_exception_Inco... | Load a module from the given data
@param array $data
@return DynamicModule|null | [
"Load",
"a",
"module",
"from",
"the",
"given",
"data"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/AbstractModuleService.php#L94-L103 |
oat-sa/tao-core | models/classes/modules/AbstractModuleService.php | AbstractModuleService.activateModule | public function activateModule(DynamicModule $module)
{
if (!is_null($module)) {
$module->setActive(true);
return $this->registry->register($module);
}
return false;
} | php | public function activateModule(DynamicModule $module)
{
if (!is_null($module)) {
$module->setActive(true);
return $this->registry->register($module);
}
return false;
} | [
"public",
"function",
"activateModule",
"(",
"DynamicModule",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"module",
")",
")",
"{",
"$",
"module",
"->",
"setActive",
"(",
"true",
")",
";",
"return",
"$",
"this",
"->",
"registry",
"->",... | Change the state of a module to active
@param DynamicModule $module the module to activate
@return boolean true if activated | [
"Change",
"the",
"state",
"of",
"a",
"module",
"to",
"active"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/AbstractModuleService.php#L111-L119 |
oat-sa/tao-core | models/classes/modules/AbstractModuleService.php | AbstractModuleService.deactivateModule | public function deactivateModule(DynamicModule $module)
{
if (!is_null($module)) {
$module->setActive(false);
return $this->registry->register($module);
}
return false;
} | php | public function deactivateModule(DynamicModule $module)
{
if (!is_null($module)) {
$module->setActive(false);
return $this->registry->register($module);
}
return false;
} | [
"public",
"function",
"deactivateModule",
"(",
"DynamicModule",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"module",
")",
")",
"{",
"$",
"module",
"->",
"setActive",
"(",
"false",
")",
";",
"return",
"$",
"this",
"->",
"registry",
"-... | Change the state of a module to inactive
@param DynamicModule $module the module to deactivate
@return boolean true if deactivated | [
"Change",
"the",
"state",
"of",
"a",
"module",
"to",
"inactive"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/AbstractModuleService.php#L127-L135 |
oat-sa/tao-core | models/classes/modules/AbstractModuleService.php | AbstractModuleService.registerModules | public function registerModules(array $modules)
{
$count = 0;
foreach($modules as $module) {
if (is_array($module)) {
$module = $this->createFromArray($module);
}
$this->registry->register($module);
$count ++;
}
return $count;
} | php | public function registerModules(array $modules)
{
$count = 0;
foreach($modules as $module) {
if (is_array($module)) {
$module = $this->createFromArray($module);
}
$this->registry->register($module);
$count ++;
}
return $count;
} | [
"public",
"function",
"registerModules",
"(",
"array",
"$",
"modules",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"module",
")",
")",
"{",
"$",
"module",
"=... | Register a list of modules
@param array $modules
@return int The number of registered modules
@throws \common_exception_InconsistentData | [
"Register",
"a",
"list",
"of",
"modules"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/AbstractModuleService.php#L143-L154 |
oat-sa/tao-core | models/classes/modules/AbstractModuleService.php | AbstractModuleService.registerModulesByCategories | public function registerModulesByCategories(array $modules)
{
$count = 0;
foreach($modules as $categoryModules) {
if (is_array($categoryModules)) {
$count += $this->registerModules($categoryModules);
} else {
throw new \common_exception_InvalidArgumentType(self::class, __FUNCTION__, 0, 'array', $categoryModules);
}
}
return $count;
} | php | public function registerModulesByCategories(array $modules)
{
$count = 0;
foreach($modules as $categoryModules) {
if (is_array($categoryModules)) {
$count += $this->registerModules($categoryModules);
} else {
throw new \common_exception_InvalidArgumentType(self::class, __FUNCTION__, 0, 'array', $categoryModules);
}
}
return $count;
} | [
"public",
"function",
"registerModulesByCategories",
"(",
"array",
"$",
"modules",
")",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"categoryModules",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"categoryModules",
")",
")",
... | Register a list of modules gathered by categories
@param array $modules
@return int The number of registered modules
@throws \common_exception_InconsistentData
@throws \common_exception_InvalidArgumentType | [
"Register",
"a",
"list",
"of",
"modules",
"gathered",
"by",
"categories"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/modules/AbstractModuleService.php#L163-L174 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.getLists | public function getLists()
{
$returnValue = array();
$returnValue[] = new core_kernel_classes_Class(GenerisRdf::GENERIS_BOOLEAN);
foreach($this->parentListClass->getSubClasses(false) as $list){
$returnValue[] = $list;
}
return (array) $returnValue;
} | php | public function getLists()
{
$returnValue = array();
$returnValue[] = new core_kernel_classes_Class(GenerisRdf::GENERIS_BOOLEAN);
foreach($this->parentListClass->getSubClasses(false) as $list){
$returnValue[] = $list;
}
return (array) $returnValue;
} | [
"public",
"function",
"getLists",
"(",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"$",
"returnValue",
"[",
"]",
"=",
"new",
"core_kernel_classes_Class",
"(",
"GenerisRdf",
"::",
"GENERIS_BOOLEAN",
")",
";",
"foreach",
"(",
"$",
"this",
"->"... | get all the lists class
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@return array | [
"get",
"all",
"the",
"lists",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L75-L92 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.getList | public function getList($uri)
{
$returnValue = null;
foreach($this->getLists() as $list){
if($list->getUri() == $uri){
$returnValue = $list;
break;
}
}
return $returnValue;
} | php | public function getList($uri)
{
$returnValue = null;
foreach($this->getLists() as $list){
if($list->getUri() == $uri){
$returnValue = $list;
break;
}
}
return $returnValue;
} | [
"public",
"function",
"getList",
"(",
"$",
"uri",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"foreach",
"(",
"$",
"this",
"->",
"getLists",
"(",
")",
"as",
"$",
"list",
")",
"{",
"if",
"(",
"$",
"list",
"->",
"getUri",
"(",
")",
"==",
"$",
... | Get a list class from the uri in parameter
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param string uri
@return core_kernel_classes_Class | [
"Get",
"a",
"list",
"class",
"from",
"the",
"uri",
"in",
"parameter"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L102-L118 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.getListElement | public function getListElement( core_kernel_classes_Class $listClass, $uri)
{
$returnValue = null;
if(!empty($uri)){
foreach($this->getListElements($listClass, false) as $element){
if($element->getUri() == $uri){
$returnValue = $element;
break;
}
}
}
return $returnValue;
} | php | public function getListElement( core_kernel_classes_Class $listClass, $uri)
{
$returnValue = null;
if(!empty($uri)){
foreach($this->getListElements($listClass, false) as $element){
if($element->getUri() == $uri){
$returnValue = $element;
break;
}
}
}
return $returnValue;
} | [
"public",
"function",
"getListElement",
"(",
"core_kernel_classes_Class",
"$",
"listClass",
",",
"$",
"uri",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"uri",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"ge... | get the element of the list defined by listClass and identified by the
in parameter
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Class listClass
@param string uri
@return core_kernel_classes_Resource | [
"get",
"the",
"element",
"of",
"the",
"list",
"defined",
"by",
"listClass",
"and",
"identified",
"by",
"the",
"in",
"parameter"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L130-L148 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.getListElements | public function getListElements( core_kernel_classes_Class $listClass, $sort = true)
{
$returnValue = array();
if($sort){
$levelProperty = new core_kernel_classes_Property(TaoOntology::PROPERTY_LIST_LEVEL);
foreach ($listClass->getInstances(false) as $element) {
$literal = $element->getOnePropertyValue($levelProperty);
$level = is_null($literal) ? 0 : (string) $literal;
while (isset($returnValue[$level])) {
$level++;
}
$returnValue[$level] = $element;
}
uksort($returnValue, 'strnatcasecmp');
}
else{
$returnValue = $listClass->getInstances(false);
}
return (array) $returnValue;
} | php | public function getListElements( core_kernel_classes_Class $listClass, $sort = true)
{
$returnValue = array();
if($sort){
$levelProperty = new core_kernel_classes_Property(TaoOntology::PROPERTY_LIST_LEVEL);
foreach ($listClass->getInstances(false) as $element) {
$literal = $element->getOnePropertyValue($levelProperty);
$level = is_null($literal) ? 0 : (string) $literal;
while (isset($returnValue[$level])) {
$level++;
}
$returnValue[$level] = $element;
}
uksort($returnValue, 'strnatcasecmp');
}
else{
$returnValue = $listClass->getInstances(false);
}
return (array) $returnValue;
} | [
"public",
"function",
"getListElements",
"(",
"core_kernel_classes_Class",
"$",
"listClass",
",",
"$",
"sort",
"=",
"true",
")",
"{",
"$",
"returnValue",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"sort",
")",
"{",
"$",
"levelProperty",
"=",
"new",
"co... | get all the elements of the list
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Class listClass
@param boolean sort
@return array | [
"get",
"all",
"the",
"elements",
"of",
"the",
"list"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L159-L180 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.removeList | public function removeList( core_kernel_classes_Class $listClass)
{
$returnValue = (bool) false;
if(!is_null($listClass)){
foreach($this->getListElements($listClass) as $element){
$this->removeListElement($element);
}
$returnValue = $listClass->delete();
}
return (bool) $returnValue;
} | php | public function removeList( core_kernel_classes_Class $listClass)
{
$returnValue = (bool) false;
if(!is_null($listClass)){
foreach($this->getListElements($listClass) as $element){
$this->removeListElement($element);
}
$returnValue = $listClass->delete();
}
return (bool) $returnValue;
} | [
"public",
"function",
"removeList",
"(",
"core_kernel_classes_Class",
"$",
"listClass",
")",
"{",
"$",
"returnValue",
"=",
"(",
"bool",
")",
"false",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"listClass",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",... | remove a list and it's elements
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Class listClass
@return boolean | [
"remove",
"a",
"list",
"and",
"it",
"s",
"elements"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L190-L206 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.removeListElement | public function removeListElement( core_kernel_classes_Resource $element)
{
$returnValue = (bool) false;
if(!is_null($element)){
$returnValue = $element->delete();
}
return (bool) $returnValue;
} | php | public function removeListElement( core_kernel_classes_Resource $element)
{
$returnValue = (bool) false;
if(!is_null($element)){
$returnValue = $element->delete();
}
return (bool) $returnValue;
} | [
"public",
"function",
"removeListElement",
"(",
"core_kernel_classes_Resource",
"$",
"element",
")",
"{",
"$",
"returnValue",
"=",
"(",
"bool",
")",
"false",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"element",
")",
")",
"{",
"$",
"returnValue",
"=",
"$",
... | remove a list element
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Resource element
@return boolean | [
"remove",
"a",
"list",
"element"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L216-L229 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.createList | public function createList($label = '')
{
$returnValue = null;
if(empty($label)) {
$label = __('List') . ' ' . (count($this->getLists()) + 1);
}
$returnValue = $this->createSubClass($this->parentListClass, $label);
return $returnValue;
} | php | public function createList($label = '')
{
$returnValue = null;
if(empty($label)) {
$label = __('List') . ' ' . (count($this->getLists()) + 1);
}
$returnValue = $this->createSubClass($this->parentListClass, $label);
return $returnValue;
} | [
"public",
"function",
"createList",
"(",
"$",
"label",
"=",
"''",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"label",
")",
")",
"{",
"$",
"label",
"=",
"__",
"(",
"'List'",
")",
".",
"' '",
".",
"(",
"count",
... | create a new list class
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param string label
@return core_kernel_classes_Class | [
"create",
"a",
"new",
"list",
"class"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L239-L253 |
oat-sa/tao-core | models/classes/class.ListService.php | tao_models_classes_ListService.createListElement | public function createListElement( core_kernel_classes_Class $listClass, $label = '')
{
$returnValue = null;
if(!is_null($listClass)){
$level = count($this->getListElements($listClass)) + 1;
if(empty($label)) {
$label = __('Element') . ' ' . $level;
}
$returnValue = $this->createInstance($listClass, $label);
$this->bindProperties($returnValue, array(TaoOntology::PROPERTY_LIST_LEVEL => count($this->getListElements($listClass, false))));
}
return $returnValue;
} | php | public function createListElement( core_kernel_classes_Class $listClass, $label = '')
{
$returnValue = null;
if(!is_null($listClass)){
$level = count($this->getListElements($listClass)) + 1;
if(empty($label)) {
$label = __('Element') . ' ' . $level;
}
$returnValue = $this->createInstance($listClass, $label);
$this->bindProperties($returnValue, array(TaoOntology::PROPERTY_LIST_LEVEL => count($this->getListElements($listClass, false))));
}
return $returnValue;
} | [
"public",
"function",
"createListElement",
"(",
"core_kernel_classes_Class",
"$",
"listClass",
",",
"$",
"label",
"=",
"''",
")",
"{",
"$",
"returnValue",
"=",
"null",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"listClass",
")",
")",
"{",
"$",
"level",
"=... | add a new element to a list
@access public
@author Joel Bout, <joel.bout@tudor.lu>
@param Class listClass
@param string label
@return core_kernel_classes_Resource | [
"add",
"a",
"new",
"element",
"to",
"a",
"list"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/class.ListService.php#L264-L281 |
oat-sa/tao-core | helpers/form/elements/xhtml/class.Checkbox.php | tao_helpers_form_elements_xhtml_Checkbox.feed | public function feed()
{
$expression = "/^" . preg_quote($this->name, "/") . "(.)*[0-9]+$/";
$this->setValues(array());
foreach ($_POST as $key => $value) {
if (preg_match($expression, $key)) {
$this->addValue(tao_helpers_Uri::decode($value));
}
}
} | php | public function feed()
{
$expression = "/^" . preg_quote($this->name, "/") . "(.)*[0-9]+$/";
$this->setValues(array());
foreach ($_POST as $key => $value) {
if (preg_match($expression, $key)) {
$this->addValue(tao_helpers_Uri::decode($value));
}
}
} | [
"public",
"function",
"feed",
"(",
")",
"{",
"$",
"expression",
"=",
"\"/^\"",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"name",
",",
"\"/\"",
")",
".",
"\"(.)*[0-9]+$/\"",
";",
"$",
"this",
"->",
"setValues",
"(",
"array",
"(",
")",
")",
";",
"fore... | 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.Checkbox.php#L40-L49 |
oat-sa/tao-core | helpers/form/elements/xhtml/class.Checkbox.php | tao_helpers_form_elements_xhtml_Checkbox.render | public function render()
{
$returnValue = $this->renderLabel();
$checkAll = false;
if (isset($this->attributes['checkAll'])) {
$checkAll = (bool) $this->attributes['checkAll'];
unset($this->attributes['checkAll']);
}
$i = 0;
$checked = 0;
$returnValue .= '<div class="form_radlst form_checklst plain">';
$readOnlyOptions = $this->getReadOnly();
foreach ($this->options as $optionId => $optionLabel) {
$readOnly = isset($readOnlyOptions[$optionId]);
if($readOnly){
$returnValue .= '<div class="grid-row readonly">';
}else{
$returnValue .= '<div class="grid-row">';
}
$returnValue .= '<div class="col-1">';
$returnValue .= "<input type='checkbox' value='{$optionId}' name='{$this->name}_{$i}' id='{$this->name}_{$i}' ";
$returnValue .= $this->renderAttributes();
if ($readOnly) {
$returnValue .= "disabled='disabled' readonly='readonly' ";
}
if (in_array($optionId, $this->values)) {
$returnValue .= " checked='checked' ";
$checked ++;
}
$returnValue .= ' />';
$returnValue .= '</div><div class="col-10">';
$returnValue .= "<label class='elt_desc' for='{$this->name}_{$i}'>" . _dh($optionLabel) . "</label>";
$returnValue .= '</div><div class="col-1">';
if ($readOnly) {
$readOnlyReason = $readOnlyOptions[$optionId];
if(!empty($readOnlyReason)){
$returnValue .= '<span class="tooltip-trigger icon-warning" data-tooltip="~ .tooltip-content" data-tooltip-theme="info"></span><div class="tooltip-content">'._dh($readOnlyReason).'</div>';
}
}
$returnValue .= '</div></div>';
$i ++;
}
$returnValue .= "</div>";
// add a small link
if ($checkAll) {
if ($checked == (count($this->options) - count($readOnlyOptions))) {
$returnValue .= "<span class='checker-container'><a id='{$this->name}_checker' class='box-checker box-checker-uncheck' href='#'>" . __('Uncheck All') . "</a></span>";
} else {
$returnValue .= "<span class='checker-container'><a id='{$this->name}_checker' class='box-checker' href='#'>" . __('Check All') . "</a></span>";
}
}
return (string) $returnValue;
} | php | public function render()
{
$returnValue = $this->renderLabel();
$checkAll = false;
if (isset($this->attributes['checkAll'])) {
$checkAll = (bool) $this->attributes['checkAll'];
unset($this->attributes['checkAll']);
}
$i = 0;
$checked = 0;
$returnValue .= '<div class="form_radlst form_checklst plain">';
$readOnlyOptions = $this->getReadOnly();
foreach ($this->options as $optionId => $optionLabel) {
$readOnly = isset($readOnlyOptions[$optionId]);
if($readOnly){
$returnValue .= '<div class="grid-row readonly">';
}else{
$returnValue .= '<div class="grid-row">';
}
$returnValue .= '<div class="col-1">';
$returnValue .= "<input type='checkbox' value='{$optionId}' name='{$this->name}_{$i}' id='{$this->name}_{$i}' ";
$returnValue .= $this->renderAttributes();
if ($readOnly) {
$returnValue .= "disabled='disabled' readonly='readonly' ";
}
if (in_array($optionId, $this->values)) {
$returnValue .= " checked='checked' ";
$checked ++;
}
$returnValue .= ' />';
$returnValue .= '</div><div class="col-10">';
$returnValue .= "<label class='elt_desc' for='{$this->name}_{$i}'>" . _dh($optionLabel) . "</label>";
$returnValue .= '</div><div class="col-1">';
if ($readOnly) {
$readOnlyReason = $readOnlyOptions[$optionId];
if(!empty($readOnlyReason)){
$returnValue .= '<span class="tooltip-trigger icon-warning" data-tooltip="~ .tooltip-content" data-tooltip-theme="info"></span><div class="tooltip-content">'._dh($readOnlyReason).'</div>';
}
}
$returnValue .= '</div></div>';
$i ++;
}
$returnValue .= "</div>";
// add a small link
if ($checkAll) {
if ($checked == (count($this->options) - count($readOnlyOptions))) {
$returnValue .= "<span class='checker-container'><a id='{$this->name}_checker' class='box-checker box-checker-uncheck' href='#'>" . __('Uncheck All') . "</a></span>";
} else {
$returnValue .= "<span class='checker-container'><a id='{$this->name}_checker' class='box-checker' href='#'>" . __('Check All') . "</a></span>";
}
}
return (string) $returnValue;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"returnValue",
"=",
"$",
"this",
"->",
"renderLabel",
"(",
")",
";",
"$",
"checkAll",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'checkAll'",
"]",
")",
")",
... | 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.Checkbox.php#L58-L116 |
oat-sa/tao-core | models/classes/cliArgument/ArgumentLoader.php | ArgumentLoader.getArguments | protected function getArguments()
{
$arguments = [];
foreach ($this->getOptionArguments() as $argument) {
if ($argument instanceof Argument) {
$arguments[] = $this->getServiceManager()->propagate($argument);
}
}
return $arguments;
} | php | protected function getArguments()
{
$arguments = [];
foreach ($this->getOptionArguments() as $argument) {
if ($argument instanceof Argument) {
$arguments[] = $this->getServiceManager()->propagate($argument);
}
}
return $arguments;
} | [
"protected",
"function",
"getArguments",
"(",
")",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getOptionArguments",
"(",
")",
"as",
"$",
"argument",
")",
"{",
"if",
"(",
"$",
"argument",
"instanceof",
"Argument",
")",
... | Get all grouped arguments from options
@return Argument[] | [
"Get",
"all",
"grouped",
"arguments",
"from",
"options"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/cliArgument/ArgumentLoader.php#L40-L49 |
oat-sa/tao-core | actions/class.CommonRestModule.php | tao_actions_CommonRestModule.index | public function index()
{
try {
$uri = null;
if ($this->hasRequestParameter("uri")) {
$uri = $this->getRequestParameter("uri");
if (!common_Utils::isUri($uri)) {
throw new common_exception_InvalidArgumentType();
}
}
switch ($this->getRequestMethod()) {
case "GET":
$response = $this->get($uri);
break;
case "PUT":
$response = $this->put($uri);
break;
case "POST":
$response = $this->post();
break;
case "DELETE":
$response = $this->delete($uri);
break;
default:
throw new common_exception_BadRequest($this->getRequestURI());
}
$this->returnSuccess($response);
} catch (Exception $e) {
if ($e instanceof \common_exception_ValidationFailed &&
$alias = $this->reverseSearchAlias($e->getField())
) {
$e = new \common_exception_ValidationFailed($alias, null, $e->getCode());
}
$this->returnFailure($e);
}
} | php | public function index()
{
try {
$uri = null;
if ($this->hasRequestParameter("uri")) {
$uri = $this->getRequestParameter("uri");
if (!common_Utils::isUri($uri)) {
throw new common_exception_InvalidArgumentType();
}
}
switch ($this->getRequestMethod()) {
case "GET":
$response = $this->get($uri);
break;
case "PUT":
$response = $this->put($uri);
break;
case "POST":
$response = $this->post();
break;
case "DELETE":
$response = $this->delete($uri);
break;
default:
throw new common_exception_BadRequest($this->getRequestURI());
}
$this->returnSuccess($response);
} catch (Exception $e) {
if ($e instanceof \common_exception_ValidationFailed &&
$alias = $this->reverseSearchAlias($e->getField())
) {
$e = new \common_exception_ValidationFailed($alias, null, $e->getCode());
}
$this->returnFailure($e);
}
} | [
"public",
"function",
"index",
"(",
")",
"{",
"try",
"{",
"$",
"uri",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"hasRequestParameter",
"(",
"\"uri\"",
")",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"getRequestParameter",
"(",
"\"uri\"",
")"... | Entry point of API
If uri parameters is provided, it must be a valid uri
Depending on HTTP method, request is routed to crud function | [
"Entry",
"point",
"of",
"API",
"If",
"uri",
"parameters",
"is",
"provided",
"it",
"must",
"be",
"a",
"valid",
"uri",
"Depending",
"on",
"HTTP",
"method",
"request",
"is",
"routed",
"to",
"crud",
"function"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.CommonRestModule.php#L36-L75 |
oat-sa/tao-core | actions/class.CommonRestModule.php | tao_actions_CommonRestModule.get | protected function get($uri=null)
{
if (!is_null($uri)) {
if (!($this->getCrudService()->isInScope($uri))) {
throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class");
}
return $this->getCrudService()->get($uri);
} else {
return $this->getCrudService()->getAll();
}
} | php | protected function get($uri=null)
{
if (!is_null($uri)) {
if (!($this->getCrudService()->isInScope($uri))) {
throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class");
}
return $this->getCrudService()->get($uri);
} else {
return $this->getCrudService()->getAll();
}
} | [
"protected",
"function",
"get",
"(",
"$",
"uri",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"uri",
")",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"getCrudService",
"(",
")",
"->",
"isInScope",
"(",
"$",
"uri",
")",
")",... | Method to wrap fetching to service:
- get() if uri is not null
- getAll() if uri is null
@param null $uri
@return mixed
@throws common_exception_InvalidArgumentType
@throws common_exception_PreConditionFailure | [
"Method",
"to",
"wrap",
"fetching",
"to",
"service",
":",
"-",
"get",
"()",
"if",
"uri",
"is",
"not",
"null",
"-",
"getAll",
"()",
"if",
"uri",
"is",
"null"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.CommonRestModule.php#L101-L111 |
oat-sa/tao-core | actions/class.CommonRestModule.php | tao_actions_CommonRestModule.delete | protected function delete($uri=null)
{
if (is_null($uri)) {
//$data = $this->service->deleteAll();
throw new common_exception_BadRequest('Delete method requires an uri parameter');
}
if (!($this->getCrudService()->isInScope($uri))) {
throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class");
}
return $this->getCrudService()->delete($uri);
} | php | protected function delete($uri=null)
{
if (is_null($uri)) {
//$data = $this->service->deleteAll();
throw new common_exception_BadRequest('Delete method requires an uri parameter');
}
if (!($this->getCrudService()->isInScope($uri))) {
throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class");
}
return $this->getCrudService()->delete($uri);
} | [
"protected",
"function",
"delete",
"(",
"$",
"uri",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"uri",
")",
")",
"{",
"//$data = $this->service->deleteAll();",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'Delete method requires an uri parameter'",
... | Method to wrap deleting to service if uri is not null
@param null $uri
@return mixed
@throws common_exception_BadRequest
@throws common_exception_InvalidArgumentType
@throws common_exception_PreConditionFailure | [
"Method",
"to",
"wrap",
"deleting",
"to",
"service",
"if",
"uri",
"is",
"not",
"null"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.CommonRestModule.php#L122-L132 |
oat-sa/tao-core | actions/class.CommonRestModule.php | tao_actions_CommonRestModule.post | protected function post()
{
$parameters = $this->getParameters();
try {
return $this->getCrudService()->createFromArray($parameters);
}
/** @noinspection PhpRedundantCatchClauseInspection */
catch (common_exception_PreConditionFailure $e) {
throw new common_exception_RestApi($e->getMessage());
}
} | php | protected function post()
{
$parameters = $this->getParameters();
try {
return $this->getCrudService()->createFromArray($parameters);
}
/** @noinspection PhpRedundantCatchClauseInspection */
catch (common_exception_PreConditionFailure $e) {
throw new common_exception_RestApi($e->getMessage());
}
} | [
"protected",
"function",
"post",
"(",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"getParameters",
"(",
")",
";",
"try",
"{",
"return",
"$",
"this",
"->",
"getCrudService",
"(",
")",
"->",
"createFromArray",
"(",
"$",
"parameters",
")",
";",
"... | Method to wrap creating to service
@OA\Schema(
schema="tao.CommonRestModule.CreatedResource",
description="Created resource data",
@OA\Property(
property="uriResource",
type="string",
example="http://sample/first.rdf#i1536680377163171"
),
@OA\Property(
property="label",
type="string"
),
@OA\Property(
property="comment",
type="string"
)
)
@OA\Schema(
schema="tao.CommonRestModule.CreatedResourceResponse",
description="Created resource data",
allOf={
@OA\Schema(ref="#/components/schemas/tao.RestTrait.BaseResponse")
},
@OA\Property(
property="data",
ref="#/components/schemas/tao.CommonRestModule.CreatedResource"
)
)
@return mixed
@throws common_Exception
@throws common_exception_RestApi | [
"Method",
"to",
"wrap",
"creating",
"to",
"service"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.CommonRestModule.php#L170-L180 |
oat-sa/tao-core | actions/class.CommonRestModule.php | tao_actions_CommonRestModule.put | protected function put($uri)
{
if (is_null($uri)) {
throw new common_exception_BadRequest('Update method requires an uri parameter');
}
if (!($this->getCrudService()->isInScope($uri))) {
throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class");
}
$parameters = $this->getParameters();
try {
return $this->getCrudService()->update($uri, $parameters);
} catch (common_exception_PreConditionFailure $e) {
throw new common_exception_RestApi($e->getMessage());
}
} | php | protected function put($uri)
{
if (is_null($uri)) {
throw new common_exception_BadRequest('Update method requires an uri parameter');
}
if (!($this->getCrudService()->isInScope($uri))) {
throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class");
}
$parameters = $this->getParameters();
try {
return $this->getCrudService()->update($uri, $parameters);
} catch (common_exception_PreConditionFailure $e) {
throw new common_exception_RestApi($e->getMessage());
}
} | [
"protected",
"function",
"put",
"(",
"$",
"uri",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"uri",
")",
")",
"{",
"throw",
"new",
"common_exception_BadRequest",
"(",
"'Update method requires an uri parameter'",
")",
";",
"}",
"if",
"(",
"!",
"(",
"$",
"this... | Method to wrap to updating to service if uri is not null
@param $uri
@return mixed
@throws common_Exception
@throws common_exception_BadRequest
@throws common_exception_InvalidArgumentType
@throws common_exception_NoContent
@throws common_exception_PreConditionFailure
@throws common_exception_RestApi | [
"Method",
"to",
"wrap",
"to",
"updating",
"to",
"service",
"if",
"uri",
"is",
"not",
"null"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.CommonRestModule.php#L194-L208 |
oat-sa/tao-core | actions/class.CommonRestModule.php | tao_actions_CommonRestModule.getParameters | protected function getParameters()
{
$effectiveParameters = [];
$missedAliases = [];
foreach ($this->getParametersAliases() as $checkParameterShort => $checkParameterUri) {
if ($this->hasRequestParameter($checkParameterUri)) {
$effectiveParameters[$checkParameterUri] = $this->getRequestParameter($checkParameterUri);
}
else if ($this->hasRequestParameter($checkParameterShort)) {
$effectiveParameters[$checkParameterUri] = $this->getRequestParameter($checkParameterShort);
}
else if ($this->isRequiredParameter($checkParameterShort)) {
$missedAliases[] = $checkParameterShort;
}
}
if (count($missedAliases) > 0) {
throw new \common_exception_RestApi(
'Missed required parameters: ' . implode(', ', $missedAliases));
}
return $effectiveParameters;
} | php | protected function getParameters()
{
$effectiveParameters = [];
$missedAliases = [];
foreach ($this->getParametersAliases() as $checkParameterShort => $checkParameterUri) {
if ($this->hasRequestParameter($checkParameterUri)) {
$effectiveParameters[$checkParameterUri] = $this->getRequestParameter($checkParameterUri);
}
else if ($this->hasRequestParameter($checkParameterShort)) {
$effectiveParameters[$checkParameterUri] = $this->getRequestParameter($checkParameterShort);
}
else if ($this->isRequiredParameter($checkParameterShort)) {
$missedAliases[] = $checkParameterShort;
}
}
if (count($missedAliases) > 0) {
throw new \common_exception_RestApi(
'Missed required parameters: ' . implode(', ', $missedAliases));
}
return $effectiveParameters;
} | [
"protected",
"function",
"getParameters",
"(",
")",
"{",
"$",
"effectiveParameters",
"=",
"[",
"]",
";",
"$",
"missedAliases",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getParametersAliases",
"(",
")",
"as",
"$",
"checkParameterShort",
"=>",
... | Returns all parameters that are URIs or Aliased with values
@return array
@throws \common_exception_RestApi If a mandatory parameter is not found | [
"Returns",
"all",
"parameters",
"that",
"are",
"URIs",
"or",
"Aliased",
"with",
"values"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.CommonRestModule.php#L216-L239 |
oat-sa/tao-core | actions/class.CommonRestModule.php | tao_actions_CommonRestModule.isRequiredParameter | protected function isRequiredParameter($parameter)
{
$method = $this->getRequestMethod();
$requirements = $this->getParametersRequirements();
$requirements = array_change_key_case($requirements, CASE_LOWER);
$method = strtolower($method);
if (!isset($requirements[$method])) {
return false;
}
if (in_array($parameter,$requirements[$method])) {
return true;
}
$isRequired = false;
//The requirements may have been declared using URIs, look up for the URI
$aliases = $this->getParametersAliases();
if (isset($aliases[$parameter])) {
$isRequired = in_array($aliases[$parameter],$requirements[$method]);
}
return $isRequired;
} | php | protected function isRequiredParameter($parameter)
{
$method = $this->getRequestMethod();
$requirements = $this->getParametersRequirements();
$requirements = array_change_key_case($requirements, CASE_LOWER);
$method = strtolower($method);
if (!isset($requirements[$method])) {
return false;
}
if (in_array($parameter,$requirements[$method])) {
return true;
}
$isRequired = false;
//The requirements may have been declared using URIs, look up for the URI
$aliases = $this->getParametersAliases();
if (isset($aliases[$parameter])) {
$isRequired = in_array($aliases[$parameter],$requirements[$method]);
}
return $isRequired;
} | [
"protected",
"function",
"isRequiredParameter",
"(",
"$",
"parameter",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"getRequestMethod",
"(",
")",
";",
"$",
"requirements",
"=",
"$",
"this",
"->",
"getParametersRequirements",
"(",
")",
";",
"$",
"requirem... | Defines if the parameter is mandatory according:
- getParametersRequirements array
- HTTP method
@param $parameter, The alias name or uri of a parameter
@return bool | [
"Defines",
"if",
"the",
"parameter",
"is",
"mandatory",
"according",
":",
"-",
"getParametersRequirements",
"array",
"-",
"HTTP",
"method"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.CommonRestModule.php#L286-L310 |
oat-sa/tao-core | helpers/class.Context.php | tao_helpers_Context.load | public static function load($mode)
{
if (!is_string($mode)){
throw new InvalidArgumentException('Try to load an irregular mode in the context. The mode must be a string, ' . gettype($mode) . ' given.');
}
else if (empty($mode)){
throw new InvalidArgumentException('Cannot load an empty mode in the context.');
}
if(!in_array($mode, self::$current)){
self::$current[] = $mode;
}
} | php | public static function load($mode)
{
if (!is_string($mode)){
throw new InvalidArgumentException('Try to load an irregular mode in the context. The mode must be a string, ' . gettype($mode) . ' given.');
}
else if (empty($mode)){
throw new InvalidArgumentException('Cannot load an empty mode in the context.');
}
if(!in_array($mode, self::$current)){
self::$current[] = $mode;
}
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"mode",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"mode",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Try to load an irregular mode in the context. The mode must be a string, '",
".",
"ge... | load a new current mode
@author Cedric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string mode
@throws InvalidArgumentException If the mode variable is not a string or is empty. | [
"load",
"a",
"new",
"current",
"mode"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Context.php#L49-L61 |
oat-sa/tao-core | helpers/class.Context.php | tao_helpers_Context.check | public static function check($mode)
{
$returnValue = (bool) false;
if (!is_string($mode)){
throw new InvalidArgumentException('Try to check an irregular mode. The mode must be a string, ' . gettype($mode) . ' given.');
}
else if (empty($mode)){
throw new InvalidArgumentException('Cannot check an empty mode.');
}
$returnValue = in_array($mode, self::$current);
return (bool) $returnValue;
} | php | public static function check($mode)
{
$returnValue = (bool) false;
if (!is_string($mode)){
throw new InvalidArgumentException('Try to check an irregular mode. The mode must be a string, ' . gettype($mode) . ' given.');
}
else if (empty($mode)){
throw new InvalidArgumentException('Cannot check an empty mode.');
}
$returnValue = in_array($mode, self::$current);
return (bool) $returnValue;
} | [
"public",
"static",
"function",
"check",
"(",
"$",
"mode",
")",
"{",
"$",
"returnValue",
"=",
"(",
"bool",
")",
"false",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"mode",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Try to check an... | check if the mode in parameter is loaded in the context.
@author Cedric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string mode The mode you want to check it is loaded or not.
@return boolean
@throws InvalidArgumentException If the mode variable is not a string or is empty. | [
"check",
"if",
"the",
"mode",
"in",
"parameter",
"is",
"loaded",
"in",
"the",
"context",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Context.php#L71-L85 |
oat-sa/tao-core | helpers/class.Context.php | tao_helpers_Context.unload | public static function unload($mode)
{
if (!is_string($mode)){
throw new InvalidArgumentException('Try to unload an irregular mode in the context. The mode must be a string, ' . gettype($mode) . ' given.');
}
else if (empty($mode)){
throw new InvalidArgumentException('Cannot unload an empty mode in the context.');
}
if(in_array($mode, self::$current)){
$index = array_search ($mode, self::$current);
if ($index !== false){
unset (self::$current[$index]);
}
}
} | php | public static function unload($mode)
{
if (!is_string($mode)){
throw new InvalidArgumentException('Try to unload an irregular mode in the context. The mode must be a string, ' . gettype($mode) . ' given.');
}
else if (empty($mode)){
throw new InvalidArgumentException('Cannot unload an empty mode in the context.');
}
if(in_array($mode, self::$current)){
$index = array_search ($mode, self::$current);
if ($index !== false){
unset (self::$current[$index]);
}
}
} | [
"public",
"static",
"function",
"unload",
"(",
"$",
"mode",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"mode",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Try to unload an irregular mode in the context. The mode must be a string, '",
".",
... | Unload a specific mode.
@author Cedric Alfonsi, <cedric.alfonsi@tudor.lu>
@param string mode
@throws InvalidArgumentException If the mode variable has not the right type (string) or is empty. | [
"Unload",
"a",
"specific",
"mode",
"."
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/class.Context.php#L104-L120 |
oat-sa/tao-core | helpers/UserHelper.php | UserHelper.getUser | public static function getUser($userId)
{
/** @var \tao_models_classes_UserService $userService */
$userService = ServiceManager::getServiceManager()->get(\tao_models_classes_UserService::SERVICE_ID);
$user = $userService->getUserById($userId);
return $user;
} | php | public static function getUser($userId)
{
/** @var \tao_models_classes_UserService $userService */
$userService = ServiceManager::getServiceManager()->get(\tao_models_classes_UserService::SERVICE_ID);
$user = $userService->getUserById($userId);
return $user;
} | [
"public",
"static",
"function",
"getUser",
"(",
"$",
"userId",
")",
"{",
"/** @var \\tao_models_classes_UserService $userService */",
"$",
"userService",
"=",
"ServiceManager",
"::",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"\\",
"tao_models_classes_UserService",
... | Gets a user from a URI
@todo Make a stronger helper which take care of provider (LDAP, OAUTH, etc.)
@param string $userId
@return User | [
"Gets",
"a",
"user",
"from",
"a",
"URI"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/UserHelper.php#L64-L70 |
oat-sa/tao-core | helpers/UserHelper.php | UserHelper.getUserStringProp | public static function getUserStringProp(User $user, $property)
{
$value = $user->getPropertyValues($property);
return empty($value) ? '' : current($value);
} | php | public static function getUserStringProp(User $user, $property)
{
$value = $user->getPropertyValues($property);
return empty($value) ? '' : current($value);
} | [
"public",
"static",
"function",
"getUserStringProp",
"(",
"User",
"$",
"user",
",",
"$",
"property",
")",
"{",
"$",
"value",
"=",
"$",
"user",
"->",
"getPropertyValues",
"(",
"$",
"property",
")",
";",
"return",
"empty",
"(",
"$",
"value",
")",
"?",
"'... | Gets the value of a string property from a user
@param User $user
@param string $property
@return string | [
"Gets",
"the",
"value",
"of",
"a",
"string",
"property",
"from",
"a",
"user"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/UserHelper.php#L78-L82 |
oat-sa/tao-core | helpers/UserHelper.php | UserHelper.getUserFirstName | public static function getUserFirstName(User $user, $defaultToLabel = false)
{
$firstName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_FIRSTNAME);
if (empty($firstName) && $defaultToLabel) {
$firstName = self::getUserLabel($user);
}
return $firstName;
} | php | public static function getUserFirstName(User $user, $defaultToLabel = false)
{
$firstName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_FIRSTNAME);
if (empty($firstName) && $defaultToLabel) {
$firstName = self::getUserLabel($user);
}
return $firstName;
} | [
"public",
"static",
"function",
"getUserFirstName",
"(",
"User",
"$",
"user",
",",
"$",
"defaultToLabel",
"=",
"false",
")",
"{",
"$",
"firstName",
"=",
"self",
"::",
"getUserStringProp",
"(",
"$",
"user",
",",
"GenerisRdf",
"::",
"PROPERTY_USER_FIRSTNAME",
")... | Gets the user's first name
@param User $user
@param bool $defaultToLabel
@return string | [
"Gets",
"the",
"user",
"s",
"first",
"name"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/UserHelper.php#L120-L129 |
oat-sa/tao-core | helpers/UserHelper.php | UserHelper.getUserLastName | public static function getUserLastName(User $user, $defaultToLabel = false)
{
$lastName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_LASTNAME);
if (empty($lastName) && $defaultToLabel) {
$lastName = self::getUserLabel($user);
}
return $lastName;
} | php | public static function getUserLastName(User $user, $defaultToLabel = false)
{
$lastName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_LASTNAME);
if (empty($lastName) && $defaultToLabel) {
$lastName = self::getUserLabel($user);
}
return $lastName;
} | [
"public",
"static",
"function",
"getUserLastName",
"(",
"User",
"$",
"user",
",",
"$",
"defaultToLabel",
"=",
"false",
")",
"{",
"$",
"lastName",
"=",
"self",
"::",
"getUserStringProp",
"(",
"$",
"user",
",",
"GenerisRdf",
"::",
"PROPERTY_USER_LASTNAME",
")",
... | Gets the user's last name
@param User $user
@param bool $defaultToLabel
@return string | [
"Gets",
"the",
"user",
"s",
"last",
"name"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/UserHelper.php#L137-L146 |
oat-sa/tao-core | helpers/UserHelper.php | UserHelper.getUserName | public static function getUserName(User $user, $defaultToLabel = false)
{
$firstName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_FIRSTNAME);
$lastName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_LASTNAME);
$userName = trim($firstName . ' ' . $lastName);
if (empty($userName) && $defaultToLabel) {
$userName = self::getUserLabel($user);
}
return $userName;
} | php | public static function getUserName(User $user, $defaultToLabel = false)
{
$firstName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_FIRSTNAME);
$lastName = self::getUserStringProp($user, GenerisRdf::PROPERTY_USER_LASTNAME);
$userName = trim($firstName . ' ' . $lastName);
if (empty($userName) && $defaultToLabel) {
$userName = self::getUserLabel($user);
}
return $userName;
} | [
"public",
"static",
"function",
"getUserName",
"(",
"User",
"$",
"user",
",",
"$",
"defaultToLabel",
"=",
"false",
")",
"{",
"$",
"firstName",
"=",
"self",
"::",
"getUserStringProp",
"(",
"$",
"user",
",",
"GenerisRdf",
"::",
"PROPERTY_USER_FIRSTNAME",
")",
... | Gets the full user name
@param User $user
@param bool $defaultToLabel
@return string | [
"Gets",
"the",
"full",
"user",
"name"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/UserHelper.php#L154-L166 |
oat-sa/tao-core | actions/class.Security.php | tao_actions_Security.index | public function index()
{
$this->setView('security/view.tpl');
$formFactory = new tao_actions_form_CspHeader(['serviceLocator' => $this->getServiceLocator()]);
$cspHeaderForm = $formFactory->getForm();
if ($cspHeaderForm->isSubmited() && $cspHeaderForm->isValid()) {
$formFactory->saveSettings();
$this->setData('cspHeaderFormSuccess', __('CSP Header settings were saved successfully!'));
}
$this->setData('formTitle', __('Edit sources that can embed this platform in an iFrame'));
$this->setData('cspHeaderForm', $cspHeaderForm->render());
} | php | public function index()
{
$this->setView('security/view.tpl');
$formFactory = new tao_actions_form_CspHeader(['serviceLocator' => $this->getServiceLocator()]);
$cspHeaderForm = $formFactory->getForm();
if ($cspHeaderForm->isSubmited() && $cspHeaderForm->isValid()) {
$formFactory->saveSettings();
$this->setData('cspHeaderFormSuccess', __('CSP Header settings were saved successfully!'));
}
$this->setData('formTitle', __('Edit sources that can embed this platform in an iFrame'));
$this->setData('cspHeaderForm', $cspHeaderForm->render());
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"this",
"->",
"setView",
"(",
"'security/view.tpl'",
")",
";",
"$",
"formFactory",
"=",
"new",
"tao_actions_form_CspHeader",
"(",
"[",
"'serviceLocator'",
"=>",
"$",
"this",
"->",
"getServiceLocator",
"(",
")"... | Index page | [
"Index",
"page"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/class.Security.php#L31-L46 |
oat-sa/tao-core | helpers/form/elements/xhtml/class.Viewablehiddenbox.php | tao_helpers_form_elements_xhtml_Viewablehiddenbox.render | public function render()
{
$uid = helpers_Random::generateString(24);
$this->addClass('viewable-hiddenbox-input');
$this->addAttribute('data-identifier', $uid);
$value = _dh($this->value);
$html = <<<HTML
<span class="viewable-hiddenbox">
{$this->renderLabel()}
<input type='password' name='{$this->name}' id='{$this->name}' {$this->renderAttributes()} value='{$value}'/>
<span class="viewable-hiddenbox-toggle" data-identifier="{$uid}"></span>
</span>
HTML;
$script = <<<SCRIPT
<script type="text/javascript">
(function() {
var input = document.querySelector('input[data-identifier="$uid"]'),
toggle = document.querySelector('.viewable-hiddenbox-toggle[data-identifier="$uid"]'),
iconView = document.createElement('span'),
iconHide = document.createElement('span');
var show = function() {
if (iconView.parentElement) {
toggle.removeChild(iconView);
}
if (!iconHide.parentElement) {
toggle.appendChild(iconHide);
}
input.type = 'text';
input.autocomplete = 'off';
window.addEventListener('mousedown', autoHide); // make sure always submit the form with an password input
input.focus();
};
var hide = function() {
if (!iconView.parentElement) {
toggle.appendChild(iconView);
}
if (iconHide.parentElement) {
toggle.removeChild(iconHide);
}
input.type = 'password';
input.autocomplete = 'on';
window.removeEventListener('mousedown', autoHide);
};
var autoHide = function(event) {
if (!event.target.isSameNode(input) && !event.target.isSameNode(iconHide) && !event.target.isSameNode(toggle)) {
hide();
}
};
iconView.classList.add('icon-preview');
iconHide.classList.add('icon-eye-slash');
hide();
toggle.addEventListener('click', function() {
if (input.type === 'password') {
show();
} else {
hide();
}
});
})();
</script>
SCRIPT;
return (string) ($html . $script);
} | php | public function render()
{
$uid = helpers_Random::generateString(24);
$this->addClass('viewable-hiddenbox-input');
$this->addAttribute('data-identifier', $uid);
$value = _dh($this->value);
$html = <<<HTML
<span class="viewable-hiddenbox">
{$this->renderLabel()}
<input type='password' name='{$this->name}' id='{$this->name}' {$this->renderAttributes()} value='{$value}'/>
<span class="viewable-hiddenbox-toggle" data-identifier="{$uid}"></span>
</span>
HTML;
$script = <<<SCRIPT
<script type="text/javascript">
(function() {
var input = document.querySelector('input[data-identifier="$uid"]'),
toggle = document.querySelector('.viewable-hiddenbox-toggle[data-identifier="$uid"]'),
iconView = document.createElement('span'),
iconHide = document.createElement('span');
var show = function() {
if (iconView.parentElement) {
toggle.removeChild(iconView);
}
if (!iconHide.parentElement) {
toggle.appendChild(iconHide);
}
input.type = 'text';
input.autocomplete = 'off';
window.addEventListener('mousedown', autoHide); // make sure always submit the form with an password input
input.focus();
};
var hide = function() {
if (!iconView.parentElement) {
toggle.appendChild(iconView);
}
if (iconHide.parentElement) {
toggle.removeChild(iconHide);
}
input.type = 'password';
input.autocomplete = 'on';
window.removeEventListener('mousedown', autoHide);
};
var autoHide = function(event) {
if (!event.target.isSameNode(input) && !event.target.isSameNode(iconHide) && !event.target.isSameNode(toggle)) {
hide();
}
};
iconView.classList.add('icon-preview');
iconHide.classList.add('icon-eye-slash');
hide();
toggle.addEventListener('click', function() {
if (input.type === 'password') {
show();
} else {
hide();
}
});
})();
</script>
SCRIPT;
return (string) ($html . $script);
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"uid",
"=",
"helpers_Random",
"::",
"generateString",
"(",
"24",
")",
";",
"$",
"this",
"->",
"addClass",
"(",
"'viewable-hiddenbox-input'",
")",
";",
"$",
"this",
"->",
"addAttribute",
"(",
"'data-identifi... | Short description of method render
@access public
@author Christophe Noël <christophe@taotesting.com>
@return string | [
"Short",
"description",
"of",
"method",
"render"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/helpers/form/elements/xhtml/class.Viewablehiddenbox.php#L41-L114 |
oat-sa/tao-core | models/classes/metadata/writer/ontologyWriter/PropertyWriter.php | PropertyWriter.validate | public function validate($data)
{
try {
/** @var \tao_helpers_form_Validator[] $validators */
$validators = ValidationRuleRegistry::getRegistry()->getValidators($this->getPropertyToWrite());
} catch (\common_exception_NotFound $e) {
throw new MetadataWriterException($e->getMessage());
}
$validated = true;
foreach ($validators as $validator) {
if (! $validator->evaluate($data)) {
$validated = false;
\common_Logger::d('Unable to validate value for property "' . $this->getPropertyToWrite()->getUri() . '"' .
' against validator "' . $validator->getName(). '" : "' . $validator->getMessage() . '".');
}
}
return $validated;
} | php | public function validate($data)
{
try {
/** @var \tao_helpers_form_Validator[] $validators */
$validators = ValidationRuleRegistry::getRegistry()->getValidators($this->getPropertyToWrite());
} catch (\common_exception_NotFound $e) {
throw new MetadataWriterException($e->getMessage());
}
$validated = true;
foreach ($validators as $validator) {
if (! $validator->evaluate($data)) {
$validated = false;
\common_Logger::d('Unable to validate value for property "' . $this->getPropertyToWrite()->getUri() . '"' .
' against validator "' . $validator->getName(). '" : "' . $validator->getMessage() . '".');
}
}
return $validated;
} | [
"public",
"function",
"validate",
"(",
"$",
"data",
")",
"{",
"try",
"{",
"/** @var \\tao_helpers_form_Validator[] $validators */",
"$",
"validators",
"=",
"ValidationRuleRegistry",
"::",
"getRegistry",
"(",
")",
"->",
"getValidators",
"(",
"$",
"this",
"->",
"getPr... | Validate if value is writable by current writer
Validation is handle by property validators
@param $data
@return bool
@throws MetadataWriterException | [
"Validate",
"if",
"value",
"is",
"writable",
"by",
"current",
"writer",
"Validation",
"is",
"handle",
"by",
"property",
"validators"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/metadata/writer/ontologyWriter/PropertyWriter.php#L71-L89 |
oat-sa/tao-core | models/classes/metadata/writer/ontologyWriter/PropertyWriter.php | PropertyWriter.write | public function write(\core_kernel_classes_Resource $resource, $data, $dryrun = false)
{
$propertyValue = $this->format($data);
if ($this->validate($propertyValue)) {
if (! $dryrun) {
if (! $resource->editPropertyValues($this->getPropertyToWrite(), $propertyValue)) {
throw new MetadataWriterException(
'A problem has occurred during writing property "' . $this->getPropertyToWrite()->getUri() . '".'
);
}
}
\common_Logger::d('Valid property "'. $this->getPropertyToWrite()->getUri() .'" ' .
'to add to resource "' . $resource->getUri() . '" : ' . $propertyValue);
return true;
}
throw new MetadataWriterException(
'Writer "' . __CLASS__ . '" cannot validate value for property "' . $this->getPropertyToWrite()->getUri() . '".'
);
} | php | public function write(\core_kernel_classes_Resource $resource, $data, $dryrun = false)
{
$propertyValue = $this->format($data);
if ($this->validate($propertyValue)) {
if (! $dryrun) {
if (! $resource->editPropertyValues($this->getPropertyToWrite(), $propertyValue)) {
throw new MetadataWriterException(
'A problem has occurred during writing property "' . $this->getPropertyToWrite()->getUri() . '".'
);
}
}
\common_Logger::d('Valid property "'. $this->getPropertyToWrite()->getUri() .'" ' .
'to add to resource "' . $resource->getUri() . '" : ' . $propertyValue);
return true;
}
throw new MetadataWriterException(
'Writer "' . __CLASS__ . '" cannot validate value for property "' . $this->getPropertyToWrite()->getUri() . '".'
);
} | [
"public",
"function",
"write",
"(",
"\\",
"core_kernel_classes_Resource",
"$",
"resource",
",",
"$",
"data",
",",
"$",
"dryrun",
"=",
"false",
")",
"{",
"$",
"propertyValue",
"=",
"$",
"this",
"->",
"format",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",... | Write a value to a $resource
@param \core_kernel_classes_Resource $resource
@param $data
@param bool $dryrun
@return bool
@throws MetadataWriterException | [
"Write",
"a",
"value",
"to",
"a",
"$resource"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/models/classes/metadata/writer/ontologyWriter/PropertyWriter.php#L100-L120 |
oat-sa/tao-core | actions/form/class.Instance.php | tao_actions_form_Instance.initForm | protected function initForm()
{
$name = isset($this->options['name']) ? $this->options['name'] : '';
if(empty($name)){
$name = 'form_'.(count(self::$forms)+1);
}
unset($this->options['name']);
$this->form = tao_helpers_form_FormFactory::getForm($name, $this->options);
//add translate action in toolbar
$actions = tao_helpers_form_FormFactory::getCommonActions();
//add a hidden form element that states that it is an Instance Form.
$instanceElt = tao_helpers_form_FormFactory::getElement('tao.forms.instance', 'Hidden');
$instanceElt->setValue('1');
$this->form->addElement($instanceElt, true);
//add a token to protect against xsrf
$tokenElt = tao_helpers_form_FormFactory::getElement('token', 'Token');
$tokenElt->addValidator(new XsrfTokenValidator());
$this->form->addElement($tokenElt, true);
$this->form->setActions($actions, 'top');
$this->form->setActions($actions, 'bottom');
} | php | protected function initForm()
{
$name = isset($this->options['name']) ? $this->options['name'] : '';
if(empty($name)){
$name = 'form_'.(count(self::$forms)+1);
}
unset($this->options['name']);
$this->form = tao_helpers_form_FormFactory::getForm($name, $this->options);
//add translate action in toolbar
$actions = tao_helpers_form_FormFactory::getCommonActions();
//add a hidden form element that states that it is an Instance Form.
$instanceElt = tao_helpers_form_FormFactory::getElement('tao.forms.instance', 'Hidden');
$instanceElt->setValue('1');
$this->form->addElement($instanceElt, true);
//add a token to protect against xsrf
$tokenElt = tao_helpers_form_FormFactory::getElement('token', 'Token');
$tokenElt->addValidator(new XsrfTokenValidator());
$this->form->addElement($tokenElt, true);
$this->form->setActions($actions, 'top');
$this->form->setActions($actions, 'bottom');
} | [
"protected",
"function",
"initForm",
"(",
")",
"{",
"$",
"name",
"=",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'name'",
"]",
")",
"?",
"$",
"this",
"->",
"options",
"[",
"'name'",
"]",
":",
"''",
";",
"if",
"(",
"empty",
"(",
"$",
"name"... | Initialize the form
@access protected
@author Bertrand Chevrier, <bertrand.chevrier@tudor.lu>
@return mixed | [
"Initialize",
"the",
"form"
] | train | https://github.com/oat-sa/tao-core/blob/067ef1ddc1a273a6f59be1cc6d07ada7c6033cd0/actions/form/class.Instance.php#L47-L72 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.