Beispiel #1
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 . '`');
 }
Beispiel #2
0
 /**
  * Create structure and if isset parent structure assign it to them
  * @param $name
  * @param $url
  * @param int $type
  * @param int $parentId
  * @return \samson\activerecord\structure
  */
 public function createStructure($name, $url, $type = self::NESTED_MATERIAL_TYPE_STRUCTURE, $parentId = 0)
 {
     $structure = new \samson\activerecord\structure(false);
     $structure->Name = $name;
     $structure->Url = $url;
     $structure->Active = 1;
     $structure->type = $type;
     $structure->system = 1;
     $structure->hidden = 1;
     $structure->ParentID = $parentId;
     $structure->save();
     // Create structure relation if this structure have to be child
     if ($parentId != 0) {
         $structureRelation = new \samson\activerecord\structure_relation(false);
         $structureRelation->child_id = $structure->StructureID;
         $structureRelation->parent_id = $parentId;
         $structureRelation->save();
     }
     return $structure;
 }