public function apply() { if ($this->hasParam(1)) { $this->dataTypeDefinition->setNamingPattern($this->getParam(1)); } else { throw new CMDLParserException('Missing mandatory parameter title for annotation @title.', CMDLParserException::CMDL_MISSING_MANDATORY_PARAM); } return $this->dataTypeDefinition; }
public function getSubtypeLabel() { $subtypesList = $this->dataTypeDefinition->getSubtypes(); if ($subtypesList) { if (array_key_exists($this->getProperty('subtype'), $subtypesList)) { return $subtypesList[$this->getProperty('subtype')]; } } return null; }
public function getContentViews(Repository $repository, ContentTypeDefinition $contentTypeDefinition, $contentTypeAccessHash) { if (!array_key_exists($contentTypeAccessHash, $this->contentViewObjects)) { $i = 0; $this->contentViewObjects[$contentTypeAccessHash] = array(); /** @var $customAnnotation CustomAnnotation */ foreach ($contentTypeDefinition->getCustomAnnotations() as $customAnnotation) { if ($customAnnotation->getType() == 'content-view') { if ($customAnnotation->hasParam(1)) { $i++; $type = $customAnnotation->getParam(1); if (array_key_exists($type, $this->contentViewRegistrations)) { $class = $this->contentViewRegistrations[$type]['class']; $contentView = new $class($i, $this->app, $repository, $contentTypeDefinition, $contentTypeAccessHash, $customAnnotation, $this->contentViewRegistrations[$type]['options']); $this->contentViewObjects[$contentTypeAccessHash][$i] = $contentView; } } } } } return $this->contentViewObjects[$contentTypeAccessHash]; }
public static function normalizeFilterQuery(Application $app, $query, ContentTypeDefinition $contentTypeDefinition) { $query = str_replace('><', '*=', $query); try { $condition = self::parseCondition($query); if (is_array($condition) && count($condition) == 3) { $property = Util::generateValidIdentifier($condition[0]); if (!$contentTypeDefinition->hasProperty($property)) { $app['context']->addAlertMessage('Cannot filter by property ' . $property . '.'); $query = ''; } } else { $query = 'name *= ' . $query; } $filter = new PropertyFilter($query); } catch (\Exception $e) { $app['context']->addAlertMessage('Could not parse query.'); $app['context']->setCurrentSearchTerm(''); //$query = ''; $filter = ''; } //$app['context']->setCurrentSearchTerm($query); return $filter; }
public function createRecord(ContentTypeDefinition $contentTypeDefinition, $properties = [], $viewName = "default", $workspace = "default", $language = "default") { $classname = $this->getRecordClassForContentType($contentTypeDefinition->getName()); /** @var Record $record */ $record = new $classname($contentTypeDefinition, '', $viewName, $workspace, $language); $revision = isset($jsonRecord['revision']) ? $jsonRecord['revision'] : 0; $record->setRevision($revision); if ($this->getOption('validateProperties') == true) { foreach ($properties as $property => $value) { $record->setProperty($property, $value); } } else { $record->setProperties($properties); } return $record; }
public function refreshContentTypeTableStructure($repositoryName, ContentTypeDefinition $contentTypeDefinition) { $this->refreshInfoTablesStructure(); $contentTypeName = $contentTypeDefinition->getName(); $tableName = $repositoryName . '$' . $contentTypeName; if ($tableName != Util::generateValidIdentifier($repositoryName) . '$' . Util::generateValidIdentifier($contentTypeName)) { throw new \Exception('Invalid repository and/or content type name(s).', self::INVALID_NAMES); } /** @var PDO $db */ $dbh = $this->app['db']->getConnection(); $sql = 'Show Tables Like ?'; $stmt = $dbh->prepare($sql); $stmt->execute(array($tableName)); if ($stmt->rowCount() == 0) { $sql = <<<TEMPLATE_CONTENTTABLE CREATE TABLE %s ( `id` int(11) unsigned NOT NULL, `hash` varchar(32) NOT NULL, `property_name` varchar(255) DEFAULT NULL, `workspace` varchar(255) NOT NULL DEFAULT 'default', `language` varchar(255) NOT NULL DEFAULT 'default', `property_subtype` varchar(255) DEFAULT NULL, `property_status` varchar(255) DEFAULT '1', `parent_id` int(11) DEFAULT NULL, `position` int(11) DEFAULT NULL, `position_left` int(11) DEFAULT NULL, `position_right` int(11) DEFAULT NULL, `position_level` int(11) DEFAULT NULL, `revision` int(11) DEFAULT NULL, `deleted` tinyint(1) DEFAULT '0', `creation_timestamp` int(11) DEFAULT NULL, `creation_apiuser` varchar(255) DEFAULT NULL, `creation_clientip` varchar(255) DEFAULT NULL, `creation_username` varchar(255) DEFAULT NULL, `creation_firstname` varchar(255) DEFAULT NULL, `creation_lastname` varchar(255) DEFAULT NULL, `lastchange_timestamp` int(11) DEFAULT NULL, `lastchange_apiuser` varchar(255) DEFAULT NULL, `lastchange_clientip` varchar(255) DEFAULT NULL, `lastchange_username` varchar(255) DEFAULT NULL, `lastchange_firstname` varchar(255) DEFAULT NULL, `lastchange_lastname` varchar(255) DEFAULT NULL, `validfrom_timestamp` varchar(16) DEFAULT NULL, `validuntil_timestamp` varchar(16) DEFAULT NULL, KEY `id` (`id`), KEY `workspace` (`workspace`,`language`), KEY `validfrom_timestamp` (`validfrom_timestamp`,`validuntil_timestamp`,`id`,`deleted`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; TEMPLATE_CONTENTTABLE; $sql = sprintf($sql, $tableName); $stmt = $dbh->prepare($sql); try { $stmt->execute(); } catch (\PDOException $e) { return false; } } $sql = sprintf('DESCRIBE %s', $tableName); $stmt = $dbh->prepare($sql); $stmt->execute(); $fields = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0); $properties = array(); foreach ($contentTypeDefinition->getProperties() as $property) { $properties[] = 'property_' . $property; } $newfields = array(); foreach (array_diff($properties, $fields) as $field) { $newfields[] = 'ADD COLUMN `' . $field . '` LONGTEXT'; } if (count($newfields) != 0) { $sql = sprintf('ALTER TABLE %s', $tableName); $sql .= ' ' . join($newfields, ','); $stmt = $dbh->prepare($sql); $stmt->execute(); } return true; }