36
tdmcreate 1.91
download from github, 11.08.2014 12:50
Xoops 2.5.7.
1) you can select "Table: Main Field" for each field
2) if you are on tab "tables", than select a module and click than on "Edit fields" for a specific table, you do not get the field edit mode.
change \templates\admin\tdmcreate_tables.tpl line 86 from
<a href="fields.php?op=edit&field_tid=<{$table.id}>" title="<{$smarty.const._EDIT}>">
into
[code]<a href="fields.php?op=edit&field_tid=<{$table.id}>&field_mid=<{$table.mid}>" title="<{$smarty.const._EDIT}>">
or change fields.php, because there is a module id neccessary in line 242
3) you create a new table and define 4 fields for this table. if yo later change the number of fields, e.g. you say now 5, you get only 4 fields in editing mode of table fields
following code of class/fields.php can solve this problem - all changes are marked with 'goffy'
/*
* @Class TDMCreateFields
* @extends XoopsObject
*/
class TDMCreateFields extends XoopsObject
{
/**
* @var mixed
*/
private $tdmcreate = null;
/*
* @public function constructor class
* @param null
*/
public function __construct()
{
$this->tdmcreate = TDMCreate::getInstance();
$this->initVar('field_id', XOBJ_DTYPE_INT);
$this->initVar('field_mid', XOBJ_DTYPE_INT);
$this->initVar('field_tid', XOBJ_DTYPE_INT);
$this->initVar('field_numb', XOBJ_DTYPE_INT);
$this->initVar('field_name', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_type', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_value', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_attribute', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_null', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_default', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_key', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_element', XOBJ_DTYPE_TXTBOX);
$this->initVar('field_parent', XOBJ_DTYPE_INT);
$this->initVar('field_inlist', XOBJ_DTYPE_INT);
$this->initVar('field_inform', XOBJ_DTYPE_INT);
$this->initVar('field_admin', XOBJ_DTYPE_INT);
$this->initVar('field_user', XOBJ_DTYPE_INT);
$this->initVar('field_block', XOBJ_DTYPE_INT);
$this->initVar('field_main', XOBJ_DTYPE_INT);
$this->initVar('field_search', XOBJ_DTYPE_INT);
$this->initVar('field_required', XOBJ_DTYPE_INT);
}
/**
* @param string $method
* @param array $args
*
* @return mixed
*/
public function __call($method, $args)
{
$arg = isset($args[0]) ? $args[0] : null;
return $this->getVar($method, $arg);
}
/*
* @static function &getInstance
* @param null
*/
public static function &getInstance()
{
static $instance = false;
if (!$instance) {
$instance = new self();
}
return $instance;
}
/*
* @private function getHeaderForm
* @param mixed $action
*/
private function getHeaderForm($action = false)
{
if ($action === false) {
$action = $_SERVER['REQUEST_URI'];
}
$isNew = $this->isNew();
$title = $isNew ? sprintf(_AM_TDMCREATE_FIELDS_NEW) : sprintf(_AM_TDMCREATE_FIELDS_EDIT);
$form = new TDMCreateThemeForm(null, 'form', $action, 'post', true);
$form->setExtra('enctype="multipart/form-data"');
// New Object HtmlTable
$form->addElement(new TDMCreateFormLabel(''));
$form->addElement(new TDMCreateFormLabel(''));
$form->addElement(new TDMCreateFormLabel(''.$title.' |
'));
$form->addElement(new TDMCreateFormLabel(''));
$form->addElement(new TDMCreateFormLabel(''._AM_TDMCREATE_FIELD_ID.' | '));
$form->addElement(new TDMCreateFormLabel(''._AM_TDMCREATE_FIELD_NAME.' | '));
$form->addElement(new TDMCreateFormLabel(''._AM_TDMCREATE_FIELD_TYPE.' | '));
$form->addElement(new TDMCreateFormLabel(''._AM_TDMCREATE_FIELD_VALUE.'')); $form->addElement(new TDMCreateFormLabel(' | '._AM_TDMCREATE_FIELD_ATTRIBUTE.'')); $form->addElement(new TDMCreateFormLabel(' | '._AM_TDMCREATE_FIELD_NULL.'')); $form->addElement(new TDMCreateFormLabel(' | '._AM_TDMCREATE_FIELD_DEFAULT.'')); $form->addElement(new TDMCreateFormLabel(' | '._AM_TDMCREATE_FIELD_KEY.'')); $form->addElement(new TDMCreateFormLabel(' | '._AM_TDMCREATE_FIELD_PARAMETERS.'')); $form->addElement(new TDMCreateFormLabel(' |
'));
$form->addElement(new TDMCreateFormLabel(''));
//
return $form;
}
/*
* @public function getFormNew
*
* @param integer $field_mid
* @param integer $field_tid
* @param integer $field_numb
* @param string $f_name
* @param mixed $action
*/
public function getFormNew($field_mid = null, $field_tid = null, $field_numb = null, $f_name = null, $action = false)
{
// Header function class
$fields_form = TDMCreateFields::getInstance();
$form = $fields_form->getHeaderForm($action);
//
$table_obj = $this->tdmcreate->getHandler('tables')->get($field_tid); //changed by goffy
$table_autoincrement = $table_obj->getVar('table_autoincrement'); //added by goffy
//
$class = 'even';
for($i = 1; $i <= $field_numb; $i++) {
$class = ($class == 'even') ? 'odd' : 'even';
//replaced creation of new line by new function - goffy
$this->getFormNewLine($form, $class, $i, $field_mid, $field_tid, $f_name, $table_autoincrement);
}
// Footer form
return $fields_form->getFooterForm($form);
}
/*
* @public function getFormNewLine - goffy
*
* @param mixed $form
* @param mixed $class
* @param integer $i
* @param integer $field_mid
* @param integer $field_tid
* @param mixed $f_name
* @param integer $table_autoincrement
*/
public function getFormNewLine($form, $class, $i, $field_mid, $field_tid, $f_name, $table_autoincrement)
{
$form->addElement(new XoopsFormHidden('field_id['.$i.']', 'new'));
$form->addElement(new XoopsFormHidden('field_mid', $field_mid));
$form->addElement(new XoopsFormHidden('field_tid', $field_tid));
$form->addElement(new TDMCreateFormLabel('.$class.'">'));
// Index ID
$form->addElement(new TDMCreateFormLabel(''.$i.' | '));
// Field Name
$this_field_name = (!empty($f_name) ? $f_name . '_' : '');
$field_name = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$i.']', 15, 255, $this_field_name);
$form->addElement(new TDMCreateFormLabel(''.$field_name->render().' | '));
// Field Type
$value = ($i == 1) && ($table_autoincrement == 1) ? '2' : '';
$fieldtype_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$i.']', $value);
$fieldtype_select->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList());
$form->addElement(new TDMCreateFormLabel(''.$fieldtype_select->render().' | '));
// Field Value
$value = ($i == 1) && ($table_autoincrement == 1) ? '8' : '';
$field_value = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$i.']', 5, 20, $value);
$form->addElement(new TDMCreateFormLabel(''.$field_value->render().' | '));
// Field Attributes
$field_attributes_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$i.']');
$field_attributes_select->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList());
$form->addElement(new TDMCreateFormLabel(''.$field_attributes_select->render().' | '));
// Field Null
$field_null_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$i.']');
$field_null_select->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList());
$form->addElement(new TDMCreateFormLabel(''.$field_null_select->render().' | '));
// Field Default
$field_default = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$i.']', 15, 25);
$form->addElement(new TDMCreateFormLabel(''.$field_default->render().' | '));
// Field Key
$field_key_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$i.']');
$field_key_select->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList());
$form->addElement(new TDMCreateFormLabel(''.$field_key_select->render().' | '));
// Field Void
if( ($i == 1) && ($table_autoincrement == 1)) {
$form->addElement(new TDMCreateFormLabel(' |
'));
} else {
// Box header row
$parameters_tray = new XoopsFormElementTray('', '
');
// Field Elements
$criteria_element = new CriteriaCompo();
$criteria_element->add(new Criteria('fieldelement_tid', 0));
$criteria_table = new CriteriaCompo();
$criteria_table->add(new Criteria('fieldelement_mid', $field_mid));
$field_elements_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$i.']');
$field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_element));
$field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_table));
unset($criteria_element); unset($criteria_table);
$parameters_tray->addElement($field_elements_select);
$field_parent = 0;
$check_field_parent = new XoopsFormCheckBox(' ', 'field_parent['.$i.']');
$check_field_parent->addOption($field_parent, _AM_TDMCREATE_FIELD_PARENT );
$parameters_tray->addElement($check_field_parent);
$field_inlist = 0;
$check_field_inlist = new XoopsFormCheckBox(' ', 'field_inlist['.$i.']', $field_inlist);
$check_field_inlist->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
$parameters_tray->addElement($check_field_inlist);
$field_inform = 0;
$check_field_inform = new XoopsFormCheckBox(' ', 'field_inform['.$i.']', $field_inform);
$check_field_inform->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
$parameters_tray->addElement($check_field_inform);
$field_admin = 0;
$check_field_admin = new XoopsFormCheckBox(' ', 'field_admin['.$i.']', $field_admin);
$check_field_admin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
$parameters_tray->addElement($check_field_admin);
$field_user = 0;
$check_field_user = new XoopsFormCheckBox(' ', 'field_user['.$i.']', $field_user);
$check_field_user->addOption(1, _AM_TDMCREATE_FIELD_USER);
$parameters_tray->addElement($check_field_user);
$field_block = 0;
$check_field_block = new XoopsFormCheckBox('', 'field_block['.$i.']', $field_block);
$check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
$parameters_tray->addElement($check_field_block);
if(($i == 1)) {
$field_main = 1;
$check_field_main = new XoopsFormRadio('', 'field_main['.$i.']', $field_main);
$check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD );
} else {
$field_main = 0;
$check_field_main = new XoopsFormRadio('', 'field_main['.$i.']');
$check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD );
}
$parameters_tray->addElement($check_field_main);
$field_search = 0;
$check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$i.']', $field_search);
$check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
$parameters_tray->addElement($check_field_search);
$field_required = 0;
$check_field_required = new XoopsFormCheckBox(' ', 'field_required['.$i.']', $field_required);
$check_field_required->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
$parameters_tray->addElement($check_field_required);
$form->addElement(new TDMCreateFormLabel(''._AM_TDMCREATE_FIELD_PARAMETERS_LIST.' '.$parameters_tray->render().' | '));
}
}
/*
* @public function getFormEdit
*
* @param integer $field_mid
* @param integer $field_tid
* @param mixed $action
*/
public function getFormEdit($field_mid = null, $field_tid = null, $action = false)
{
// Header function class
$fields_form = TDMCreateFields::getInstance();
$form = $fields_form->getHeaderForm($action);
//
$class = 'even';
// Get the number of fields - goffy
$tablesHandler =& $this->tdmcreate->getHandler('tables');
$table_nbfields = $tablesHandler->get($field_tid)->getVar("table_nbfields");
$f_name = $tablesHandler->get($field_tid)->getVar("table_fieldname");
// Get the list of fields
$criteria = new CriteriaCompo();
$criteria->add(new Criteria('field_mid', $field_mid));
$criteria->add(new Criteria('field_tid', $field_tid));
$criteria->setSort('field_id'); //added by goffy
$fields = $this->tdmcreate->getHandler('fields')->getObjects($criteria);
unset($criteria);
$id = 1;
foreach($fields as $field) {
$class = ($class == 'even') ? 'odd' : 'even';
$field_id = $field->getVar('field_id');
if ($id>$table_nbfields) { //delete additional fields, if number of fields is reduced - goffy
$fieldsObj =& $this->tdmcreate->getHandler('fields')->get( $field_id );
$this->tdmcreate->getHandler('fields')->delete($fieldsObj, true);
} else {
// show field with settings
$form->addElement(new XoopsFormHidden('field_id['.$field_id.']', $field_id));
$form->addElement(new XoopsFormHidden('field_mid', $field_mid));
$form->addElement(new XoopsFormHidden('field_tid', $field_tid));
$form->addElement(new TDMCreateFormLabel('.$class.'">'));
// Index ID
$form->addElement(new TDMCreateFormLabel(''.$id.' | '));
// Field Name
$field_name = new XoopsFormText(_AM_TDMCREATE_FIELD_NAME, 'field_name['.$field_id.']', 15, 255, $field->getVar('field_name'));
$form->addElement(new TDMCreateFormLabel(''.$field_name->render().' | '));
// Field Type
$fieldtype_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_type['.$field_id.']', $field->getVar('field_type'));
$fieldtype_select->addOptionArray($this->tdmcreate->getHandler('fieldtype')->getList());
$form->addElement(new TDMCreateFormLabel(''.$fieldtype_select->render().' | '));
// Field Value
$field_value = new XoopsFormText(_AM_TDMCREATE_FIELD_VALUE, 'field_value['.$field_id.']', 5, 20, $field->getVar('field_value'));
$form->addElement(new TDMCreateFormLabel(''.$field_value->render().' | '));
// Field Attributes
$field_attributes_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_TYPE, 'field_attribute['.$field_id.']', $field->getVar('field_attribute'));
$field_attributes_select->addOptionArray($this->tdmcreate->getHandler('fieldattributes')->getList());
$form->addElement(new TDMCreateFormLabel(''.$field_attributes_select->render().' | '));
// Field Null
$field_null_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_NULL, 'field_null['.$field_id.']', $field->getVar('field_null'));
$field_null_select->addOptionArray($this->tdmcreate->getHandler('fieldnull')->getList());
$form->addElement(new TDMCreateFormLabel(''.$field_null_select->render().' | '));
// Field Default
$field_default = new XoopsFormText(_AM_TDMCREATE_FIELD_DEFAULT, 'field_default['.$field_id.']', 15, 25, $field->getVar('field_default'));
$form->addElement(new TDMCreateFormLabel(''.$field_default->render().' | '));
// Field Key
$field_key_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_KEY, 'field_key['.$field_id.']', $field->getVar('field_key'));
$field_key_select->addOptionArray($this->tdmcreate->getHandler('fieldkey')->getList());
$form->addElement(new TDMCreateFormLabel(''.$field_key_select->render().' | '));
// Field Void
$table_autoincrement = $this->tdmcreate->getHandler('tables')->get($field_tid);
if( ($id == 1) && ($table_autoincrement->getVar('table_autoincrement') == 1)) {
$form->addElement(new TDMCreateFormLabel(' |
'));
} else {
// Box header row
$parameters_tray = new XoopsFormElementTray('', '
');
// Field Elements
$criteria_element = new CriteriaCompo();
$criteria_element->add(new Criteria('fieldelement_tid', 0));
$criteria_table = new CriteriaCompo();
$criteria_table->add(new Criteria('fieldelement_mid', $field_mid));
$field_elements_select = new XoopsFormSelect(_AM_TDMCREATE_FIELD_ELEMENT_NAME, 'field_element['.$field_id.']', $field->getVar('field_element'));
$field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_element));
$field_elements_select->addOptionArray($this->tdmcreate->getHandler('fieldelements')->getList($criteria_table));
unset($criteria_element); unset($criteria_table);
$parameters_tray->addElement($field_elements_select);
$check_field_parent = new XoopsFormCheckBox(' ', 'field_parent['.$field_id.']', $field->getVar('field_parent'));
$check_field_parent->addOption(1, _AM_TDMCREATE_FIELD_PARENT );
$parameters_tray->addElement($check_field_parent);
$check_field_inlist = new XoopsFormCheckBox(' ', 'field_inlist['.$field_id.']', $field->getVar('field_inlist'));
$check_field_inlist->addOption(1, _AM_TDMCREATE_FIELD_INLIST);
$parameters_tray->addElement($check_field_inlist);
$check_field_inform = new XoopsFormCheckBox(' ', 'field_inform['.$field_id.']', $field->getVar('field_inform'));
$check_field_inform->addOption(1, _AM_TDMCREATE_FIELD_INFORM);
$parameters_tray->addElement($check_field_inform);
$check_field_admin = new XoopsFormCheckBox(' ', 'field_admin['.$field_id.']', $field->getVar('field_admin'));
$check_field_admin->addOption(1, _AM_TDMCREATE_FIELD_ADMIN);
$parameters_tray->addElement($check_field_admin);
$check_field_user = new XoopsFormCheckBox(' ', 'field_user['.$field_id.']', $field->getVar('field_user'));
$check_field_user->addOption(1, _AM_TDMCREATE_FIELD_USER);
$parameters_tray->addElement($check_field_user);
$check_field_block = new XoopsFormCheckBox('', 'field_block['.$field_id.']', $field->getVar('field_block'));
$check_field_block->addOption(1, _AM_TDMCREATE_FIELD_BLOCK);
$parameters_tray->addElement($check_field_block);
$field_main = $field->getVar('field_main');
if($field_main == 1) {
$check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']', $field_main);
} else {
$check_field_main = new XoopsFormRadio('', 'field_main['.$field_id.']');
}
$check_field_main->addOption($field_main, _AM_TDMCREATE_FIELD_MAINFIELD );
$parameters_tray->addElement($check_field_main);
$check_field_search = new XoopsFormCheckBox(' ', 'field_search['.$field_id.']', $field->getVar('field_search'));
$check_field_search->addOption(1, _AM_TDMCREATE_FIELD_SEARCH);
$parameters_tray->addElement($check_field_search);
$check_field_required = new XoopsFormCheckBox(' ', 'field_required['.$field_id.']', $field->getVar('field_required'));
$check_field_required->addOption(1, _AM_TDMCREATE_FIELD_REQUIRED);
$parameters_tray->addElement($check_field_required);
$form->addElement(new TDMCreateFormLabel(''._AM_TDMCREATE_FIELD_PARAMETERS_LIST.' '.$parameters_tray->render().' | '));
}
$id++;
}
}
//add missing fields - goffy
for ($i=$id; $i<=$table_nbfields; $i++) {
$class = ($class == 'even') ? 'odd' : 'even';
$this->getFormNewLine($form, $class, $i, $field_mid, $field_tid, $f_name, 0);
}
unset($id);
// Footer form
return $fields_form->getFooterForm($form);
}
/*
* @private function getFooterForm
* @param null
*/
private function getFooterForm($form)
{
// Send Form Data
$form->addElement(new TDMCreateFormLabel(''));
$form->addElement(new TDMCreateFormLabel(''));
$form_hidden = new XoopsFormHidden('op', 'save');
$form_button = new XoopsFormButton('', 'submit', _SUBMIT, 'submit');
$form->addElement(new TDMCreateFormLabel(''.$form_hidden->render().' | '));
$form->addElement(new TDMCreateFormLabel(''.$form_button->render().' | '));
$form->addElement(new TDMCreateFormLabel('
'));
return $form;
}
}
/*
* @Class TDMCreateFieldsHandler
* @extends XoopsPersistableObjectHandler
*/
class TDMCreateFieldsHandler extends XoopsPersistableObjectHandler
{
/*
* @public function constructor class
* @param mixed $db
*/
public function __construct(&$db)
{
parent::__construct($db, 'tdmcreate_fields', 'tdmcreatefields', 'field_id', 'field_name');
}
/**
* @param bool $isNew
*
* @return object
*/
public function &create($isNew = true)
{
return parent::create($isNew);
}
/**
* retrieve a field
*
* @param int $i field id
*
* @return mixed reference to the {@link TDMCreateFields} object
*/
public function &get($i = null, $fields = null)
{
return parent::get($i, $fields);
}
/**
* get IDs of objects matching a condition
*
* @param object $criteria {@link CriteriaElement} to match
* @return array of object IDs
*/
function &getIds($criteria)
{
return parent::getIds($criteria);
}
/**
* insert a new field in the database
*
* @param object $field reference to the {@link TDMCreateFields} object
* @param bool $force
*
* @return bool FALSE if failed, TRUE if already present and unchanged or successful
*/
public function insert(&$field, $force = false)
{
if (!parent::insert($field, $force)) {
return false;
}
return true;
}
}
I have made a new function 'getFormNewLine', because a new field can now be in function getFormNew and also in getFormEdit
4) deleting a table does not delete the corresponding items in tdmcreate_fields
5) I started to translate to german, but there are a lot of not used defines, maybe should some be use in future, i dont know. I wait for Beta version to make a translation