/** * Returns the {@link $obj} with the parsed NodeSchema attached * * @param ModelObject $obj The object to translate * * @return ModelObject {@link $obj} with the 'Schema' field set. */ public function preCacheTranslateObject(ModelObject $obj) { $plugin = $this->PluginService->getByID($obj->PluginID); if (empty($plugin) || !$plugin->isInstalled() || !$plugin->isEnabled()) { return null; } if ($obj->getXMLSchema() != '') { // resolve schema $schemaXML = "<?xml version='1.0'?><schema>"; $schemaXML .= preg_replace('/\\<\\?xml([^\\>\\/]*)\\>/', '', $obj->getXMLSchema()); $schemaXML .= "</schema>"; try { $schema = $this->NodeSchemaParser->parse($schemaXML); } catch (Exception $e) { throw new SchemaException("Unable to parse schema for aspect [{$obj->Slug}]:\n " . $e->getMessage()); } $obj->setSchema($schema); } else { $obj->setSchema(new NodeSchema()); } return $obj; }
/** * Sets the schema for the element * * @param Element $obj The element to analyze * * @return Element the translated element */ public function preCacheTranslateObject(ModelObject $obj) { // merge aspects //$db = $this->getConnection(); // $q = new Query(); // $q->select('aspectid'); // $q->from('elementaspectrel'); // $q->where("elementid = {$db->quote($obj->{$obj->getPrimaryKey()})}"); // $aspectIDs = $db->readCol($q); // $this->populateRels(); // $aspectSlugs = array_key_exists($obj->Slug, $this->aspectrel)?$this->aspectrel[$obj->Slug]['Aspects']:array(); $aspectSlugs = $obj->getAspectSlugs(); $schema = new NodeSchema(); if (!empty($aspectSlugs)) { $aspects = $this->AspectDAO->multiGetBySlug($aspectSlugs); $newAspects = array(); foreach ($aspects as $aspect) { // $plugin = $this->PluginService->getByID($aspect['PluginID']); // if(empty($plugin) || !$plugin->isInstalled() || !$plugin->isEnabled()) // continue; $aspectSchema = $aspect->getSchema(); foreach ($aspectSchema->getTagDefs() as $tagDef) { $schema->addTagDef($tagDef); } foreach ($aspectSchema->getMetaDefs() as $metaDef) { $schema->addMetaDef($metaDef); } $newAspects[] = $aspect; } $obj->setAspects($newAspects); } $obj->setSchema($schema); $obj->setAnchoredSite($this->SiteService->getAnchoredSite()); $obj->setAnchoredSiteSlug($obj->getAnchoredSite()->getSlug()); return $obj; }