public function __construct($name, $params = array(), $lists = array())
 {
     if (!isset($params[0])) {
         throw new CMDLParserException('Missing mandatory parameter type for form element sourcecode.', CMDLParserException::CMDL_MISSING_MANDATORY_PARAM);
     }
     $this->setType($params[0]);
     if (isset($params[1])) {
         $this->setRows($params[1]);
     }
     if (isset($params[2])) {
         $this->setSize($params[2]);
     }
     parent::__construct($name, $params, $lists);
 }
Esempio n. 2
0
 public static function parseFormElementDefinition($line)
 {
     $line = trim($line);
     $name = Util::getTextBetweenChars($line, '{', '}');
     $line = Util::removeTextBetweenCharsIncludingDelimiters($line, '{', '}');
     $p = strpos($line, '=');
     if ($p) {
         $title = trim(substr($line, 0, $p));
         $onTheRight = trim(substr($line, $p + 1));
     } else {
         $title = trim($line);
         $onTheRight = '';
     }
     if ($name) {
         $name = $name[0];
     } else {
         $name = Util::generateValidIdentifier($title);
     }
     //
     // extract type and qualifier
     //
     $type = 'textfield';
     $typeWithQualifier = $type;
     $params = array();
     $lists = array();
     if ($onTheRight != '') {
         $p = strpos($onTheRight, ' ');
         if ($p) {
             $typeWithQualifier = substr($onTheRight, 0, $p);
             $onTheRight = substr($onTheRight, $p + 1);
             $lists = Util::extractLists($onTheRight);
             $params = Util::extractParams($onTheRight);
         } else {
             $typeWithQualifier = $onTheRight;
         }
         $typeWithQualifier = Util::generateValidIdentifier($typeWithQualifier, '!*§-');
         $type = Util::generateValidIdentifier($typeWithQualifier, '-');
     }
     switch ($type) {
         case 'textfield':
             $formElementDefinition = new TextfieldFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setSize($params[0]);
             }
             break;
         case 'link':
             $formElementDefinition = new LinkFormElementDefinition($name, $params, $lists);
             break;
         case 'email':
             $formElementDefinition = new EmailFormElementDefinition($name, $params, $lists);
             break;
         case 'textarea':
             $formElementDefinition = new TextareaFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRows($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setSize($params[1]);
             }
             break;
         case 'richtext':
             $formElementDefinition = new RichtextFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRows($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setSize($params[1]);
             }
             break;
         case 'markdown':
             $formElementDefinition = new MarkdownFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRows($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setSize($params[1]);
             }
             break;
         case 'html':
             $formElementDefinition = new HTMLFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRows($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setSize($params[1]);
             }
             break;
         case 'cmdl':
             $formElementDefinition = new CMDLFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRows($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setSize($params[1]);
             }
             break;
         case 'sourcecode':
             $formElementDefinition = new SourceCodeFormElementDefinition($name, $params, $lists);
             break;
         case 'password':
             $formElementDefinition = new PasswordFormElementDefinition($name, $params, $lists);
             break;
         case 'number':
             $formElementDefinition = new NumberFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setDigits($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setUnit($params[1]);
             }
             break;
         case 'range':
             $formElementDefinition = new RangeFormElementDefinition($name, $params, $lists);
             break;
         case 'checkbox':
             $formElementDefinition = new CheckboxFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setLegend($params[0]);
             }
             break;
         case 'selection':
             $formElementDefinition = new SelectionFormElementDefinition($name, $params, $lists);
             break;
         case 'multiselection':
             $formElementDefinition = new MultiSelectionFormElementDefinition($name, $params, $lists);
             break;
         case 'reference':
             $formElementDefinition = new ReferenceFormElementDefinition($name, $params, $lists);
             break;
         case 'multireference':
             $formElementDefinition = new MultiReferenceFormElementDefinition($name, $params, $lists);
             break;
         case 'remote-selection':
             $formElementDefinition = new RemoteSelectionFormElementDefinition($name, $params, $lists);
             break;
         case 'remote-multiselection':
             $formElementDefinition = new RemoteMultiSelectionFormElementDefinition($name, $params, $lists);
             break;
         case 'remote-reference':
             $formElementDefinition = new RemoteReferenceFormElementDefinition($name, $params, $lists);
             break;
         case 'remote-multireference':
             $formElementDefinition = new RemoteMultiReferenceFormElementDefinition($name, $params, $lists);
             break;
         case 'timestamp':
             $formElementDefinition = new TimestampFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setType($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setInit($params[1]);
             }
             break;
         case 'date':
             $formElementDefinition = new DateFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setType($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setInit($params[1]);
             }
             break;
         case 'time':
             $formElementDefinition = new TimeFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setType($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setInit($params[1]);
             }
             break;
         case 'file':
             $formElementDefinition = new FileFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setPath($params[0]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'files':
             $formElementDefinition = new FilesFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setPath($params[0]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'image':
             $formElementDefinition = new ImageFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setPath($params[0]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'images':
             $formElementDefinition = new ImagesFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setPath($params[0]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'remote-file':
             $formElementDefinition = new RemoteFileFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRepositoryUrl($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setPath($params[1]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'remote-files':
             $formElementDefinition = new RemoteFilesFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRepositoryUrl($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setPath($params[1]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'remote-image':
             $formElementDefinition = new RemoteImageFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRepositoryUrl($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setPath($params[1]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'remote-images':
             $formElementDefinition = new RemoteImagesFormElementDefinition($name);
             if (isset($params[0])) {
                 $formElementDefinition->setRepositoryUrl($params[0]);
             }
             if (isset($params[1])) {
                 $formElementDefinition->setPath($params[1]);
             }
             if (isset($lists[0])) {
                 $formElementDefinition->setFileTypes($lists[0]);
             }
             break;
         case 'table':
             $lists = Util::extractLists($onTheRight, true);
             $formElementDefinition = new TableFormElementDefinition($name, $params, $lists);
             break;
         case 'color':
             $formElementDefinition = new ColorFormElementDefinition($name, $params, $lists);
             break;
         case 'geolocation':
             $formElementDefinition = new GeolocationFormElementDefinition($name, $params, $lists);
             break;
         case 'sequence':
             $formElementDefinition = new SequenceFormElementDefinition($name);
             if (isset($lists[0])) {
                 $formElementDefinition->setInserts($lists[0]);
             }
             break;
         case 'custom':
             $formElementDefinition = new CustomFormElementDefinition($name, $params, $lists);
             break;
         default:
             throw new CMDLParserException('Unknown form element type ' . $type . '.', CMDLParserException::CMDL_UNKNOWN_FORMELEMENT_TYPE);
             break;
     }
     $formElementDefinition->setLabel($title);
     if (strstr($typeWithQualifier, '*') !== false) {
         $formElementDefinition->markMandatory();
     }
     if (strstr($typeWithQualifier, '!') !== false) {
         $formElementDefinition->markUnique();
     }
     if (strstr($typeWithQualifier, '§') !== false) {
         $formElementDefinition->markProtected();
     }
     return $formElementDefinition;
 }