/**
  * @param DataTypeDefinition $dataTypeDefinition
  * @param array              $values
  *
  * @return mixed
  */
 public function getClippingDefinition($dataTypeDefinition, $values = array(), $attributes = array())
 {
     if ($this->definition->getPropertyName()) {
         $value = null;
         if (strpos($this->definition->getPropertyName(), '.') !== false) {
             $attribute = array_pop(explode('.', $this->definition->getPropertyName()));
             if (array_key_exists($attribute, $attributes)) {
                 $value = $attributes[$attribute];
             }
         } else {
             if (array_key_exists($this->definition->getPropertyName(), $values)) {
                 $value = $values[$this->definition->getPropertyName()];
             }
         }
         $clippingName = $this->definition->getClippingName($value);
     } else {
         $clippingName = $this->definition->getClippingName();
     }
     if ($dataTypeDefinition->hasClippingDefinition($clippingName)) {
         $clippingDefinition = $dataTypeDefinition->getClippingDefinition($clippingName);
         if ($this->definition->hasWorkspacesRestriction()) {
             if (!in_array($this->context->getCurrentWorkspace(), $this->definition->getWorkspaces())) {
                 return false;
             }
         }
         if ($this->definition->hasLanguagesRestriction()) {
             if (!in_array($this->context->getCurrentLanguage(), $this->definition->getLanguages())) {
                 return false;
             }
         }
         return $clippingDefinition;
     } else {
         return false;
     }
 }
 public function __construct(DataTypeDefinition $definition, $property, $type)
 {
     $this->dataTypeDefinition = $definition;
     if (!$definition->hasProperty($property)) {
         throw new AnyContentClientException('Unknown sequence property ' . $property . ' for data type ' . $definition->getName());
     }
     $this->type = $type;
 }
 public function setProperty($property, $value)
 {
     $property = Util::generateValidIdentifier($property);
     if ($this->dataTypeDefinition->hasProperty($property, $this->view)) {
         $this->properties[$property] = (string) $value;
     } else {
         throw new CMDLParserException('Unknown property ' . $property, CMDLParserException::CMDL_UNKNOWN_PROPERTY);
     }
     return $this;
 }
 /**
  * Creates record object from (array) decoded JSON record (json_decode($json,true))
  *
  * @param DataTypeDefinition $dataTypeDefinition
  * @param                    $jsonRecord
  * @param string             $viewName
  * @param string             $workspace
  * @param string             $language
  *
  * @return Config|Record
  */
 public function createRecordFromJSON(DataTypeDefinition $dataTypeDefinition, $jsonRecord, $viewName = "default", $workspace = "default", $language = "default")
 {
     if ($dataTypeDefinition instanceof ConfigTypeDefinition) {
         $classname = $this->getRecordClassForConfigType($dataTypeDefinition->getName());
         /** @var Config $record */
         $record = new $classname($dataTypeDefinition, $viewName, $workspace, $language);
     } else {
         $classname = $this->getRecordClassForContentType($dataTypeDefinition->getName());
         /** @var Record $record */
         $record = new $classname($dataTypeDefinition, '', $viewName, $workspace, $language);
         $record->setID($jsonRecord['id']);
     }
     $record = $this->finishRecordCreationFromJSON($record, $jsonRecord);
     return $record;
 }
 public function setCurrentDataType(DataTypeDefinition $dataTypeDefinition)
 {
     $this->dataTypeDefinition = $dataTypeDefinition;
     $contentType = $dataTypeDefinition->getTitle();
     if (!$contentType) {
         $contentType = $dataTypeDefinition->getName();
     }
     // check workspaces
     $workspaces = $dataTypeDefinition->getWorkspaces();
     if (!array_key_exists($this->getCurrentWorkspace(), $workspaces)) {
         reset($workspaces);
         list($key, $workspace) = each($workspaces);
         $this->setCurrentWorkspace($key);
         $this->addInfoMessage('Switching to workspace ' . $workspace . ' (' . $key . ') for content type ' . $contentType . '.');
     }
     if ($dataTypeDefinition->hasLanguages()) {
         $languages = $dataTypeDefinition->getLanguages();
     } else {
         $languages = array('default' => 'None');
     }
     if (!array_key_exists($this->getCurrentLanguage(), $languages)) {
         reset($languages);
         list($key, $language) = each($languages);
         $this->setCurrentLanguage($key);
         $this->addInfoMessage('Switching to language ' . $language . ' (' . $key . ') for content type ' . $contentType . '.');
     }
     if (!$dataTypeDefinition->isTimeShiftable() and $this->getCurrentTimeShift() != 0) {
         $this->resetTimeShift();
     }
 }
