function assetTreeSwitchDataDefinitionForBlock(aohs\AssetOperationHandlerService $service, p\Child $child, $params = NULL, &$results = NULL) { global $common_assets_site_name; $type = $child->getType(); if ($type != a\DataBlock::TYPE) { return; } if (!isset($params["cascade"])) { throw new \Exception("The Cascade object is not supplied"); } else { $cascade = $params["cascade"]; } $block = $child->getAsset($service); $b_name = $block->getName(); if ($b_name == "_footer-contact") { $dd_name = "Footer Contact"; } elseif ($b_name == "_left-column") { $dd_name = "Left Column"; } elseif ($b_name == "_right-column") { $dd_name = "Right Column"; } elseif ($b_name == "_site-info") { $dd_name = "Site Info"; } else { return; } $dd = $cascade->getAsset(a\DataDefinition::TYPE, $dd_name, $common_assets_site_name); $st = new p\StructuredData($dd->getStructuredData(), $service, $dd->getId()); $identifiers = $block->getIdentifiers(); foreach ($identifiers as $identifier) { // create the correct number of instances for multiple field if (u\StringUtility::endsWith($identifier, ";0") && $st->hasIdentifier($identifier)) { $st->createNInstancesForMultipleField($block->getNumberOfSiblings($identifier), $identifier); } // map the data if ($st->hasNode($identifier) && $block->isTextNode($identifier)) { $st->setText($identifier, $block->getText($identifier)); } elseif ($st->hasNode($identifier) && $block->isAssetNode($identifier)) { $asset_node_type = $block->getAssetNodeType($identifier); if ($asset_node_type == "page" && $block->getPageId($identifier) != null) { $st->setPage($identifier, $cascade->getPage($block->getPageId($identifier))); } elseif ($asset_node_type == "file" && $block->getFileId($identifier) != null) { $st->setFile($identifier, $cascade->getFile($block->getFileId($identifier))); } elseif ($asset_node_type == "block" && $block->getBlockId($identifier) != null) { $st->setBlock($identifier, a\Block::getBlock($service, $block->getBlockId($identifier))); } elseif ($asset_node_type == "page,file,symlink" && $block->getLinkableId($identifier) != null) { $st->setLinkable($identifier, a\Linkable::getLinkable($service, $block->getLinkableId($identifier))); } } } $block->setStructuredData($st); }
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 setLinkable(a\Linkable $linkable = NULL) { // required if ($this->required && $linkable == NULL) { throw new e\EmptyValueException(S_SPAN . c\M::NULL_LINKABLE . E_SPAN); } if ($this->asset_type != c\T::PFS) { throw new e\NodeException(S_SPAN . "The asset does not accept a linkable." . E_SPAN); } if (isset($linkable)) { $type = $linkable->getType(); if ($type == c\T::FILE) { $this->file_id = $linkable->getId(); $this->file_path = $linkable->getPath(); $this->page_id = NULL; $this->page_path = NULL; $this->symlink_id = NULL; $this->symlink_path = NULL; } else { if ($type == c\T::PAGE) { $this->page_id = $linkable->getId(); $this->page_path = $linkable->getPath(); $this->file_id = NULL; $this->file_path = NULL; $this->symlink_id = NULL; $this->symlink_path = NULL; } else { if ($type == c\T::SYMLINK) { $this->symlink_id = $linkable->getId(); $this->symlink_path = $linkable->getPath(); $this->file_id = NULL; $this->file_path = NULL; $this->page_id = NULL; $this->page_path = NULL; } } } } else { $this->file_id = NULL; $this->file_path = NULL; $this->page_id = NULL; $this->page_path = NULL; $this->symlink_id = NULL; $this->symlink_path = NULL; } return $this; }
echo $page->getCreatedDate(), BR; //u\DebugUtility::dump( $page->getDynamicField( "exclude-from-menu" ) ); //u\DebugUtility::dump( $page->getDynamicFields() ); echo u\StringUtility::getCoalescedString( $page->getExpirationFolderId() ), BR; echo u\StringUtility::getCoalescedString( $page->getExpirationFolderPath() ), BR; echo u\StringUtility::boolToString( $page->getExpirationFolderRecycled() ), BR; echo $page->getLastModifiedBy(), BR; echo $page->getLastModifiedDate(), BR; */ //u\DebugUtility::dump( $page->getMetadata() ); //$page->getMetadataSet()->dump(); //echo u\StringUtility::getCoalescedString( $page->getMetadataSetId() ), BR; //echo u\StringUtility::getCoalescedString( $page->getMetadataSetPath() ), BR; //u\DebugUtility::dump( $page->getMetadataStdClass() ); //echo u\StringUtility::boolToString( $page->hasDynamicField( "exclude-from-menu" ) ), BR; /* $page->setExpirationFolder( $cascade->getAsset( a\Folder::TYPE, "39d53a118b7ffe834c5fe91e7e2e0cd9" ) )->edit(); */ //$page->setMetadata( $page->getMetadata() ); //$page->setMetadataSet( $cascade->getAsset( //a\MetadataSet::TYPE, "35963bf48b7ffe83164c931407216994" ) ); //echo a\Linkable::getLinkableType( $service, "06a23e5b8b7ffe830820c9fac501387b" ), BR; a\Linkable::getLinkable($service, "06a23e5b8b7ffe830820c9fac501387b")->dump(); } catch (\Exception $e) { echo S_PRE . $e . E_PRE; } catch (\Error $er) { echo S_PRE . $er . E_PRE; }
private static function copyData($source, StructuredData $target, $id) { if (!$source instanceof StructuredData && !$source instanceof StructuredDataPhantom) { throw new \Exception("Wrong source type"); } if ($source->isTextNode($id) || $source->isWYSIWYG($id)) { $target->setText($id, $source->getText($id)); if ($target->getText($id) == NULL) { $target->setText($id, ""); } } elseif ($source->isAssetNode($id)) { $asset_type = $source->getAssetNodeType($id); try { switch ($asset_type) { case c\T::PAGE: $page_id = $source->getPageId($id); if (isset($page_id)) { $target->setPage($id, $source->getService()->getAsset($source->getService()->createId(a\Page, $page_id))); } break; case c\T::FILE: $file_id = $source->getFileId($id); if (isset($file_id)) { $target->setFile($id, $source->getService()->getAsset($source->getService()->createId(a\File, $file_id))); } break; case c\T::BLOCK: $block_id = $source->getBlockId($id); if (isset($block_id)) { $target->setBlock($id, a\Block::getBlock($target->getService(), $block_id)); } break; case c\T::SYMLINK: $symlink_id = $source->getSymlinkId($id); if (isset($symlink_id)) { $target->setSymlink($id, $source->getService()->getAsset($source->getService()->createId(a\Symlink, $symlink_id))); } break; case c\T::PFS: $linkable_id = $source->getLinkableId($id); if (isset($linkable_id)) { $target->setLinkable($id, a\Linkable::getLinkable($source->getService(), $linkable_id)); } break; } } catch (e\NoSuchTypeException $e) { // do nothing to skip deleted blocks } } }