/** * 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; }