/**
  * (non-PHPdoc)
  * @see tao_helpers_form_FormContainer::initElements()
  */
 public function initElements()
 {
     /*
         	$descElt = tao_helpers_form_FormFactory::getElement('qtitest_desc', 'Label');
     $descElt->setValue(__('A qti testpackage'));
     $this->form->addElement($descElt);
     */
     //create file upload form box
     $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add the source file"));
     if (isset($_POST['import_sent_xhtml'])) {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('FileMimeType', array('mimetype' => array('application/zip', 'application/x-zip', 'application/x-zip-compressed', 'application/octet-stream'), 'extension' => array('zip'))), tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     $this->form->createGroup('file', __('Upload a QTI 2.1 Test Package File'), array('source'));
     $element = tao_helpers_form_FormFactory::getElement('uri', 'Hidden');
     //$element->setValue();
     $this->getForm()->addElement($element);
     $xhtmlSentElt = tao_helpers_form_FormFactory::getElement('import_sent_qtitest', 'Hidden');
     $xhtmlSentElt->setValue(1);
     $this->form->addElement($xhtmlSentElt);
 }
 protected function initElements()
 {
     parent::initElements();
     $labelElt = $this->form->getElement(\tao_helpers_Uri::encode(RDFS_LABEL));
     if ($labelElt !== null) {
         $labelElt->addAttribute('noLabel', true);
         $labelElt->addAttribute('class', 'full-width js-label');
         $labelElt->addAttribute('value', '{{label}}');
         $labelElt->setName('label');
         $labelElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('NotEmpty')));
         $this->form->addElement($labelElt);
     }
     $maxExecElt = $this->form->getElement(\tao_helpers_Uri::encode(TAO_DELIVERY_MAXEXEC_PROP));
     if ($maxExecElt !== null) {
         $maxExecElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('Integer', array('min' => 1))));
         $maxExecElt->addAttribute('value', '{{maxexec}}');
         $maxExecElt->addAttribute('noLabel', true);
         $maxExecElt->setName('maxexec');
         $maxExecElt->addAttribute('class', 'full-width js-maxexec');
         $this->form->addElement($maxExecElt);
     }
     $resultServerElt = $this->form->getElement(\tao_helpers_Uri::encode(TAO_DELIVERY_RESULTSERVER_PROP));
     if ($resultServerElt !== null) {
         $resultServerElt->addAttribute('noLabel', true);
         $resultServerElt->addAttribute('class', 'full-width');
         $resultServerElt->setName('resultserver');
         $resultServerElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('NotEmpty')));
         $this->form->addElement($resultServerElt);
     }
     $recurrenceRuleElt = $this->form->getElement(\tao_helpers_Uri::encode(DeliveryScheduleService::TAO_DELIVERY_RRULE_PROP));
     if ($recurrenceRuleElt !== null) {
         $recurrenceRuleElt->setName('rrule');
         $this->form->addElement($recurrenceRuleElt);
     }
 }
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     parent::initElements();
     $codeElt = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_PROCESSVARIABLES_CODE));
     $codeElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $codeElt->addValidator(new wfAuthoring_actions_form_validators_VariableCode(array('uri' => $this->getInstance()->getUri())));
 }
 /**
  * Inits the element to select the importhandler
  * and takes over the elements of the import form
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     //create the element to select the import format
     $formatElt = tao_helpers_form_FormFactory::getElement('importHandler', 'Radiobox');
     $formatElt->setDescription(__('Choose import format'));
     $formatElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     // should never happen anyway
     $importHandlerOptions = array();
     foreach ($this->importHandlers as $importHandler) {
         $importHandlerOptions[get_class($importHandler)] = $importHandler->getLabel();
     }
     $formatElt->setOptions($importHandlerOptions);
     $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
     //		$classUriElt->setValue($class->getUri());
     $this->form->addElement($classUriElt);
     $classUriElt = tao_helpers_form_FormFactory::getElement('id', 'Hidden');
     $this->form->addElement($classUriElt);
     $this->form->addElement($formatElt);
     $this->form->createGroup('formats', __('Supported import formats'), array('importHandler'));
     if (!is_null($this->subForm)) {
         //			load dynamically the method regarding the selected format
         $this->form->setElements(array_merge($this->form->getElements(), $this->subForm->getElements()));
         foreach ($this->subForm->getGroups() as $key => $group) {
             $this->form->createGroup($key, $group['title'], $group['elements'], $group['options']);
         }
     }
 }
 public function initElements()
 {
     $class = $this->data['class'];
     if (!$class instanceof \core_kernel_classes_Class) {
         throw new \common_Exception('missing class in simple delivery creation form');
     }
     $classUriElt = \tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
     $classUriElt->setValue($class->getUri());
     $this->form->addElement($classUriElt);
     //create the element to select the import format
     $formatElt = \tao_helpers_form_FormFactory::getElement('test', 'Combobox');
     $formatElt->setDescription(__('Select the test you want to publish to the test-takers'));
     $testClass = new \core_kernel_classes_Class(TAO_TEST_CLASS);
     $options = array();
     $testService = \taoTests_models_classes_TestsService::singleton();
     foreach ($testClass->getInstances(true) as $test) {
         try {
             $testItems = $testService->getTestItems($test);
             //Filter tests which has no items
             if (!empty($testItems)) {
                 $options[$test->getUri()] = $test->getLabel();
             }
         } catch (\Exception $e) {
             \common_Logger::w('Unable to load items for test ' . $test->getUri());
         }
     }
     if (empty($options)) {
         throw new NoTestsException();
     }
     $formatElt->setOptions($options);
     $formatElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($formatElt);
 }
 /**
  * Initialiaze recovery form elements
  *
  * @access public
  * @author Aleh Hutnikau <*****@*****.**>
  */
 public function initElements()
 {
     $mailElement = tao_helpers_form_FormFactory::getElement('userMail', 'Textbox');
     $mailElement->setDescription(__('Your mail') . '*');
     $mailElement->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $mailElement->addValidator(tao_helpers_form_FormFactory::getValidator('Email'));
     $mailElement->setAttributes(array('autofocus' => 'autofocus'));
     $this->form->addElement($mailElement);
 }
 /**
  * Init filename field
  *
  * @throws \common_Exception
  */
 public function initElements()
 {
     $date = new \DateTime();
     $filename = 'metadata-' . $date->format('ymd');
     $nameElt = \tao_helpers_form_FormFactory::getElement('filename', 'Textbox');
     $nameElt->setDescription(__('File name'));
     $nameElt->setValue($filename);
     $nameElt->setUnit(".csv");
     $nameElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($nameElt);
     $this->form->createGroup('options', __('Export metadata item'), array('xml_desc', 'filename', 'exportInstance'));
 }
