/** * Inserts the AutoCode into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger The EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { JFactory::getApplication()->enqueueMessage(__METHOD__ . ' not finished', 'error'); $input = JFactory::getApplication()->input; $table_name = $input->get('element'); $element_scope = $input->get('element_scope'); if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $fields = EcrTableHelper::getTableColumns($table_name); $reqFields = $input->get('field', array(), 'array'); $headers = ''; $cells = ''; $tags = array('<!--', '-->'); $indent = ' '; if (!count($fields)) { JFactory::getApplication()->enqueueMessage('No table fields found', 'error'); return false; } foreach ($fields as $name => $field) { $reqFieldHeader = $reqFields['header'][$name]; $reqFieldCell = $reqFields['cell'][$name]; if (isset($project->autoCodes[$this->key]->fields[$this->key . '.header'][$name])) { $fieldHeader = $project->autoCodes[$this->key]->fields[$this->key . '.header'][$name]; $fieldHeader->label = $reqFieldHeader['label']; } else { $fieldHeader = new EcrTableField(); $fieldHeader->name = $name; $fieldHeader->label = $name; } if (isset($project->autoCodes[$this->key]->fields[$this->key . '.cell'][$name])) { $fieldCell = $project->autoCodes[$this->key]->fields[$this->key . '.cell'][$name]; } else { $fieldCell = new EcrTableField(); $fieldCell->name = $name; } $fieldHeader->display = $reqFieldHeader['display']; $fieldHeader->width = $reqFieldHeader['width']; //-- Display value for cells is the same as for headers $fieldCell->display = $reqFieldHeader['display']; $autoCodeFieldsHeader[] = $fieldHeader; $autoCodeFieldsCell[] = $fieldCell; $headers .= $this->getCode('header', $fieldHeader, $indent); $cells .= $this->getCode('cell', $fieldCell, $indent); } //foreach $this->fields[$this->key . '.header'] = $autoCodeFieldsHeader; $this->codes[$this->key . '.header'] = $this->enclose($headers, $this->key . '.header', true); $this->fields[$this->key . '.cell'] = $autoCodeFieldsCell; $this->codes[$this->key . '.cell'] = $this->enclose($cells, $this->key . '.cell', true); $project->addAutoCode($this); /* * Add substitutes * * Define keys that will be substitutes in the code */ $project->addSubstitute('ECR_SUBPACKAGE', 'Views'); $project->addSubstitute('_ECR_TABLE_NAME_', $table_name); foreach ($this->codes as $key => $code) { $project->addSubstitute($tags[0] . $key . $tags[1], $code); } //foreach /* Insert the part to your project and return the results */ return $project->insertPart($options, $logger); }
/** * Open the part for edit. * * @param EcrProjectAutocode $AutoCode TheAutocode * * @return void */ public function edit(EcrProjectAutocode $AutoCode) { $var_scope = $AutoCode->options['varscope']; /* Array with required fields */ $requireds = array(); $requireds[] = EcrHtmlSelect::scope($this->scope); echo '<input type="hidden" name="element" value="' . $this->element . '" />'; /* Draws an input box for a name field */ $requireds[] = EcrHtmlSelect::name($this->element, jgettext('Table')); echo '<strong>Var Scope:</strong><br />'; foreach ($this->varScopes as $vScope) { $checked = $vScope == $var_scope ? ' checked="checked"' : ''; echo '<input type="radio" name="var_scope" value="' . $vScope . '"' . ' id="vscope-' . $vScope . '"' . $checked . '> <label for="vscope-' . $vScope . '">' . $vScope . '</label><br />'; } //foreach $tableFields = EcrTableHelper::getTableColumns($this->element); $acFields = $AutoCode->fields[$AutoCode->getKey() . '.var']; echo '<table>'; echo '<tr>'; echo '<th>' . jgettext('Field') . '</th>'; echo '<th>' . jgettext('Label') . '</th>'; echo '</tr>'; foreach ($tableFields as $name => $tableField) { if (array_key_exists($name, $acFields)) { //-- Autocode present $value = $acFields[$name]->label; } else { //-- New field $value = $tableField[$name]->field; } echo '<tr>'; echo '<th>'; echo '<input type="hidden" name="field[' . $name . '][name]" value="' . $name . '" />'; echo $name; echo '</th>'; echo '<td>'; echo '<input type="text" name="field[' . $name . '][label]" value="' . $value . '" />'; echo '</td>'; echo '</tr>'; } //foreach echo '</table>'; /* Draws the submit button */ EcrHtmlButton::autoCode($requireds); }
/** * Inserts the AutoCode into the project. * * @param EcrProjectBase $project The project. * @param array $options Insert options. * @param EcrLogger $logger EcrLogger. * * @return boolean */ public function insert(EcrProjectBase $project, $options, EcrLogger $logger) { $input = JFactory::getApplication()->input; $table_name = $input->get('element'); $element_scope = $input->get('element_scope'); $element = 'row'; if (!$table_name) { JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error'); return false; } $table = new EcrTable($table_name); $fields = EcrTableHelper::getTableColumns($table_name); $reqFields = $input->get('field', array(), 'array'); $rows = ''; $tags = array('<!--', '-->'); $indent = ' '; if (!count($fields)) { JFactory::getApplication()->enqueueMessage('No table fields found', 'error'); return false; } foreach ($fields as $name => $field) { $reqFieldHeader = $reqFields[$name]; if (isset($project->autoCodes[$this->key]->fields[$this->key . '.' . $element][$name])) { $fieldHeader = $project->autoCodes[$this->key]->fields[$this->key . '.' . $element][$name]; } else { $fieldHeader = new EcrTableField(); $fieldHeader->name = $name; } $fieldHeader->label = $reqFieldHeader['label']; $fieldHeader->inputType = $reqFieldHeader['input_type']; $autoCodeFieldsHeader[] = $fieldHeader; $table->addField($fieldHeader); } //foreach $rows .= $this->getCode($element, $table, $indent); $this->fields[$this->key . '.' . $element] = $autoCodeFieldsHeader; $this->codes[$this->key . '.' . $element] = $this->enclose($rows, $this->key . '.' . $element); $project->addAutoCode($this); /* * Add substitutes * * Define keys that will be substitutes in the code */ $project->addSubstitute('ECR_SUBPACKAGE', 'Views'); $project->addSubstitute('_ECR_TABLE_NAME_', $table_name); foreach ($this->codes as $key => $code) { $project->addSubstitute($tags[0] . $key . $tags[1], $code); } //foreach /* Insert the part to your project and return the results */ return $project->insertPart($options, $logger); }