/** * Override default entity saving */ public function save() { // Format url $this->Url = str_replace(' ', '-', utf8_translit($this->Url)); parent::save(); $relationEntity = CMS::MATERIAL_FIELD_RELATION_ENTITY; foreach (static::$fieldIDs as $fieldID => $fieldName) { $type = static::$fieldValueColumns[$fieldID]; // If material field relation exists use it or create new $materialField = null; if (!$this->query->entity($relationEntity)->where(Field::F_PRIMARY, $fieldID)->where(Material::F_PRIMARY, $this->id)->first($materialField)) { /** @var Field $materialfield */ $materialField = new $relationEntity(); $materialField->Active = 1; $materialField->MaterialID = $this->id; $materialField->FieldID = $fieldID; } // Set locale only if this field is localized if (array_key_exists($fieldID, static::$localizedFieldIDs)) { $materialField->locale = $this->locale; } $materialField->{$type} = $this->{$fieldName}; $materialField->save(); } $this->attachTo(static::$navigationIDs); }
/** * Constructor * * @param Form $form Pointer to parent Form * @param FormTab $parent Pointer to parent FormTab */ public function __construct(Form &$form, FormTab &$parent = null) { // Save pointer to Form $this->form =& $form; // Save pointer to parent FormTab $this->parent =& $parent; // Generate identifier if it not passed $this->id = !isset($this->id[0]) ? utf8_translit($this->name) . '_tab' : $this->id; // Add this tab as child $this->tabs[] = $this; }
/** * Constructor * @param Form $form * @param FormTab $parent * @param CMSMaterialField $db_mf * @param string $locale * @param string $field_type */ public function __construct(Form &$form, FormTab &$parent, CMSMaterialField &$db_mf, $locale = null, $field_type = 'WYSIWYG') { // Create CMS Field object from CMSMaterialField object $this->cmsfield = m('samsoncms_input_wysiwyg_application')->createField(new dbQuery(), $db_mf); // Save tab header name as locale name $this->name = $locale; // Generate unique html identifier $this->id = utf8_translit($parent->name) . '_' . $this->name . '_tab'; // Save pointers to database CMSMaterialField object $this->db_mf =& $db_mf; // Call parent parent::__construct($form, $parent); //elapsed($this->content_view.'!!!!!!!!!!!!!!'); // Render CMS Field $this->content_html = m('material')->view($this->content_view)->cmsfield($this->cmsfield)->output(); }
/** * Set parent structure element to work when building catalog tree * @param mixed $name Pointer to structure object or its name for searching/creating * @return \samson\parse\Excel2 Chaining */ public function setStructure($name) { // If passed parent structure does not exists if (!ifcmsnav($name, $cmsnav, 'Name')) { // Create structure $cmsnav = new \samson\cms\cmsnav(false); $cmsnav->Name = $name; $cmsnav->Url = utf8_translit($name); $cmsnav->Active = 1; $cmsnav->Created = date('Y-m-d h:i:s'); $cmsnav->UserID = self::$user->id; $cmsnav->save(); } // Store pointer to parent structure $this->parent_structure =& $cmsnav; return $this; }
/** * 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(); if (isset($user->user_id)) { $entity->UserID = $user->userId; } else { $entity->UserID = '1'; } // 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); }
/** * Recursively create CMSNavigation tree and relations with materials * * @param string $nested_a CMSNav tree * @param array $parents Array of CMSNavs parents chain * @param null $user */ public static function structure_create($nested_a, array $parents = array(), &$user = null) { // Iterate structures array foreach ($nested_a as $k => $v) { // create structure if (is_array($v)) { /** @var \samson\activerecord\Structure $s */ $s = null; $url = utf8_translit($k); // Try to find structure by url if (!dbQuery('structure')->Active(1)->Url($url)->first($s)) { // Create new structure $s = new \samson\activerecord\Structure(false); $s->Name = $k; $s->Active = 1; $s->Url = $url; $s->UserID = $user->id; $s->Created = date('Y-m-d h:i:s'); // Save structure to db $s->save(); } // If parents chain is specified and has data if (sizeof($parents)) { // Get last element from parents chain $parent = end($parents); /** @var \samson\activerecord\structure_relation $str_related */ if ($parent->id != $s->id) { $str_related = new \samson\activerecord\structure_relation(false); $str_related->parent_id = $parent->id; $str_related->child_id = $s->id; $str_related->save(); } } // Add new created structure object to parents chain array_push($parents, $s); // Recursion self::structure_create($v, $parents, $user); // Remove added element from parents chain array_pop($parents); } else { // save structure material foreach ($parents as $parent) { if (!dbQuery('\\samson\\activerecord\\structurematerial')->MaterialID($v->MaterialID)->StructureID($parent['StructureID'])->first($sm)) { $sm = new \samson\activerecord\structurematerial(false); } $sm->MaterialID = $v->MaterialID; $sm->StructureID = $parent['StructureID']; $sm->Active = 1; $sm->save(); } } } }
/** * Generic material table object parser * * @param string $name Material unique identifier * @param null $url * @param int $published * @param int $active * @param int $user_id * * @see \samson\parse\ColumnParser::parser() * @return \samson\activerecord\material Material table object */ public function &parser($name, $data, $url = null, $published = 1, $active = 1, $user_id = null) { $m = null; if ($this->allowEmptyValues || !isset($this->uniques[$name])) { $this->uniques[$name] = ''; $inArrayValue = isset($this->findByField['index']) ? $data[$this->findByField['index']] : $name; if (!in_array($inArrayValue, $this->uniqueArray)) { $m = new \samson\activerecord\material(false); $m->Name = $name; $m->Url = $this->url_prefix . utf8_translit($name); $m->Published = $published; $m->Active = $active; $m->UserID = !isset($user_id) ? Excel2::$user->id : $user_id; $m->save(); } elseif (!empty($this->findByField)) { $m = dbQuery('material')->cond($this->findByField['value'], $data[$this->findByField['index']])->first(); if (!$m) { $m = new \samson\activerecord\material(false); } $m->Name = $name; $m->Url = $this->url_prefix . utf8_translit($name); $m->Published = $published; $m->Active = $active; $m->UserID = !isset($user_id) ? Excel2::$user->id : $user_id; $m->save(); } } else { // Trigger duplicate warning //e('Found duplicate material by ## at ##', D_SAMSON_DEBUG, array($value, $row_idx)); } return $m; }