/** * Get data from hierarchy of inheritance * @param $schema * @param $fieldName * @param $material * @param bool $deep search in parent structures then change current material to parent * @return null * @throws \Exception */ public function getFieldBySchema($schema, $fieldName, $material, $deep = false) { // Set field name with prefix of schema $fieldNameFull = $fieldName . '_' . $schema->id; $fieldValue = $this->getDataField($fieldNameFull, $material); // If in the current schema need value wasn't found then find in sibling schemas if ($fieldValue == null) { // Find value in all reserved schemas foreach (Schema::getSchemas() as $schemaFind) { // If it is not deep search then avoid equal schema if ($schema->id == $schemaFind->id && $deep == false) { continue; } // Set field name with prefix of schema $fieldNameFull = $fieldName . '_' . $schemaFind->id; // If it is deep search i.e search in parent structures then change current material to parent if ($deep == true) { $material = $this->getNestedMaterial($schemaFind->getStructure()); } // Get data from material $fieldValue = $this->getDataField($fieldNameFull, $material); // End if value was found if (!empty($fieldValue)) { return $fieldValue; } } // Valued was not found return null; } return $fieldValue; }
/** * Render tags */ public function __handler() { // Class for work with data $display = new Display($this->query); // Iterate all reserved schemas and output their data $html = ''; foreach (Schema::getSchemas() as $schema) { // Get current material $material = $display->getMaterialByUrl($display->getItemUrl()); // Out comment $html .= "<!-- {$schema->id} -->"; // Iterate all relations foreach ($schema->relations as $fieldName => $alias) { // Find data in hierarchy of structures $content = $display->findField($schema, $fieldName, $material); // EXCLUDE Render title of page if ($schema->id == 'meta' && $fieldName == '__SEO_Title') { $html .= $this->view($this->viewTitle)->title($content)->output(); } // Save html view $html .= $this->view($schema->view)->name($alias)->content($content)->output() . "\n"; } } // Show result $this->view($this->viewIndex)->content($html); }
public function __construct($query) { $this->query = $query; // Get all structures $this->structures = \samson\cms\seo\schema\Schema::getSchemas(); }