/** * Add new structure to entity * @param int $navigation Parent navigation identifier */ public function __async_addnav($materialId = null, $navigation = null) { // Save record // $sm = new CMSNavMaterial(false); $sm = new NavigationMaterial(); $sm->MaterialID = $materialId; $sm->StructureID = $navigation; $sm->Active = '1'; $sm->save(); }
/** * New material entity creation controller action * @param int $navigation Parent navigation identifier */ public function __new($navigation = array()) { // Create new entity $entity = new Material(); $entity->Active = 1; $entity->Created = date('Y-m-d H:m:s'); // Set user $user = $this->system->module('social')->user(); $entity->UserID = $user->user_id; // Persist $entity->save(); // Set name for created material $entity->Name = t($this->name, true) . ' №' . $entity->id; $entity->Url = utf8_translit($entity->Name); // Check unique url for material if ($this->query->entity(Material::class)->where(Material::F_IDENTIFIER, utf8_translit($entity->Name))->first()) { $entity->Url = md5(utf8_translit($entity->Name)); } // Persist $entity->save(); Event::fire('samsoncms.app.material.new', array(&$entity)); $navigation = is_array($navigation) ? $navigation : array($navigation); // Set navigation relation foreach (array_merge($navigation, static::$structures) as $structureID) { // Create relation with structure $structureMaterial = new NavigationMaterial(); $structureMaterial->MaterialID = $entity->id; $structureMaterial->StructureID = $structureID; $structureMaterial->Active = '1'; $structureMaterial->save(); } // Go to correct form URL url()->redirect($this->system->module('cms')->baseUrl . '/' . $this->id . '/form/' . $entity->id); }