public function setMetadataMapping(ContentType $ct, $name, $value) { if ($ct == NULL) { throw new e\NullAssetException(S_SPAN . c\M::NULL_CONTENT_TYPE . E_SPAN); } if ($name != self::TAGS && $name != self::CATEGORIES) { throw new e\UnacceptableValueException(S_SPAN . "The name {$name} is not acceptable." . E_SPAN); } $links = $this->getConnectorContentTypeLinks(); foreach ($links as $link) { if ($link->getContentTypeId() == $ct->getId()) { $link->setMetadataMapping($name, $value); return $this; } } throw new \Exception(S_SPAN . "The content does not exist in the connector." . E_SPAN); }
public function createWordPressConnector(ConnectorContainer $parent, $name, $url, ContentType $ct, $page_config) { if (trim($name) == "") { throw new e\CreationErrorException(S_SPAN . c\M::EMPTY_CONNECTOR_NAME . E_SPAN); } if (trim($url) == "") { throw new e\CreationErrorException(S_SPAN . c\M::EMPTY_PAGE_NAME . E_SPAN); } if (trim($page_config) == "") { throw new e\CreationErrorException(S_SPAN . c\M::EMPTY_CONFIGURATION_NAME . E_SPAN); } $asset = AssetTemplate::getWordPressConnector(); $asset->wordPressConnector->name = $name; $asset->wordPressConnector->parentContainerPath = $parent->getPath(); $asset->wordPressConnector->siteName = $parent->getSiteName(); $asset->wordPressConnector->url = trim($url); $asset->wordPressConnector->connectorContentTypeLinks->connectorContentTypeLink->contentTypeId = $ct->getId(); $asset->wordPressConnector->connectorContentTypeLinks->connectorContentTypeLink->pageConfigurationName = $page_config; if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($asset); } return $this->createAsset($asset, WordPressConnector::TYPE, $this->getPath($parent, $name), $parent->getSiteName()); }
public function setContentType(ContentType $content_type) { if ($this->getIndexBlockType() != c\T::CONTENTTYPEINDEX) { throw new \Exception(S_SPAN . "This block is not a content type index block." . E_SPAN); } $this->getProperty()->indexedContentTypeId = $content_type->getId(); $this->getProperty()->indexedContentTypePath = $content_type->getPath(); return $this; }
public function setContentType(ContentType $c, $exception = true) { // nothing to do if already set if ($c->getId() == $this->getContentType()->getId()) { echo "Nothing to do" . BR; return $this; } // part 1: get the page level blocks and formats $block_format_array = $this->getPageLevelRegionBlockFormat(); // just the default config, other config can be added $default_configuration = $this->getContentType()->getConfigurationSet()->getDefaultConfiguration(); $default_configuration_name = $default_configuration->getName(); $default_config_page_regions = $default_configuration->getPageRegions(); $default_region_names = $default_configuration->getPageRegionNames(); $page_level_config = $this->page_configuration_map[$default_configuration_name]; $page_level_regions = $page_level_config->getPageRegions(); $page_region_names = $page_level_config->getPageRegionNames(); if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($block_format_array); } // part 2: switch content type if ($c == NULL) { throw new e\NullAssetException(S_SPAN . c\M::NULL_ASSET . E_SPAN); } $page = $this->getProperty(); $page->contentTypeId = $c->getId(); $page->contentTypePath = $c->getPath(); $configuration_array = array(); $new_configurations = $c->getPageConfigurationSet()->getPageConfigurations(); foreach ($new_configurations as $new_configuration) { $configuration_array[] = $new_configuration->toStdClass(); } $page->pageConfigurations->pageConfiguration = $configuration_array; if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($page->pageConfigurations); } $asset = new \stdClass(); $asset->{$p = $this->getPropertyName()} = $page; // edit asset $service = $this->getService(); $service->edit($asset); if (!$service->isSuccessful()) { throw new e\EditingFailureException(S_SPAN . c\M::EDIT_ASSET_FAILURE . E_SPAN . $service->getMessage()); } if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($this->getProperty()->pageConfigurations); } $this->reloadProperty(); $this->processPageConfigurations($this->getProperty()->pageConfigurations->pageConfiguration); $this->content_type = $c; parent::setPageContentType($this->content_type); if (isset($this->getProperty()->structuredData)) { $this->data_definition_id = $this->content_type->getDataDefinitionId(); // structuredDataNode could be empty for xml pages if (isset($this->getProperty()->structuredData) && isset($this->getProperty()->structuredData->structuredDataNodes) && isset($this->getProperty()->structuredData->structuredDataNodes->structuredDataNode)) { if ($exception) { // defaulted to true $this->processStructuredData($this->data_definition_id); } } } else { $this->xhtml = $this->getProperty()->xhtml; } // part 3: plug the blocks and formats back in $count = count(array_keys($block_format_array)); if ($count > 0) { $service = $this->getService(); $page_level_config = $this->page_configuration_map[$default_configuration_name]; $page_region_names = $page_level_config->getPageRegionNames(); if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($page_region_names); } foreach ($block_format_array as $region => $block_format) { // only if the region exists in the current config if (in_array($region, $page_region_names)) { if (isset($block_format['block'])) { $block_id = $block_format['block']; } if (isset($block_format['format'])) { $format_id = $block_format['format']; } if (isset($block_id)) { $block = $this->getAsset($service, $service->getType($block_id), $block_id); $this->setRegionBlock($default_configuration_name, $region, $block); } else { if (isset($block_format['no-block'])) { $this->setRegionNoBlock($default_configuration_name, $region, true); } } if (isset($format_id)) { $format = $this->getAsset($service, $service->getType($format_id), $format_id); $this->setRegionFormat($default_configuration_name, $region, $format); } else { if (isset($block_format['no-format'])) { $this->setRegionNoFormat($default_configuration_name, $region, true); } } } } if ($exception) { $this->edit(); } else { $this->editWithoutException(); } } $page = $this->getProperty(); if (self::DEBUG && self::DUMP) { u\DebugUtility::dump($page->pageConfigurations); } return $this; }
public function removeContentTypeLink(ContentType $ct) { if ($this->getPropertyName() == c\P::GOOGLEANALYTICSCONNECTOR) { throw new \Exception(S_SPAN . c\M::GOOGLE_CONNECTOR_NO_CT . E_SPAN); } $temp = array(); foreach ($this->connector_content_type_links as $link) { // link exist if ($link->getContentTypeId() != $ct->getId()) { $temp[] = $link; } } $this->connector_content_type_links = $temp; return $this; }