Exemplo n.º 1
0
 /**
  * @param $fid
  * @return __cms_field
  */
 public static function get_field_from_fid($fid)
 {
     if (!isset(self::$cms_fields)) {
         $cms_fields = __cms_field::get_all([]);
         $cms_fields->iterate(function ($object) {
             self::$cms_fields[$object->fid] = $object;
         });
     }
     return isset(self::$cms_fields[$fid]) ? self::$cms_fields[$fid] : false;
 }
Exemplo n.º 2
0
 /**
  *
  */
 public function do_reorder_fields()
 {
     if (isset($_REQUEST['mid']) && isset($_REQUEST['fid'])) {
         $this->set_from_mid($_REQUEST['mid']);
         $fields = object\_cms_field::get_all([], ['where_equals' => ['mid' => $_REQUEST['mid']]]);
         $reverse = false;
         if (isset($_REQUEST['dir']) && $_REQUEST['dir'] == 'down') {
             $reverse = true;
             $fields->reverse();
         }
         $cnt = $reverse ? count($fields) + 1 : 0;
         /** @var object\_cms_field $previous */
         $previous = $fields[0];
         $fields->iterate(function (object\_cms_field $field) use(&$previous, $reverse, &$cnt) {
             $cnt += $reverse ? -1 : 1;
             $field->position = $cnt;
             $field->position = $cnt;
             if ($field->fid == $_REQUEST['fid']) {
                 $field->position = $previous->position;
                 $previous->position = $cnt;
             }
             $previous = $field;
         });
         if ($reverse) {
             $fields->reverse();
         }
         $fields->uasort(function (object\_cms_field $a, object\_cms_field $b) {
             return $a->position - $b->position;
         });
         $cnt = 1;
         $fields->iterate(function (object\_cms_field $field) use(&$cnt) {
             db::update('_cms_field')->add_value('position', $cnt++)->filter_field('fid', $field->fid)->execute();
         });
         table::reset_module_fields($this->module->mid);
         ajax::update($this->module->get_fields_list()->get());
     }
 }
Exemplo n.º 3
0
 public static function rebuild_modules()
 {
     $modules = _cms_module::get_all(_cms_module::$default_fields);
     $fields = _cms_field::get_all(_cms_field::$default_fields);
     $json = [];
     $modules->iterate(function (_cms_module $row) use(&$json) {
         $result = [];
         foreach (_cms_module::$default_fields as $field) {
             $result[$field] = $row->{$field};
         }
         $json[$row->mid] = $result;
     });
     $fields->iterate(function (_cms_field $row) use(&$json) {
         $result = [];
         foreach (_cms_field::$default_fields as $field) {
             $result[$field] = $row->{$field};
         }
         $json[$row->mid]['fields'][$row->field_name] = $result;
     });
     file_put_contents(root . '/.cache/.modules.json', json_encode($json));
 }