Esempio n. 1
0
 public static function create($field_name, $structure, $module)
 {
     $field = new __cms_field();
     $field->do_retrieve([], ['where_equals' => ['mid' => $module, 'field_name' => $field_name]]);
     if (!$field->get_primary_key()) {
         $field->field_name = $field_name;
         $field->mid = $module;
         $field->type = $structure->type;
         $field->title = isset($structure->title) ? $structure->title : ucwords(str_replace('_', ' ', $field_name));
         if (isset($structure->module) && $structure->module) {
             $_module = new __cms_module();
             $_module->do_retrieve(['mid'], ['where_equals' => ['table_name' => $structure->module]]);
             $field->link_module = $_module->mid;
             if (isset($structure->field) && $structure->field) {
                 $_field = new __cms_field();
                 $_field->do_retrieve(['fid'], ['where_equals' => ['field_name' => $structure->field, 'mid' => $_module->mid]]);
                 if ($_field->get_primary_key()) {
                     $field->link_field = $_field->fid;
                 }
             }
         }
         $field->list = isset($structure->list) ? $structure->list : true;
         $field->filter = isset($structure->filter) ? $structure->filter : true;
         $field->required = isset($structure->required) ? $structure->required : true;
         $field->do_save();
     } else {
         throw new \Exception('Field ' . $field_name . ' already exists in module ' . $module);
     }
     return $field;
 }
Esempio n. 2
0
 public static function modify_link_field($source_field, $destination_module, $destination_field)
 {
     if (!$source_field->link_module) {
         $link_cms_module = new _cms_module();
         $link_cms_module->do_retrieve([], ['where_equals' => ['table_name' => $destination_module]]);
         if ($link_cms_module->get_primary_key()) {
             $source_field->link_module = $link_cms_module->get_primary_key();
         } else {
             try {
                 self::create_from_structure($destination_module);
             } catch (\Exception $e) {
                 die('Missing dependency: ' . $destination_module);
             }
         }
     }
     if (!$source_field->link_field) {
         $link_cms_field = new _cms_field();
         $link_cms_field->do_retrieve([], ['where_equals' => ['mid' => $source_field->link_module, 'field_name' => $destination_field]]);
         if ($link_cms_field->get_primary_key()) {
             $source_field->link_field = $link_cms_field->get_primary_key();
         }
     }
     $source_field->do_save();
 }