Example #1
0
 /**
  * Create structurefield database record
  * @param \samson\activerecord\structure $structure Pointer to structure record
  * @param \samson\activerecord\field     $field     Pointer to field record
  *
  * @return \samson\activerecord\structurefield Create StructureField record
  */
 public static function structurefield_create(\samson\activerecord\structure $structure, \samson\activerecord\field &$field)
 {
     // Connect material field to structure
     $sf = new \samson\activerecord\structurefield(false);
     $sf->StructureID = $structure->StructureID;
     $sf->FieldID = $field->id;
     $sf->Active = 1;
     $sf->save();
     return $sf;
 }
Example #2
0
 /**
  * Updating field and creating relation with structure
  * @param int $structureID
  */
 public function update($structureID = 0)
 {
     // Fill the fields from $_POST array
     foreach ($_POST as $key => $val) {
         $this[$key] = $val;
     }
     $this->save();
     /** @var \samson\cms\web\navigation\CMSNav $cmsnav */
     // If isset current structure
     if (dbQuery('\\samson\\cms\\web\\navigation\\CMSNav')->id($structureID)->first($cmsnav)) {
         // If structure has not relation with current field
         if (!dbQuery('structurefield')->StructureID($cmsnav->id)->FieldID($this->id)->first()) {
             // Create new relation between structure and field
             $strField = new \samson\activerecord\structurefield(false);
             $strField->FieldID = $this->id;
             $strField->StructureID = $cmsnav->id;
             $strField->Active = 1;
             // Save relation
             $strField->save();
         }
     }
 }
Example #3
0
 /** Override generic column parser initialization */
 public function init()
 {
     // This is very important
     if (!isset($this->name[0])) {
         return e('Cannot create MaterialField - no name is passed', E_SAMSON_FATAL_ERROR);
     }
     // Try to find field record
     if (!SamsonCMS::find('field', $this->name, $this->db_field)) {
         // Create new field record
         $this->db_field = new \samson\activerecord\field(false);
         $this->db_field->Name = $this->name;
         $this->db_field->Active = 1;
         $this->db_field->Description = $this->description;
         $this->db_field->Value = $this->defaultValue;
         $this->db_field->Type = $this->type;
         // Set field localization if necessary
         if (isset($this->locale)) {
             $this->db_field->local = 1;
         }
         $this->db_field->save();
     }
     // Try to find structure
     if (SamsonCMS::find('structure', $this->parentStructure, $this->parentStructure)) {
         // Is this field is not connect with this structure already
         $fields = null;
         if (!dbQuery('structurefield')->StructureID($this->parentStructure->StructureID)->FieldID($this->db_field->id)->exec($fields)) {
             // Connect material field to structure
             $sf = new \samson\activerecord\structurefield(false);
             $sf->StructureID = $this->parentStructure->StructureID;
             $sf->FieldID = $this->db_field->id;
             $sf->Active = 1;
             $sf->save();
         }
     }
     parent::init();
 }
Example #4
0
 public function materialColumnToField($column, $structure)
 {
     // Find first user
     $user = null;
     if (dbQuery('user')->first($user)) {
     }
     // Create structure for all materials
     $db_structure = null;
     if (!dbQuery('structure')->Url('__' . $structure)->cond('Active', 1)->first($db_structure)) {
         $db_structure = new \samson\activerecord\structure(false);
         $db_structure->Name = $structure;
         $db_structure->Url = '__' . $structure;
         $db_structure->Active = 1;
         $db_structure->UserID = $user->id;
         $db_structure->system = 1;
         $db_structure->save();
     }
     $dbField = null;
     if (!dbQuery('field')->Name($column)->first($dbField)) {
         $dbField = new \samson\activerecord\field(false);
         $dbField->Name = $column;
         $dbField->Type = 8;
         $dbField->Active = 1;
         $dbField->system = 1;
         $dbField->save();
     }
     // Create structure field relations
     $db_sf = null;
     if (!dbQuery('structurefield')->FieldID($dbField->id)->StructureID($db_structure->id)->cond('Active', 1)->first($db_sf)) {
         $db_sf = new \samson\activerecord\structurefield(false);
         $db_sf->FieldID = $dbField->id;
         $db_sf->StructureID = $db_structure->id;
         $db_sf->Active = 1;
         $db_sf->save();
     }
     // Iterate all existing materials
     $db_materials = array();
     if (dbQuery('material')->cond('Active', '1')->Draft('0')->exec($db_materials)) {
         trace('Found materials:' . sizeof($db_materials));
         foreach ($db_materials as $db_material) {
             //trace('Updating material:'.$db_material->id);
             // If current material has no connection with new structure
             $db_sm = null;
             if (!dbQuery('structurematerial')->StructureID($db_structure->id)->MaterialID($db_material->id)->first($db_sm)) {
                 // Create this connection
                 $db_sm = new \samson\activerecord\structurematerial(false);
                 $db_sm->StructureID = $db_structure->id;
                 $db_sm->MaterialID = $db_material->id;
                 $db_sm->Active = 1;
                 $db_sm->save();
                 //trace('Updating structurematerial:'.$db_material->id);
             }
             // If this material has no Content field right now
             $db_mf = null;
             if (!dbQuery('materialfield')->MaterialID($db_material->id)->FieldID($dbField->id)->cond('Active', 1)->first($db_mf)) {
                 // Create Content additional field
                 $db_mf = new \samson\activerecord\materialfield(false);
                 $db_mf->MaterialID = $db_material->id;
                 $db_mf->FieldID = $dbField->id;
                 $db_mf->Active = 1;
                 $db_mf->Value = $db_material[$column];
                 $db_mf->save();
                 //trace('Updating materialfield:'.$db_material->id);
             }
         }
     }
     db()->query('ALTER TABLE  `material` DROP  `' . $column . '`');
 }
Example #5
0
 /**
  * Assign field to the structure
  * @param $structureId
  * @param $fieldId
  * @return \samson\activerecord\structurefield
  */
 public function assignFieldToStructure($structureId, $fieldId)
 {
     // Save value of field
     $structureField = new \samson\activerecord\structurefield(false);
     $structureField->StructureID = $structureId;
     $structureField->FieldID = $fieldId;
     $structureField->Active = 1;
     $structureField->save();
     return $structureField;
 }
Example #6
0
 public function __async_saveexisted($structure_id = null)
 {
     $fields = explode(',', $_POST['_orderfield']);
     array_pop($fields);
     if (count($fields)) {
         foreach ($fields as $field) {
             if (!$this->query->entity('\\samson\\activerecord\\structurefield')->where('StructureID', $structure_id)->where('FieldID', $field)->first()) {
                 $relation = new \samson\activerecord\structurefield();
                 $relation->StructureID = $structure_id;
                 $relation->FieldID = $field;
                 $relation->Active = 1;
                 $relation->save();
             }
         }
     }
     return $this->__async_renderfields($structure_id);
 }