} if (count($row['variations'])) { foreach ($row['variations'] as $var) { array_unshift($out[$key][0], calc_bytes($var)); } } if (count($row['skin_variations'])) { foreach ($row['skin_variations'] as $row2) { list($key) = explode('.', $row2['image']); $vars_out[$key] = array($row2['sheet_x'], $row2['sheet_y'], calc_img_has($row2)); } } } $json = pretty_print_json($out); $json_vars = pretty_print_json($vars_out); $json_text = pretty_print_json($text_out); # # calc sheet size # $max = 0; foreach ($d as $row) { $max = max($max, $row['sheet_x']); $max = max($max, $row['sheet_y']); if (count($row['skin_variations'])) { foreach ($row['skin_variations'] as $row2) { $max = max($max, $row2['sheet_x']); $max = max($max, $row2['sheet_y']); } } } $sheet_size = $max + 1;
/** * Process the magic form... * * @return magic_form * @throws exception */ public function _get_magic_form() { if (module_exists('magic_forms')) { $form = new magic_form(); $columns = $this->_interogate_db_for_columns(); foreach ($columns as $column) { // Default type is text. $type = 'magic_form_field_text'; // primary key column is always omitted if ($column['Field'] == $this->get_table_primary_key()) { continue; } // Ignore Auto_Increment primary keys if ($column['Extra'] == 'auto_increment') { continue; } // Ignore logical deletion column if ($column['Field'] == 'deleted') { continue; } // uid column is always invisible if ($column['Field'] == 'uid') { continue; } // Remote key if (isset($column['Constraint'])) { $type = 'magic_form_field_select'; } // Set the value, if set. if (property_exists($this, $column['Field'])) { $value = $this->{$column}['Field']; if (is_array($value) || is_object($value)) { $value = pretty_print_json(json_encode($value)); } } else { $value = null; } // Do something useful with default values. if (isset($column['Default'])) { $default_value = $column['Default']; } else { $default_value = null; } // If the value is long, and the field is a text field, make it a textarea if (strlen($value) > 100 || strpos($value, "\n") !== FALSE) { $type = 'magic_form_field_textarea'; } // Create the new field and add it to the form. /* @var $new_field magic_form_field */ $new_field = new $type(strtolower($column['Field']), $column['Field']); // Remote key options if (isset($column['Constraint'])) { $contraint_options = db_select($column['Constraint']['Table'], 'a')->fields('a', array('name', $column['Constraint']['Column']))->execute()->fetchAll(); foreach ($contraint_options as $contraint_option) { $contraint_option = (array) $contraint_option; $new_field->add_option(reset($contraint_option), end($contraint_option)); } } // Set the value & default $new_field->set_value($value); $new_field->set_default_value($default_value); // Add to the form $form->add_field($new_field); } // Add save button $save = new magic_form_field_submit('save', 'Save', 'Save'); $form->add_field($save); // Sort out passing variables $that = $this; global $user; // Create a simple handler $form->submit(function (magic_form $form) use($that, $user) { $object_type = get_class($that); $object = new $object_type(); /* @var $object active_record */ // Attempt to load by the ID given to us $field = $form->get_field($object->get_table_primary_key()); if ($field instanceof magic_form_field) { $value = $field->get_value(); $object->loadById($value); } // Attempt to read in all the variables foreach ($object->get_table_headings() as $heading) { $field = $form->get_field($heading); if ($field instanceof magic_form_field) { echo $heading; krumo($field); $object->{$heading} = $field->get_value(); } if ($heading == 'uid') { $object->uid = $user->uid; } } // Save object. $object->save(); // If Submit Destination is set, redirect to it. if ($form->get_submit_destination()) { header("Location: {$form->get_submit_destination()}"); exit; } }); // Return the form return $form; } else { throw new exception("Magic forms is not installed, cannot call active_record::magic_form()"); } }