/** * Set the Row Object to be edited * * @param Row $Row the Row to be edited * @return void */ public function setRow(Row $Row) { $this->Row = $Row; $this->no_fields = 0; /** Parse table structure into template friendly data **/ $structure = $Row->getStructure(); foreach ($structure as $field) { $aux = array(); $name = $field['Field']; $aux['label'] = ucwords(str_replace('_', ' ', $name)); $aux['value'] = isset($Row->data[$name]) ? $Row->data[$name] : $field['Default']; $this->no_fields++; /** * Extract type information. * $match[0] The whole string. ie: int(11) unsigned * $match[1] The type. ie: int * $match[2] The type parameters ie: 11 * $match[3] Extra. ie: unsigned */ preg_match('/^([a-z]*)(?:\\((.*)\\))?\\s?(.*)$/', $field['Type'], $match); switch ($match[1]) { case 'varchar': if ($match[2] <= 100) { $aux['type'] = 'text'; $aux['input_parameters']['maxlength'] = $match[2]; } else { $aux['type'] = 'textarea'; $aux['input_parameters']['cols'] = '60'; $aux['input_parameters']['rows'] = '3'; } break; case 'char': if ($match[2] <= 100) { $aux['type'] = 'text'; $aux['input_parameters']['maxlength'] = $match[2]; } else { $aux['type'] = 'textarea'; $aux['input_parameters']['cols'] = '60'; $aux['input_parameters']['rows'] = '3'; } break; case 'text': $aux['type'] = 'textarea'; $aux['input_parameters']['cols'] = '60'; $aux['input_parameters']['rows'] = '6'; break; case 'int': $aux['type'] = 'text'; $aux['input_parameters']['maxlength'] = $match[2]; break; case 'date': $aux['type'] = 'date'; $aux['parameters']['before'] = '5'; $aux['parameters']['after'] = '5'; break; case 'enum': case 'set': //Testing if ($match[2] == "'0','1'") { $options = array('1' => t('Yes'), '0' => t('No')); } else { /** Retrive and parse Options **/ $options = array(); $params = explode("','", $match[2]); $params[0] = substr($params[0], 1); //remove the first quote $params[count($params) - 1] = substr($params[count($params) - 1], 0, -1); //remove the second quote $options = array_combine($params, $params); //creates a createCombox compatible array } $aux['type'] = 'select'; if (count($options) <= 3) { $aux['type'] = 'radio'; } $aux['parameters']['options'] = $options; break; } $this->fields[$name] = $aux; } }