Example #1
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();
 }