/** * 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 (empty($fieldValue)) { // Find value in all reserved schemas foreach (Schema::getMaterialSchema() 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->getMainMaterial(); } // 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; }
public function __construct($query) { $this->query = $query; // Get all structures $this->structures = Schema::getMaterialSchema(); // Add structures which not assign to material $this->structures = array_merge($this->structures, Schema::getControlSchema()); }
/** * Universal controller action. * Entity collection rendering */ public function __handler($page = 1) { // Find id main material of main structure $structureID = \samsoncms\seo\schema\Schema::getMainSchema()->getStructureId(); $material = null; if ($this->query->className('structure')->cond('StructureID', $structureID)->first($material)) { // Get id $materialID = $material->MaterialID; // Redirect to seo module url()->redirect($this->system->module('cms')->baseUrl . "/material/form/{$materialID}#seo_field_tab"); } else { //throw new \Exception('Main material of seo module not found'); trace('Main material of seo module not found', 1); } }
/** * Render tags */ public function show() { // Class for work with data $display = new Display($this->query); // Get main material $mainMaterial = $display->getNestedMaterial(Schema::getMainSchema()->getStructure()); // Iterate all reserved schemas and output their data $html = ''; foreach (Schema::getMaterialSchema() as $schema) { // Get current material $material = $display->getMaterialByUrl($display->getItemUrl()); // Exclude publisher if ($schema instanceof \samsoncms\seo\schema\material\Publisher) { continue; } // Out comment $html .= "<!-- {$schema->id} -->"; // Iterate all relations foreach ($schema->relations as $fieldName => $alias) { // trace($fieldName,1); // Find data in hierarchy of structures $content = trim($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(); } // If content not empty render field(meta tag) if (isset($content[0])) { // Save html view $html .= $this->view($schema->view)->name($alias)->content($content)->output() . "\n"; } } } // Get current material $material = $display->getMaterialByUrl($display->getItemUrl()); $dynamic = new Dynamic(); $table = null; if (!empty($material)) { // Get all possible values of tags $table = $material->getTable($dynamic->getStructureId()); } // If there not any values then find them in main material if (empty($table)) { $table = $mainMaterial->getTable($dynamic->getStructureId()); } $html .= '<!-- dynamic tags -->'; // Get full view foreach ($table as $tag) { $html .= $this->view($dynamic->view)->content(array_shift($tag))->output(); } // Get all view of not assigned(single) material $html .= $display->getCommonViews($this); //trace($html,1); // Show result return $this->view($this->viewIndex)->content($html)->output(); }
/** * Get all views which not assign to any material * @param $renderer * @return String */ public function getCommonViews($renderer) { $html = ''; // Get main material $material = $this->getNestedMaterial(Schema::getMainSchema()->getStructure()); // Get all single schemas foreach (array(new Publisher()) as $schema) { // Get relation in schema foreach ($schema->relations as $fieldName => $alias) { // Get value $content = trim($material[$fieldName . '_' . $schema->id]); if (isset($content[0])) { // Render $html .= $renderer->view($schema->view)->name($alias)->content($content)->output() . "\n"; } } } return $html; }