public function setValues() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } $values = tao_helpers_form_GenerisTreeForm::getSelectedInstancesFromPost(); $resource = new core_kernel_classes_Resource($this->getRequestParameter('resourceUri')); $property = new core_kernel_classes_Property($this->getRequestParameter('propertyUri')); $success = $resource->editPropertyValues($property, $values); echo json_encode(array('saved' => $success)); }
/** * Short description of method setFirstActivity * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource process * @param Resource activity * @return boolean */ public function setFirstActivity(core_kernel_classes_Resource $process, core_kernel_classes_Resource $activity) { $returnValue = (bool) false; //@TODO: to be moved to actiivty service: $activities = $this->getActivitiesByProcess($process); $propActivityInitial = new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISINITIAL); foreach ($activities as $activityTemp) { $activityTemp->editPropertyValues($propActivityInitial, GENERIS_FALSE); } $returnValue = $activity->editPropertyValues($propActivityInitial, GENERIS_TRUE); return (bool) $returnValue; }
/** * Force the mime-type of a resource * * @param string $link * @param string $mimeType * @return boolean */ public function forceMimeType($link, $mimeType) { $resource = new \core_kernel_classes_Resource(\tao_helpers_Uri::decode($link)); return $resource->editPropertyValues(new \core_kernel_classes_Property(MEDIA_MIME_TYPE), $mimeType); }
/** * Create the default content directory of a QTI test. * * @param core_kernel_classes_Resource $test * @param boolean $createTestFile Whether or not create an empty QTI XML test file. Default is (boolean) true. * @return Directory the content directory * @throws taoQtiTest_models_classes_QtiTestServiceException If a runtime error occurs while creating the test content. */ public function createContent(core_kernel_classes_Resource $test, $createTestFile = true) { $dir = $this->getDefaultDir()->getDirectory(md5($test->getUri())); if ($dir->exists()) { throw new common_exception_InconsistentData('Data dir fir test ' . $test->getUri() . ' already exists'); } $file = $dir->getFile(TAOQTITEST_FILENAME); if ($createTestFile === true) { $emptyTestXml = $this->getQtiTestTemplateFileAsString(); $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadXML($emptyTestXml); // Set the test label as title. $doc->documentElement->setAttribute('title', $test->getLabel()); //generate a valid qti identifier $identifier = tao_helpers_Display::textCleaner($test->getLabel(), '*', 32); $identifier = str_replace('_', '-', $identifier); if (preg_match('/^[0-9]/', $identifier)) { $identifier = '_' . $identifier; } $doc->documentElement->setAttribute('identifier', $identifier); $doc->documentElement->setAttribute('toolVersion', TAO_VERSION); if (!$file->write($doc->saveXML())) { $msg = "Unable to write raw QTI Test template."; throw new taoQtiTest_models_classes_QtiTestServiceException($msg, taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR); } common_Logger::i("Created QTI Test content for test '" . $test->getUri() . "'."); } else { if ($file->exists()) { $doc = new DOMDocument('1.0', 'UTF-8'); $doc->loadXML($file->read()); // Label update only. $doc->documentElement->setAttribute('title', $test->getLabel()); if (!$file->update($doc->saveXML())) { $msg = "Unable to update QTI Test file."; throw new taoQtiTest_models_classes_QtiTestServiceException($msg, taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR); } } } $directory = $this->getFileReferenceSerializer()->serialize($dir); $test->editPropertyValues($this->getProperty(TEST_TESTCONTENT_PROP), $directory); return $dir; }
/** * @param string deliveryIdentifier (uri recommended) */ public function storeDelivery(core_kernel_classes_Resource $deliveryResult, $deliveryIdentifier) { $propResultOfDelivery = new core_kernel_classes_Property(PROPERTY_RESULT_OF_DELIVERY); $deliveryResult->editPropertyValues($propResultOfDelivery, $deliveryIdentifier); try { //if the delviery information is provided, update to a more meaningful delvieryResult Label $delivery = new core_kernel_classes_Resource($deliveryIdentifier); $deliveryLabel = $delivery->getLabel(); $deliveryResult->setLabel(str_replace("-" . $deliveryLabel, "", $deliveryResult->getLabel()) . "-" . $deliveryLabel); } catch (Exception $e) { //the test taker to be referrd in the delivery Result does not exist (or the label is not stated) } }
/** * Short description of method setConnectorType * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource connector * @param Resource type * @return boolean */ public function setConnectorType(core_kernel_classes_Resource $connector, core_kernel_classes_Resource $type) { $returnValue = (bool) false; //@TODO: check range of type of connectors: $returnValue = $connector->editPropertyValues(new core_kernel_classes_Property(PROPERTY_CONNECTORS_TYPE), $type->getUri()); return (bool) $returnValue; }
/** * Create the defautl content directory of a QTI test. * * @param core_kernel_classes_Resource $test * @param boolean $createTestFile Whether or not create an empty QTI XML test file. Default is (boolean) true. * @return core_kernel_file_File the content file * @throws taoQtiTest_models_classes_QtiTestServiceException If a runtime error occurs while creating the test content. */ public function createContent(core_kernel_classes_Resource $test, $createTestFile = true) { $props = self::getQtiTestDirectory()->getPropertiesValues(array(PROPERTY_FILE_FILESYSTEM, PROPERTY_FILE_FILEPATH)); $repository = new core_kernel_versioning_Repository(current($props[PROPERTY_FILE_FILESYSTEM])); $path = (string) current($props[PROPERTY_FILE_FILEPATH]); // $directory is the directory where test related resources will be stored. $directory = $repository->createFile('', $path . DIRECTORY_SEPARATOR . md5($test->getUri()) . DIRECTORY_SEPARATOR); $dirPath = $directory->getAbsolutePath() . DIRECTORY_SEPARATOR; if (!file_exists($dirPath)) { mkdir($dirPath, 0770, true); } if ($createTestFile === true) { $emptyTestXml = $this->getQtiTestTemplateFileAsString(); $doc = new DOMDocument(); $doc->loadXML($emptyTestXml); // Set the test label as title. $doc->documentElement->setAttribute('title', $test->getLabel()); //generate a valid qti identifier $identifier = tao_helpers_Display::textCleaner($test->getLabel(), '*', 32); $identifier = str_replace('_', '-', $identifier); if (preg_match('/^[0-9]/', $identifier)) { $identifier = '_' . $identifier; } $doc->documentElement->setAttribute('identifier', $identifier); $doc->documentElement->setAttribute('toolVersion', TAO_VERSION); $filePath = $dirPath . TAOQTITEST_FILENAME; if ($doc->save($filePath) === false) { $msg = "Unable to write raw QTI Test template at location '{$filePath}'."; throw new taoQtiTest_models_classes_QtiTestServiceException($msg, taoQtiTest_models_classes_QtiTestServiceException::TEST_WRITE_ERROR); } common_Logger::i("Created QTI Test content at location '" . $filePath . "'."); } $test->editPropertyValues(new core_kernel_classes_Property(TEST_TESTCONTENT_PROP), $directory); return $directory; }
/** * (non-PHPdoc) * @see taoTests_models_classes_TestModel::cloneContent() */ public function cloneContent(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination) { //clone the process: $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP); try { $process = $source->getUniquePropertyValue($propInstanceContent); $processCloner = new wfAuthoring_models_classes_ProcessCloner(); $processClone = $processCloner->cloneProcess($process); $destination->editPropertyValues($propInstanceContent, $processClone->getUri()); } catch (Exception $e) { throw new Exception("the test process cannot be found"); } }
/** * * For now it is only one test * * @author Lionel Lecaque, lionel@taotesting.com */ public function addTest(core_kernel_classes_Resource $content, core_kernel_classes_Resource $test) { return $content->editPropertyValues(new core_kernel_classes_Property(PROPERTY_DELIVERYCONTENT_TEST), $test->getUri()); }
/** * Set the password of a specifc user. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Resource user The user you want to set the password. * @param string password The md5 hash of the password you want to set to the user. */ public function setPassword(core_kernel_classes_Resource $user, $password) { if (!is_string($password)) { throw new core_kernel_users_Exception('The password must be of "string" type, got ' . gettype($password)); } $user->editPropertyValues(new core_kernel_classes_Property(PROPERTY_USER_PASSWORD), core_kernel_users_Service::getPasswordHash()->encrypt($password)); }
/** * Short description of method setControls * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource activity * @param array controls * @return boolean */ public function setControls(core_kernel_classes_Resource $activity, $controls) { $returnValue = (bool) false; $possibleValues = $this->getAllControls(); if (is_array($controls)) { $values = array(); foreach ($controls as $control) { if (in_array($control, $possibleValues)) { $values[] = $control; } } $returnValue = $activity->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITIES_CONTROLS), $values); } return (bool) $returnValue; }
/** * * @author Patrick Plichart, patrick@taotesting.com * @param string $uri * @param array $propertiesValues * @throws common_exception_InvalidArgumentType * @throws common_exception_PreConditionFailure * @throws common_exception_NoContent * @return core_kernel_classes_Resource */ public function update($uri, $propertiesValues = array()) { if (!common_Utils::isUri($uri)) { throw new common_exception_InvalidArgumentType(); } if (!$this->isInScope($uri)) { throw new common_exception_PreConditionFailure("The URI must be a valid resource under the root Class"); } $resource = new core_kernel_classes_Resource($uri); // if the resource does not exist, indicate a not found exception if (count($resource->getRdfTriples()->sequence) == 0) { throw new common_exception_NoContent(); } foreach ($propertiesValues as $uri => $parameterValue) { $resource->editPropertyValues(new core_kernel_classes_Property($uri), $parameterValue); } return $resource; }
/** * Short description of method setHidden * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource activity * @param boolean hidden * @return boolean */ public function setHidden(core_kernel_classes_Resource $activity, $hidden = true) { $returnValue = (bool) false; $propHidden = new core_kernel_classes_Property(PROPERTY_ACTIVITIES_ISHIDDEN); $hidden = (bool) $hidden; $returnValue = $activity->editPropertyValues($propHidden, $hidden ? GENERIS_TRUE : GENERIS_FALSE); $this->setCache(__CLASS__ . '::isHidden', array($activity), $hidden); return (bool) $returnValue; }
/** * Save excluded test takers * @param \core_kernel_classes_Resource $delivery Delivery instance * @param array $excluded List of excluded testakers (uri) * @return boolean */ public function saveExcludedTestTakers(\core_kernel_classes_Resource $delivery, $excluded) { $success = $delivery->editPropertyValues(new \core_kernel_classes_Property(TAO_DELIVERY_EXCLUDEDSUBJECTS_PROP), $excluded); return $success; }
/** * Set whether this Eligibility can by-pass the proctor authorization * @param Resource $eligibility * @param boolean $bypass true if the elligility can by-pass the proctor authorization */ public function setByPassProctor(Resource $eligibility, $bypass = false) { $eligibility->editPropertyValues(new Property(self::PROPERTY_BYPASSPROCTOR_URI), new Resource($bypass ? self::BOOLEAN_TRUE : self::BOOLEAN_FALSE)); }
/** * Short description of method setRootActivities * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource processDefinition * @param array rootActivities * @return boolean */ public function setRootActivities(core_kernel_classes_Resource $processDefinition, $rootActivities) { $returnValue = (bool) false; //@TODO: use this method to set initial process activities $processDefinition->editPropertyValues($this->processRootActivitiesProp, $rootActivities); return (bool) $returnValue; }
/** * Short description of method createNonce * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource activityExecution * @param string nonce * @return string */ public function createNonce(core_kernel_classes_Resource $activityExecution, $nonce = '') { $returnValue = (string) ''; //tip : to be executed after a transition : $nonce = trim($nonce); if (empty($nonce)) { // $nonce = (string)time(); $nonce = (string) uniqid(time() . 'n'); } if ($activityExecution->editPropertyValues($this->activityExecutionNonceProperty, $nonce)) { $returnValue = $nonce; $this->setCache(__CLASS__ . '::getNonce', array($activityExecution), (string) $returnValue); } return (string) $returnValue; }
<?php /** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2015 (original work) Open Assessment Technologies SA; * * */ require_once dirname(__FILE__) . '/../includes/raw_start.php'; $user = new core_kernel_classes_Resource(LOCAL_NAMESPACE . DEFAULT_USER_URI_SUFFIX); $login = $user->getUniquePropertyValue(new core_kernel_classes_Property(PROPERTY_USER_LOGIN)); $password = readline("Enter new password for user '" . $login . "': "); $success = false; if (!empty($password)) { $hash = core_kernel_users_Service::getPasswordHash(); $success = $user->editPropertyValues(new core_kernel_classes_Property(PROPERTY_USER_PASSWORD), $hash->encrypt($password)); } die($success ? 0 : 1);
/** * Set the model of an item * * @param core_kernel_classes_Resource $item * @param core_kernel_classes_Resource $model * @return boolean */ public function setItemModel(core_kernel_classes_Resource $item, core_kernel_classes_Resource $model) { return $item->editPropertyValues($this->getProperty(self::PROPERTY_ITEM_MODEL), $model); }
/** * Short description of method setStatus * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Resource processExecution * @param string status * @return boolean */ public function setStatus(core_kernel_classes_Resource $processExecution, $status) { $returnValue = (bool) false; if (!empty($status)) { if ($status instanceof core_kernel_classes_Resource) { switch ($status->getUri()) { case INSTANCE_PROCESSSTATUS_RESUMED: case INSTANCE_PROCESSSTATUS_STARTED: case INSTANCE_PROCESSSTATUS_FINISHED: case INSTANCE_PROCESSSTATUS_PAUSED: case INSTANCE_PROCESSSTATUS_CLOSED: $returnValue = $processExecution->editPropertyValues($this->processInstancesStatusProp, $status->getUri()); break; } } else { if (is_string($status)) { $status = strtolower(trim($status)); switch ($status) { case 'resumed': $status = new core_kernel_classes_Resource(INSTANCE_PROCESSSTATUS_RESUMED); break; case 'started': $status = new core_kernel_classes_Resource(INSTANCE_PROCESSSTATUS_STARTED); break; case 'finished': $status = new core_kernel_classes_Resource(INSTANCE_PROCESSSTATUS_FINISHED); break; case 'paused': $status = new core_kernel_classes_Resource(INSTANCE_PROCESSSTATUS_PAUSED); break; case 'closed': $status = new core_kernel_classes_Resource(INSTANCE_PROCESSSTATUS_CLOSED); break; } if ($status instanceof core_kernel_classes_Resource) { $returnValue = $processExecution->editPropertyValues($this->processInstancesStatusProp, $status->getUri()); } } } if ($returnValue) { $this->setCache(__CLASS__ . '::getStatus', array($processExecution), $status); } } return (bool) $returnValue; }
/** * Short description of method editSplitVariables * * @access public * @author Joel Bout, <*****@*****.**> * @param Resource activityCardinality * @param array variables * @return boolean */ public function editSplitVariables(core_kernel_classes_Resource $activityCardinality, $variables) { $returnValue = (bool) false; $returnValue = $activityCardinality->editPropertyValues(new core_kernel_classes_Property(PROPERTY_ACTIVITYCARDINALITY_SPLITVARIABLES), $variables); return (bool) $returnValue; }
/** * changes the service definition of a service call * * @access public * @author Joel Bout, <*****@*****.**> * @param core_kernel_classes_Resource serviceCall * @param core_kernel_classes_Resource serviceDefinition * @return boolean */ public function setCallOfServiceDefinition(core_kernel_classes_Resource $serviceCall, core_kernel_classes_Resource $serviceDefinition) { return $serviceCall->editPropertyValues(new core_kernel_classes_Property(PROPERTY_CALLOFSERVICES_SERVICEDEFINITION), $serviceDefinition->getUri()); }
/** * Set the model of an item * * @param core_kernel_classes_Resource $item * @param core_kernel_classes_Resource $model * @return boolean */ public function setItemModel(core_kernel_classes_Resource $item, core_kernel_classes_Resource $model) { $modelProp = new core_kernel_classes_Property(TAO_ITEM_MODEL_PROPERTY); return $item->editPropertyValues($modelProp, $model); }
/** * (non-PHPdoc) * @see taoTests_models_classes_TestModel::cloneContent() */ public function cloneContent(core_kernel_classes_Resource $source, core_kernel_classes_Resource $destination) { //clone the process: $propInstanceContent = new core_kernel_classes_Property(TEST_TESTCONTENT_PROP); try { $content = $source->getUniquePropertyValue($propInstanceContent); $destination->editPropertyValues($propInstanceContent, $content->duplicate()); } catch (Exception $e) { throw new Exception("the test process cannot be found"); } }
/** * Short description of method sendNotifications * * @access public * @author Somsack Sipasseuth, <*****@*****.**> * @param Adapter adapter * @return boolean */ public function sendNotifications(tao_helpers_transfert_Adapter $adapter) { $returnValue = (bool) false; if (!is_null($adapter)) { //initialize properties used in the loop $userMailProp = new core_kernel_classes_Property(PROPERTY_USER_MAIL); $processExecutionOfProp = new core_kernel_classes_Property(PROPERTY_PROCESSINSTANCES_EXECUTIONOF); //create messages from the notifications resources $messages = array(); $notificationsToSend = $this->getNotificationsToSend(); foreach ($notificationsToSend as $notificationResource) { //get the message content from the notification //@TODO: "getNotificationMessage" can be cached $content = (string) $notificationResource->getOnePropertyValue($this->notificationMessageProp); //get the email of the user $toEmail = ''; $to = $notificationResource->getOnePropertyValue($this->notificationToProp); if (!is_null($to)) { $toEmail = (string) $to->getOnePropertyValue($userMailProp); } //get the name of the concerned process $processName = ''; $processExec = $notificationResource->getOnePropertyValue($this->notificationProcessExecProp); if ($processExec instanceof core_kernel_classes_Resource) { $process = $processExec->getOnePropertyValue($processExecutionOfProp); if ($process instanceof core_kernel_classes_Resource) { $processName = $process->getLabel() . " / " . $processExec->getLabel(); } } //create the message instance if (!empty($toEmail) && !empty($content)) { $message = new tao_helpers_transfert_Message(); $message->setTitle(__("[TAO Notification System] Workflow") . ' : ' . $processName); $message->setBody($content); $message->setTo($toEmail); $message->setFrom("*****@*****.**"); $messages[$notificationResource->getUri()] = $message; } } if (count($messages) > 0) { $adapter->setMessages($messages); $returnValue = count($messages) == $adapter->send(); foreach ($adapter->getMessages() as $notificationUri => $message) { if ($message->getStatus() == tao_helpers_transfert_Message::STATUS_SENT) { $notificationResource = new core_kernel_classes_Resource($notificationUri); $notificationResource->editPropertyValues($this->notificationSentProp, GENERIS_TRUE); } //add a new date at each sending try $notificationResource->setPropertyValue($this->notificationDateProp, date("Y-m-d H:i:s")); } } } return (bool) $returnValue; }