Beispiel #8
0
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $labelElt = tao_helpers_form_FormFactory::getElement('label', 'Textbox');
     $labelElt->setDescription(__('Name'));
     $labelElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($labelElt);
     $sizeElt = tao_helpers_form_FormFactory::getElement('size', 'Textbox');
     $sizeElt->setDescription(__('Number of elements'));
     $sizeElt->setAttribute('size', '4');
     $sizeElt->setValue(1);
     $sizeElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Integer', array('min' => 1))));
     $this->form->addElement($sizeElt);
 }
Beispiel #9
0
 /**
  * Initialize the form elements
  *
  * @access protected
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     parent::initElements();
     $elements = $this->form->getElements();
     $this->form->setElements(array());
     $currentLangElt = tao_helpers_form_FormFactory::getElement('current_lang', 'Textbox');
     $currentLangElt->setDescription(__('Current language'));
     $currentLangElt->setAttributes(array('readonly' => 'true'));
     $currentLangElt->setValue(\common_session_SessionManager::getSession()->getDataLanguage());
     //API lang /data lang
     $this->form->addElement($currentLangElt);
     $dataLangElement = tao_helpers_form_FormFactory::getElement('translate_lang', 'Combobox');
     $dataLangElement->setDescription(__('Translate to'));
     $dataLangElement->setOptions(tao_helpers_I18n::getAvailableLangsByUsage(new core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA)));
     $dataLangElement->setEmptyOption(__('Select a language'));
     $dataLangElement->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($dataLangElement);
     $this->form->createGroup('translation_info', __('Translation parameters'), array('current_lang', 'translate_lang'));
     $dataGroup = array();
     foreach ($elements as $element) {
         if ($element instanceof tao_helpers_form_elements_Hidden || $element->getName() == 'uri' || $element->getName() == 'classUri') {
             $this->form->addElement($element);
         } else {
             $propertyUri = tao_helpers_Uri::decode($element->getName());
             $property = new core_kernel_classes_Property($propertyUri);
             //translate only language dependent properties or Labels
             //supported widget are: Textbox, TextArea, HtmlArea
             //@todo support other widgets
             if ($property->isLgDependent() && ($element instanceof tao_helpers_form_elements_Textbox || $element instanceof tao_helpers_form_elements_TextArea || $element instanceof tao_helpers_form_elements_HtmlArea) || $propertyUri == RDFS_LABEL) {
                 $translatedElt = clone $element;
                 $viewElt = tao_helpers_form_FormFactory::getElement('view_' . $element->getName(), 'Label');
                 $viewElt->setDescription($element->getDescription());
                 $viewElt->setValue($element->getValue());
                 $viewElt->setAttribute('no-format', true);
                 if ($element instanceof tao_helpers_form_elements_HtmlArea) {
                     $viewElt->setAttribute('htmlentities', false);
                 }
                 $this->form->addElement($viewElt);
                 $dataGroup[] = $viewElt->getName();
                 $translatedElt->setDescription(' ');
                 $translatedElt->setValue('');
                 if ($propertyUri == RDFS_LABEL) {
                     $translatedElt->setForcedValid();
                 }
                 $this->form->addElement($translatedElt);
                 $dataGroup[] = $translatedElt->getName();
             }
         }
     }
     $this->form->createGroup('translation_form', __('Translate'), $dataGroup);
 }
 /**
  * Initialiaze password reset form elements
  *
  * @access public
  * @author Aleh Hutnikau <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $tokenElement = tao_helpers_form_FormFactory::getElement('token', 'Hidden');
     $this->form->addElement($tokenElement);
     $pass1Element = tao_helpers_form_FormFactory::getElement('newpassword', 'Hiddenbox');
     $pass1Element->setDescription(__('New password'));
     $pass1Element->addValidators(PasswordConstraintsService::singleton()->getValidators());
     $pass1Element->setBreakOnFirstError(false);
     $this->form->addElement($pass1Element);
     $pass2Element = tao_helpers_form_FormFactory::getElement('newpassword2', 'Hiddenbox');
     $pass2Element->setDescription(__('Repeat new password'));
     $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass1Element))));
     $this->form->addElement($pass2Element);
 }
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $pass1Element = tao_helpers_form_FormFactory::getElement('oldpassword', 'Hiddenbox');
     $pass1Element->setDescription(__('Old Password'));
     $pass1Element->addValidator(tao_helpers_form_FormFactory::getValidator('Callback', array('message' => __('Passwords are not matching'), 'object' => tao_models_classes_UserService::singleton(), 'method' => 'isPasswordValid', 'param' => tao_models_classes_UserService::singleton()->getCurrentUser())));
     $this->form->addElement($pass1Element);
     $pass2Element = tao_helpers_form_FormFactory::getElement('newpassword', 'Hiddenbox');
     $pass2Element->setDescription(__('New password'));
     $pass2Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
     $this->form->addElement($pass2Element);
     $pass3Element = tao_helpers_form_FormFactory::getElement('newpassword2', 'Hiddenbox');
     $pass3Element->setDescription(__('Repeat new password'));
     $pass3Element->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password', array('password2_ref' => $pass2Element))));
     $this->form->addElement($pass3Element);
 }
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $loginElt = tao_helpers_form_FormFactory::getElement('login', 'Textbox');
     $loginElt->setDescription(__('Login'));
     $loginElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($loginElt);
     $passElt = tao_helpers_form_FormFactory::getElement('password', 'Hiddenbox');
     $passElt->setDescription(__('Password'));
     $passElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($passElt);
     //add 2 hidden inputs to post requested process and activity executions:
     $processElt = tao_helpers_form_FormFactory::getElement('processUri', 'Hidden');
     $this->form->addElement($processElt);
     $activityElt = tao_helpers_form_FormFactory::getElement('activityUri', 'Hidden');
     $this->form->addElement($activityElt);
 }
 /**
  * overriden
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     //create file upload form box
     $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add an RDF/XML file"));
     if (isset($_POST['import_sent_rdf'])) {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('FileMimeType', array('mimetype' => array('text/xml', 'application/rdf+xml', 'application/xml'), 'extension' => array('rdf', 'rdfs'))), tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     $this->form->createGroup('file', __('Import Metadata from RDF file'), array('rdf_desc', 'source'));
     $rdfSentElt = tao_helpers_form_FormFactory::getElement('import_sent_rdf', 'Hidden');
     $rdfSentElt->setValue(1);
     $this->form->addElement($rdfSentElt);
 }
Beispiel #14
0
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     if (isset($this->data['redirect']) && !empty($this->data['redirect'])) {
         $hiddenElt = tao_helpers_form_FormFactory::getElement('redirect', 'Hidden');
         $hiddenElt->setValue($this->data['redirect']);
         $this->form->addElement($hiddenElt);
     }
     $loginElt = tao_helpers_form_FormFactory::getElement('login', 'Textbox');
     $loginElt->setDescription(Layout::getLoginLabel());
     $loginElt->setAttributes(array('autofocus' => 'autofocus'));
     $loginElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($loginElt);
     $passElt = tao_helpers_form_FormFactory::getElement('password', 'Hiddenbox');
     $passElt->setDescription(Layout::getPasswordLabel());
     $passElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($passElt);
 }
 /**
  * overriden
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     //create file upload form box
     $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add a CSV file"));
     if (isset($_POST['import_sent_csv'])) {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('FileMimeType', array('mimetype' => array('text/plain', 'text/csv', 'text/comma-separated-values', 'application/csv', 'application/csv-tab-delimited-table'), 'extension' => array('csv', 'txt'))), tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     $this->form->createGroup('file', __('Import Metadata from CSV file'), array('csv_desc', 'source'));
     $csvSentElt = tao_helpers_form_FormFactory::getElement('import_sent_csv', 'Hidden');
     $csvSentElt->setValue(1);
     $this->form->addElement($csvSentElt);
     // options
     $optDelimiter = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIELD_DELIMITER, 'Textbox');
     $optDelimiter->setDescription(__("Field delimiter"));
     $optDelimiter->setValue(';');
     $optDelimiter->addAttribute("size", 6);
     $optDelimiter->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($optDelimiter);
     $optEncloser = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIELD_ENCLOSER, 'Textbox');
     $optEncloser->setDescription(__("Field encloser"));
     $optEncloser->setValue('"');
     $optEncloser->addAttribute("size", 6);
     $optEncloser->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($optEncloser);
     /*
     $optMulti = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::MULTI_VALUES_DELIMITER, 'Textbox');
     $optMulti->setDescription(__("Multiple values delimiter"));
     $optMulti->setValue('|');
     $optMulti->addAttribute("size", 6);
     $optMulti->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($optMulti);
     */
     $optFirstColumn = tao_helpers_form_FormFactory::getElement(tao_helpers_data_CsvFile::FIRST_ROW_COLUMN_NAMES, 'Checkbox');
     $optFirstColumn->setDescription(__("First row column names"));
     $optFirstColumn->setOptions(array(tao_helpers_data_CsvFile::FIRST_ROW_COLUMN_NAMES => ''));
     $optFirstColumn->setValue(tao_helpers_data_CsvFile::FIRST_ROW_COLUMN_NAMES);
     $this->form->addElement($optFirstColumn);
     $this->form->createGroup('options', __('CSV Options'), array($optDelimiter, $optEncloser, $optFirstColumn));
 }
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 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', __('Supported export formats'), 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 (isset($this->data['resource'])) {
         $resource = $this->data['resource'];
     } else {
         throw new \common_Exception('No class nor instance specified for export');
     }
     $fileName = strtolower(\tao_helpers_Display::textCleaner($resource->getLabel(), '*'));
     $hiddenElt = \tao_helpers_form_FormFactory::getElement('resource', 'Hidden');
     $hiddenElt->setValue($resource->getUri());
     $this->form->addElement($hiddenElt);
     $nameElt = \tao_helpers_form_FormFactory::getElement('filename', 'Textbox');
     $nameElt->setDescription(__('File name'));
     $nameElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $nameElt->setValue($fileName);
     $nameElt->setUnit(".zip");
     $this->form->addElement($nameElt);
     $this->form->createGroup('options', __('Export Media as Zip file'), array('filename', 'ziptpl'));
 }