Пример #6
0
 public static function parseCMDLString($cmdl, $dataTypeName = null, $dataTypeTitle = null, $dataType = 'content')
 {
     switch ($dataType) {
         case 'content':
             $dataTypeDefinition = new ContentTypeDefinition();
             break;
         case 'config':
             $dataTypeDefinition = new ConfigTypeDefinition();
             break;
         case 'data':
             $dataTypeDefinition = new DataTypeDefinition();
             break;
         default:
             throw new CMDLParserException('Unknown data type ' . $dataType . '. Must be one of content,config,data.', CMDLParserException::CMDL_UNKNOWN_DATATYPE);
             break;
     }
     $dataTypeDefinition->setCMDL($cmdl);
     $currentFormElementDefinitionCollection = new ViewDefinition('default', $dataTypeDefinition);
     $dataTypeDefinition->addViewDefinition($currentFormElementDefinitionCollection);
     $cmdl = preg_split('/$\\R?^/m', $cmdl);
     $sectionOpened = false;
     $tabOpened = false;
     $currentTabLabel = '';
     foreach ($cmdl as $line) {
         $line = trim($line);
         if (isset($line[0])) {
             switch ($line[0]) {
                 case '@':
                     // annotation
                     $dataTypeDefinition = self::parseAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $line);
                     break;
                 case '#':
                     // comment
                     break;
                 case ' ':
                     // ignore empty lines
                 // ignore empty lines
                 case '':
                     break;
                 case '=':
                     // start of a view definition
                     if ($tabOpened) {
                         self::closeTab($currentFormElementDefinitionCollection, $currentTabLabel);
                         $tabOpened = false;
                     }
                     $viewName = Util::generateValidIdentifier(trim($line, '-'));
                     if ($viewName == 'default') {
                         // get the already created and added definition of view "default"
                         $currentFormElementDefinitionCollection = $dataTypeDefinition->getViewDefinition('default');
                     } else {
                         $currentFormElementDefinitionCollection = new ViewDefinition($viewName);
                         $dataTypeDefinition->addViewDefinition($currentFormElementDefinitionCollection);
                     }
                     break;
                 case '+':
                     // start of an clipping definition
                     if ($tabOpened) {
                         self::closeTab($currentFormElementDefinitionCollection, $currentTabLabel);
                         $tabOpened = false;
                     }
                     $clippingName = Util::generateValidIdentifier($line);
                     $currentFormElementDefinitionCollection = new ClippingDefinition($clippingName);
                     $dataTypeDefinition->addClippingDefinition($currentFormElementDefinitionCollection);
                     break;
                 case '[':
                     if (substr($line, 0, 3) == '[[[') {
                         $currentTabLabel = rtrim(substr($line, 3), ']');
                         if ($tabOpened === true) {
                             $formElementDefinition = new TabNextFormElementDefinition();
                         } else {
                             $formElementDefinition = new TabStartFormElementDefinition();
                         }
                         $formElementDefinition->setLabel($currentTabLabel);
                         $currentFormElementDefinitionCollection->addFormElementDefinition($formElementDefinition);
                         $tabOpened = true;
                     } elseif (substr($line, 0, 2) == '[[') {
                         if ($sectionOpened === true) {
                             $formElementDefinition = new SectionEndFormElementDefinition();
                             $currentFormElementDefinitionCollection->addFormElementDefinition($formElementDefinition);
                         }
                         $formElementDefinition = new SectionStartFormElementDefinition();
                         if (substr($line, -1) == '+') {
                             $line = substr($line, 0, -1);
                             $formElementDefinition->setOpened(true);
                         }
                         $formElementDefinition->setLabel(rtrim(substr($line, 2), ']'));
                         $currentFormElementDefinitionCollection->addFormElementDefinition($formElementDefinition);
                         $sectionOpened = true;
                     } else {
                         $formElementDefinition = new HeadlineFormElementDefinition();
                         $formElementDefinition->setLabel(rtrim(substr($line, 1), ']'));
                         $currentFormElementDefinitionCollection->addFormElementDefinition($formElementDefinition);
                     }
                     break;
                 case ']':
                     if (substr($line, 0, 3) == ']]]') {
                         self::closeTab($currentFormElementDefinitionCollection, $currentTabLabel);
                         $tabOpened = false;
                         $currentTabLabel = '';
                     } elseif ($sectionOpened === true) {
                         $formElementDefinition = new SectionEndFormElementDefinition();
                         $currentFormElementDefinitionCollection->addFormElementDefinition($formElementDefinition);
                         $sectionOpened = false;
                     }
                     break;
                 case '>':
                     $formElementDefinition = new PrintFormElementDefinition();
                     $p = strpos($line, ' ');
                     $display = '';
                     if ($p) {
                         $display = trim(substr($line, $p));
                     }
                     $formElementDefinition->setDisplay($display);
                     $currentFormElementDefinitionCollection->addFormElementDefinition($formElementDefinition);
                     break;
                 default:
                     $formElementDefinition = self::parseFormElementDefinition($line);
                     $currentFormElementDefinitionCollection->addFormElementDefinition($formElementDefinition);
                     break;
             }
         }
     }
     if ($dataTypeName != '') {
         $dataTypeDefinition->setName($dataTypeName);
     }
     if ($dataTypeTitle != '') {
         $dataTypeDefinition->setTitle($dataTypeTitle);
     }
     if ($tabOpened) {
         self::closeTab($currentFormElementDefinitionCollection, $currentTabLabel);
     }
     return $dataTypeDefinition;
 }