Beispiel #18
0
    /**
     * Short description of method initElements
     *
     * @access public
     * @author Joel Bout, <*****@*****.**>
     * @return mixed
     */
    public function initElements()
    {
        parent::initElements();
        $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_URL));
        $ele->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty'), tao_helpers_form_FormFactory::getValidator('Url')));
        $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_TYPE));
        $ele->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
        $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_ENABLED));
        //prevent having neither enabled or disabled selected
        if (is_null($ele->getValue())) {
            $ele->setValue(tao_helpers_Uri::encode(GENERIS_FALSE));
        }
        $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_LOGIN));
        $ele->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
        $ele = $this->form->getElement(tao_helpers_Uri::encode(PROPERTY_GENERIS_VERSIONEDREPOSITORY_PATH));
        $ele->setHelp(__('Path to the local working copy, it is where your local 
				version of your versioned Resource will be stored. ') . '/path/to/the/local/working_copy');
        $ele->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
    }
 protected function initElements()
 {
     parent::initElements();
     $maxExecElt = $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_MAXEXEC_PROP));
     if (!is_null($maxExecElt)) {
         $maxExecElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('Integer', array('min' => 1))));
         $this->form->addElement($maxExecElt);
     }
     $periodEndElt = $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_END_PROP));
     if (!is_null($periodEndElt)) {
         $periodEndElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('DateTime', array('comparator' => '>=', 'datetime2_ref' => $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_START_PROP))))));
         $this->form->addElement($periodEndElt);
     }
     $resultServerElt = $this->form->getElement(tao_helpers_Uri::encode(TAO_DELIVERY_RESULTSERVER_PROP));
     if (!is_null($resultServerElt)) {
         $resultServerElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty')));
         $this->form->addElement($resultServerElt);
     }
 }
 /**
  * Short description of method initElements
  *
  * @access public
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $property = $this->getPropertyInstance();
     isset($this->options['index']) ? $index = $this->options['index'] : ($index = 1);
     $propertyProperties = array_merge(tao_helpers_form_GenerisFormFactory::getDefaultProperties(), array(new core_kernel_classes_Property(PROPERTY_IS_LG_DEPENDENT), new core_kernel_classes_Property(PROPERTY_WIDGET), new core_kernel_classes_Property(RDFS_RANGE)));
     $elementNames = array();
     foreach ($propertyProperties as $propertyProperty) {
         //map properties widgets to form elements
         $element = tao_helpers_form_GenerisFormFactory::elementMap($propertyProperty);
         if (!is_null($element)) {
             //take property values to populate the form
             $values = $property->getPropertyValuesCollection($propertyProperty);
             foreach ($values->getIterator() as $value) {
                 if (!is_null($value)) {
                     if ($value instanceof core_kernel_classes_Resource) {
                         $element->setValue($value->getUri());
                     }
                     if ($value instanceof core_kernel_classes_Literal) {
                         $element->setValue((string) $value);
                     }
                 }
             }
             $element->setName("property_{$index}_{$element->getName()}");
             $element->addClass('property');
             if ($propertyProperty->getUri() == RDFS_LABEL) {
                 $element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
             }
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     $encodedUri = tao_helpers_Uri::encode($property->getUri());
     $modeElt = tao_helpers_form_FormFactory::getElement("{$index}_uri", 'Hidden');
     $modeElt->setValue($encodedUri);
     $modeElt->addClass('property');
     $this->form->addElement($modeElt);
     $elementNames[] = $modeElt->getName();
     if (count($elementNames) > 0) {
         $groupTitle = $this->getGroupTitle($property);
         $this->form->createGroup("property_{$encodedUri}", $groupTitle, $elementNames);
     }
 }
 /**
  * overriden
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $descElt = tao_helpers_form_FormFactory::getElement('rdf_desc', 'Label');
     $descElt->setValue(__('Please upload a published delivery assembly .'));
     $this->form->addElement($descElt);
     //create file upload form box
     $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add the source file."));
     if (isset($_POST['import_sent_rdf'])) {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('FileMimeType', array('mimetype' => array('application/zip', 'application/x-zip', 'application/x-zip-compressed', 'application/octet-stream'), 'extension' => array('zip'))), tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     $this->form->createGroup('file', __('Upload an assembly'), array('rdf_desc', 'source'));
     $rdfSentElt = tao_helpers_form_FormFactory::getElement('import_sent_rdf', 'Hidden');
     $rdfSentElt->setValue(1);
     $this->form->addElement($rdfSentElt);
 }
 /**
  * Used to create the form elements and bind them to the form instance
  *
  * @access protected
  * @return mixed
  */
 protected function initElements()
 {
     //create file upload form box
     $fileElt = \tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add a media file"));
     if (isset($_POST['import_sent_file'])) {
         $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(\tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => \tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     $langService = \tao_models_classes_LanguageService::singleton();
     $dataUsage = new \core_kernel_classes_Resource(INSTANCE_LANGUAGE_USAGE_DATA);
     $dataLang = \common_session_SessionManager::getSession()->getDataLanguage();
     $dataLang = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $dataLang;
     if (!is_null($this->instanceUri)) {
         $instance = new \core_kernel_classes_Resource($this->instanceUri);
         $lang = $instance->getOnePropertyValue(new \core_kernel_classes_Property(MEDIA_LANGUAGE));
         if ($lang instanceof \core_kernel_classes_Resource) {
             $dataLang = $lang->getUri();
         }
     }
     $langOptions = array();
     foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) {
         $langOptions[\tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel();
     }
     $langElt = \tao_helpers_form_FormFactory::getElement('lang', 'Combobox');
     $langElt->setValue(\tao_helpers_Uri::encode($dataLang));
     $langElt->setOptions($langOptions);
     $this->form->addElement($langElt);
     $this->form->createGroup('options', __('Media Options'), array($langElt));
     $fileSentElt = \tao_helpers_form_FormFactory::getElement('import_sent_file', 'Hidden');
     $fileSentElt->setValue(1);
     $this->form->addElement($fileSentElt);
     if (!is_null($this->instanceUri)) {
         $instanceElt = \tao_helpers_form_FormFactory::getElement('instanceUri', 'Hidden');
         $instanceElt->setValue($this->instanceUri);
         $this->form->addElement($instanceElt);
     }
 }
 /**
  * (non-PHPdoc)
  * @see tao_helpers_form_FormContainer::initElements()
  */
 public function initElements()
 {
     //create file upload form box
     $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile');
     $fileElt->setDescription(__("Add a zip file containing QTI/APIP tests and items"));
     if (isset($_POST['import_sent_qti'])) {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     } else {
         $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', array('message' => '')));
     }
     $fileElt->addValidators(array(tao_helpers_form_FormFactory::getValidator('FileMimeType', array('mimetype' => array('application/zip', 'application/x-zip', 'application/x-zip-compressed', 'application/octet-stream'), 'extension' => array('zip'))), tao_helpers_form_FormFactory::getValidator('FileSize', array('max' => tao_helpers_Environment::getFileUploadLimit()))));
     $this->form->addElement($fileElt);
     /*
     $disableValidationElt = tao_helpers_form_FormFactory::getElement("disable_validation", 'Checkbox');
     $disableValidationElt->setDescription(__("Disable validation"));
     $disableValidationElt->setOptions(array("on" => ""));
     $this->form->addElement($disableValidationElt);
     */
     $this->form->createGroup('file', __('Import a QTI/APIP Content Package'), array('source'));
     $qtiSentElt = tao_helpers_form_FormFactory::getElement('import_sent_qti', 'Hidden');
     $qtiSentElt->setValue(1);
     $this->form->addElement($qtiSentElt);
 }
 /**
  * overriden
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return mixed
  */
 public function initElements()
 {
     $fileName = '';
     $instances = array();
     if (isset($this->data['instance'])) {
         $resource = $this->data['instance'];
     } elseif (isset($this->data['class'])) {
         $resource = $this->data['class'];
     } else {
         throw new common_Exception('No class nor instance specified for export');
     }
     $fileName = strtolower(tao_helpers_Display::textCleaner($resource->getLabel(), '*'));
     $hiddenElt = tao_helpers_form_FormFactory::getElement('resource', 'Hidden');
     $hiddenElt->setValue($resource->getUri());
     $this->form->addElement($hiddenElt);
     $nameElt = tao_helpers_form_FormFactory::getElement('filename', 'Textbox');
     $nameElt->setDescription(__('File name'));
     $nameElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $nameElt->setValue($fileName);
     $nameElt->setUnit(".rdf");
     $this->form->addElement($nameElt);
     $instances = tao_helpers_Uri::encodeArray($instances, tao_helpers_Uri::ENCODE_ARRAY_KEYS);
     $this->form->createGroup('options', __('Export Metadata as RDF/XML file'), array('rdf_desc', 'filename', 'rdftpl'));
 }
 public function initElements()
 {
     $class = $this->data['class'];
     if (!$class instanceof core_kernel_classes_Class) {
         throw new common_Exception('missing class in simple delivery creation form');
     }
     $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
     $classUriElt->setValue($class->getUri());
     $this->form->addElement($classUriElt);
     //create the element to select the import format
     $formatElt = tao_helpers_form_FormFactory::getElement('test', 'Combobox');
     $formatElt->setDescription(__('Select the test you want to publish to the test-takers'));
     $testClass = new core_kernel_classes_Class(TAO_TEST_CLASS);
     $options = array();
     foreach ($testClass->getInstances(true) as $test) {
         $options[$test->getUri()] = $test->getLabel();
     }
     if (empty($options)) {
         throw new taoSimpleDelivery_actions_form_NoTestsException();
     }
     $formatElt->setOptions($options);
     $formatElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($formatElt);
 }
 /**
  * Initialize the form elements
  *
  * @access protected
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $property = new core_kernel_classes_Property($this->instance->getUri());
     isset($this->options['index']) ? $index = $this->options['index'] : ($index = 1);
     $propertyProperties = array_merge(tao_helpers_form_GenerisFormFactory::getDefaultProperties(), array(new core_kernel_classes_Property(PROPERTY_IS_LG_DEPENDENT), new core_kernel_classes_Property(TAO_GUIORDER_PROP)));
     $elementNames = array();
     foreach ($propertyProperties as $propertyProperty) {
         //map properties widgets to form elements
         $element = tao_helpers_form_GenerisFormFactory::elementMap($propertyProperty);
         if (!is_null($element)) {
             //take property values to populate the form
             $values = $property->getPropertyValuesCollection($propertyProperty);
             foreach ($values->getIterator() as $value) {
                 if (!is_null($value)) {
                     if ($value instanceof core_kernel_classes_Resource) {
                         $element->setValue($value->getUri());
                     }
                     if ($value instanceof core_kernel_classes_Literal) {
                         $element->setValue((string) $value);
                     }
                 }
             }
             $element->setName("{$index}_{$element->getName()}");
             $element->addClass('property');
             if ($propertyProperty->getUri() == TAO_GUIORDER_PROP) {
                 $element->addValidator(tao_helpers_form_FormFactory::getValidator('Integer'));
             }
             if ($propertyProperty->getUri() == RDFS_LABEL) {
                 $element->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
             }
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     //build the type list from the "widget/range to type" map
     $typeElt = tao_helpers_form_FormFactory::getElement("{$index}_type", 'Combobox');
     $typeElt->setDescription(__('Type'));
     $typeElt->addAttribute('class', 'property-type property');
     $typeElt->setEmptyOption(' --- ' . __('select') . ' --- ');
     $options = array();
     $checkRange = false;
     foreach (tao_helpers_form_GenerisFormFactory::getPropertyMap() as $typeKey => $map) {
         $options[$typeKey] = $map['title'];
         $widget = $property->getWidget();
         if ($widget instanceof core_kernel_classes_Resource) {
             if ($widget->getUri() == $map['widget']) {
                 $typeElt->setValue($typeKey);
                 $checkRange = is_null($map['range']);
             }
         }
     }
     $typeElt->setOptions($options);
     $this->form->addElement($typeElt);
     $elementNames[] = $typeElt->getName();
     //list drop down
     $listService = tao_models_classes_ListService::singleton();
     $listElt = tao_helpers_form_FormFactory::getElement("{$index}_range", 'Combobox');
     $listElt->setDescription(__('List values'));
     $listElt->addAttribute('class', 'property-listvalues property');
     $listElt->setEmptyOption(' --- ' . __('select') . ' --- ');
     $listOptions = array();
     foreach ($listService->getLists() as $list) {
         $listOptions[tao_helpers_Uri::encode($list->getUri())] = $list->getLabel();
         $range = $property->getRange();
         if (!is_null($range)) {
             if ($range->getUri() == $list->getUri()) {
                 $listElt->setValue($list->getUri());
             }
         }
     }
     $listOptions['new'] = ' + ' . __('Add / Edit lists');
     $listElt->setOptions($listOptions);
     if ($checkRange) {
         $listElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     }
     $this->form->addElement($listElt);
     $elementNames[] = $listElt->getName();
     //index part
     $indexes = $property->getPropertyValues(new \core_kernel_classes_Property(INDEX_PROPERTY));
     foreach ($indexes as $i => $indexUri) {
         $indexProperty = new \oat\tao\model\search\Index($indexUri);
         $indexFormContainer = new tao_actions_form_IndexProperty($this->getClazz(), $indexProperty, array('property' => $property->getUri(), 'propertyindex' => $index, 'index' => $i));
         /** @var tao_helpers_form_Form $indexForm */
         $indexForm = $indexFormContainer->getForm();
         foreach ($indexForm->getElements() as $element) {
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     //add this element only when the property is defined (type)
     if (!is_null($property->getRange())) {
         $addIndexElt = tao_helpers_form_FormFactory::getElement("index_{$index}_add", 'Free');
         $addIndexElt->setValue("<a href='#' class='btn-info index-adder small index'><span class='icon-add'></span> " . __('Add index') . "</a><div class='clearfix'></div>");
         $this->form->addElement($addIndexElt);
         $elementNames[] = $addIndexElt;
     } else {
         $addIndexElt = tao_helpers_form_FormFactory::getElement("index_{$index}_p", 'Free');
         $addIndexElt->setValue("<p class='index' >" . __('Choose a type for your property first') . "</p>");
         $this->form->addElement($addIndexElt);
         $elementNames[] = $addIndexElt;
     }
     //add an hidden elt for the property uri
     $encodedUri = tao_helpers_Uri::encode($property->getUri());
     $propUriElt = tao_helpers_form_FormFactory::getElement("{$index}_uri", 'Hidden');
     $propUriElt->addAttribute('class', 'property-uri property');
     $propUriElt->setValue($encodedUri);
     $this->form->addElement($propUriElt);
     $elementNames[] = $propUriElt;
     if (count($elementNames) > 0) {
         $groupTitle = $this->getGroupTitle($property);
         $this->form->createGroup("property_{$encodedUri}", $groupTitle, $elementNames);
     }
 }
 /**
  * Initialize the form elements
  *
  * @access protected
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $idElt = \tao_helpers_form_FormFactory::getElement('name', 'Textbox');
     $idElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $idElt->addValidator(\tao_helpers_form_FormFactory::getValidator('AlphaNum'));
     $this->form->addElement($idElt);
     $verElt = \tao_helpers_form_FormFactory::getElement('version', 'Textbox');
     $verElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($verElt);
     $authorElt = \tao_helpers_form_FormFactory::getElement('author', 'Textbox');
     $authValid = \tao_helpers_form_FormFactory::getValidator('NotEmpty');
     $authorElt->addValidator($authValid);
     $authorElt->setValue('Open Assessment Technologies SA');
     $this->form->addElement($authorElt);
     $nsElt = \tao_helpers_form_FormFactory::getElement('authorNs', 'Textbox');
     $nsElt->setDescription('Author namespace');
     $nsElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $nsElt->addValidator(\tao_helpers_form_FormFactory::getValidator('AlphaNum'));
     $nsElt->setValue('oat');
     $this->form->addElement($nsElt);
     $licenseElt = \tao_helpers_form_FormFactory::getElement('license', 'Textbox');
     $licenseElt->setValue('GPL-2.0');
     $this->form->addElement($licenseElt);
     $idElt = \tao_helpers_form_FormFactory::getElement('label', 'Textbox');
     $idElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty'));
     $this->form->addElement($idElt);
     $descElt = \tao_helpers_form_FormFactory::getElement('description', 'Textarea');
     //$descElt->setValue(__('Use the * character to replace any string'));
     $this->form->addElement($descElt);
     $extIds = array();
     foreach (\common_ext_ExtensionsManager::singleton()->getInstalledExtensions() as $ext) {
         $extIds[$ext->getId()] = $ext->getId();
     }
     $depElt = \tao_helpers_form_FormFactory::getElement('dependencies', 'Checkbox');
     $depElt->setDescription(__('Depends on'));
     $depElt->setOptions($extIds);
     $depElt->setValue('tao');
     $this->form->addElement($depElt);
     $chainingElt = \tao_helpers_form_FormFactory::getElement('samples', 'Checkbox');
     $chainingElt->setDescription(__('Samples'));
     $chainingElt->setOptions(array('structure' => __('sample structure'), 'model' => __('sample model (todo)'), 'rdf' => __('sample rdf install (todo)'), 'install' => __('sample post install script (todo)'), 'uninstall' => __('sample uninstall script (todo)'), 'entry' => __('sample entry point (todo)'), 'itemmodel' => __('sample item model (todo)'), 'testmodel' => __('sample test model todo)'), 'deliverymodel' => __('sample delivery model (todo)')));
     $chainingElt->setValue('structure');
     $this->form->addElement($chainingElt);
 }
Beispiel #28
0
 /**
  * Short description of method __construct
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @param  string name
  * @return mixed
  */
 public function __construct($name = '')
 {
     parent::__construct($name);
     $this->addValidators(array(tao_helpers_form_FormFactory::getValidator('Password'), tao_helpers_form_FormFactory::getValidator('Length', array('min' => 3))));
 }
Beispiel #29
0
 /**
  * Initialize the form elements
  *
  * @access protected
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $clazz = $this->getClazz();
     $instance = $this->getInstance();
     $guiOrderProperty = new core_kernel_classes_Property(TAO_GUIORDER_PROP);
     //get the list of properties to set in the form
     $propertyCandidates = tao_helpers_form_GenerisFormFactory::getDefaultProperties();
     $classProperties = tao_helpers_form_GenerisFormFactory::getClassProperties($clazz, $this->getTopClazz());
     $propertyCandidates = array_merge($propertyCandidates, $classProperties);
     $additionalProperties = isset($this->options['additionalProperties']) && is_array($this->options['additionalProperties']) ? $this->options['additionalProperties'] : array();
     if (!empty($additionalProperties)) {
         $propertyCandidates = array_merge($propertyCandidates, $additionalProperties);
     }
     $excludedProperties = isset($this->options['excludedProperties']) && is_array($this->options['excludedProperties']) ? $this->options['excludedProperties'] : array();
     $editedProperties = array();
     foreach ($propertyCandidates as $property) {
         if (!isset($editedProperties[$property->getUri()]) && !in_array($property->getUri(), $excludedProperties)) {
             $editedProperties[$property->getUri()] = $property;
         }
     }
     $finalElements = array();
     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() == WIDGET_TREEVIEW) {
                 continue;
             }
         }
         //map properties widgets to form elments
         $element = tao_helpers_form_GenerisFormFactory::elementMap($property);
         if (!is_null($element)) {
             //take instance values to populate the form
             if (!is_null($instance)) {
                 $values = $instance->getPropertyValuesCollection($property);
                 foreach ($values->getIterator() as $value) {
                     if (!is_null($value)) {
                         if ($value instanceof core_kernel_classes_Resource) {
                             if ($element instanceof tao_helpers_form_elements_Readonly) {
                                 $element->setValue($value->getLabel());
                             } else {
                                 $element->setValue($value->getUri());
                             }
                         }
                         if ($value instanceof core_kernel_classes_Literal) {
                             $element->setValue((string) $value);
                         }
                     }
                 }
             }
             //set label validator
             if ($property->getUri() == RDFS_LABEL) {
                 $element->setDescription(__('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() == 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]);
     }
     //add an hidden elt for the class uri
     $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
     $classUriElt->setValue(tao_helpers_Uri::encode($clazz->getUri()));
     $this->form->addElement($classUriElt);
     if (!is_null($instance)) {
         //add an hidden elt for the instance Uri
         $instanceUriElt = tao_helpers_form_FormFactory::getElement('uri', 'Hidden');
         $instanceUriElt->setValue(tao_helpers_Uri::encode($instance->getUri()));
         $this->form->addElement($instanceUriElt);
         $hiddenId = tao_helpers_form_FormFactory::getElement('id', 'Hidden');
         $hiddenId->setValue($instance->getUri());
         $this->form->addElement($hiddenId);
     }
 }
Beispiel #30
0
 /**
  * Initialize the form elements
  *
  * @access protected
  * @author Bertrand Chevrier, <*****@*****.**>
  * @return mixed
  */
 protected function initElements()
 {
     $clazz = $this->getClassInstance();
     //add a group form for the class edition
     $elementNames = array();
     foreach (tao_helpers_form_GenerisFormFactory::getDefaultProperties() as $property) {
         //map properties widgets to form elements
         $element = tao_helpers_form_GenerisFormFactory::elementMap($property);
         if (!is_null($element)) {
             //take property values to populate the form
             $values = $clazz->getPropertyValues($property);
             if (!$property->isMultiple()) {
                 if (count($values) > 1) {
                     $values = array_slice($values, 0, 1);
                 }
             }
             foreach ($values as $value) {
                 if (!is_null($value)) {
                     $element->setValue($value);
                 }
             }
             $element->setName('class_' . $element->getName());
             //set label validator
             if ($property->getUri() == RDFS_LABEL) {
                 $element->addValidators(array(tao_helpers_form_FormFactory::getValidator('NotEmpty')));
                 $ns = substr($clazz->getUri(), 0, strpos($clazz->getUri(), '#'));
                 if ($ns != LOCAL_NAMESPACE) {
                     $readonly = tao_helpers_form_FormFactory::getElement($element->getName(), 'Readonly');
                     $readonly->setDescription($element->getDescription());
                     $readonly->setValue($element->getRawValue());
                     $element = $readonly;
                 }
             }
             $element->addClass('global');
             $this->form->addElement($element);
             $elementNames[] = $element->getName();
         }
     }
     //add an hidden elt for the class uri
     $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden');
     $classUriElt->setValue(tao_helpers_Uri::encode($clazz->getUri()));
     $classUriElt->addClass('global');
     $this->form->addElement($classUriElt);
     $hiddenId = tao_helpers_form_FormFactory::getElement('id', 'Hidden');
     $hiddenId->setValue($clazz->getUri());
     $hiddenId->addClass('global');
     $this->form->addElement($hiddenId);
     $localNamespace = common_ext_NamespaceManager::singleton()->getLocalNamespace()->getUri();
     //class properties edition: add a group form for each property
     $classProperties = tao_helpers_form_GenerisFormFactory::getClassProperties($clazz, $this->getTopClazz());
     $i = 0;
     $systemProperties = $this->getSystemProperties();
     foreach ($classProperties as $classProperty) {
         $i++;
         $useEditor = (bool) preg_match("/^" . preg_quote($localNamespace, '/') . "/", $classProperty->getUri());
         $parentProp = true;
         $domains = $classProperty->getDomain();
         foreach ($domains->getIterator() as $domain) {
             if (array_search($classProperty->getUri(), $systemProperties) !== false || $domain->getUri() == $clazz->getUri()) {
                 $parentProp = false;
                 //@todo use the getPrivileges method once implemented
                 break;
             }
         }
         if ($useEditor) {
             $propData = array();
             if (isset($this->propertyData[$classProperty->getUri()])) {
                 foreach ($this->propertyData[$classProperty->getUri()] as $key => $value) {
                     $propData[$i . '_' . $key] = $value;
                 }
             }
             $propForm = $this->getPropertyForm($classProperty, $i, $parentProp, $propData);
             //and get its elements and groups
             $this->form->setElements(array_merge($this->form->getElements(), $propForm->getElements()));
             $this->form->setGroups(array_merge($this->form->getGroups(), $propForm->getGroups()));
             unset($propForm);
         } else {
             $roElement = tao_helpers_form_FormFactory::getElement('roProperty' . $i, 'Free');
             $roElement->setValue(__('Cannot be edited'));
             $this->form->addElement($roElement);
             $groupTitle = '<span class="property-heading-label">' . _dh($classProperty->getLabel()) . '</span>';
             $this->form->createGroup("ro_property_{$i}", $groupTitle, array('roProperty' . $i));
         }
     }
 }