示例#1
0
 /**
  * Open the AutoCode for edit.
  *
  * @param EcrProjectAutocode $AutoCode The AutoCode
  *
  * @return void
  */
 public function edit(EcrProjectAutocode $AutoCode)
 {
     /* 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'));
     $tableFields = EcrTableHelper::getTableColumns($this->element);
     echo '<br />';
     $key = $AutoCode->getKey() . '.row';
     if (array_key_exists($key, $AutoCode->fields)) {
         $acFields = $AutoCode->fields[$key];
     } else {
         $acFields = array();
     }
     echo '<div style="background-color: #f3fbe6;">Header</div>';
     echo '<table>';
     echo '<tr>';
     echo '<th>' . jgettext('Field') . '</th>';
     echo '<th>' . jgettext('Label') . '</th>';
     echo '<th>' . jgettext('Input type') . '</th>';
     echo '</tr>';
     foreach ($tableFields as $name => $tableField) {
         if (array_key_exists($name, $acFields)) {
             //-- Autocode present
             $label = $acFields[$name]->label;
             $inputType = $acFields[$name]->inputType;
             $width = $acFields[$name]->width;
         } else {
             //-- New field
             $label = $tableField->Field;
             $inputType = 'text';
             $width = 0;
         }
         echo '<tr>';
         echo '<th>';
         echo $name;
         echo '</th>';
         echo '<td>';
         echo '<input type="text" name="field[' . $name . '][label]" value="' . $label . '" />';
         echo '</td>';
         echo '<td>';
         echo '<select name="field[' . $name . '][input_type]">';
         $selected = $inputType == 'text' ? ' selected="selected"' : '';
         echo '<option value="text"' . $selected . '>&lt;text&gt;</option>';
         $selected = $inputType == 'hidden' ? ' selected="selected"' : '';
         echo '<option value="hidden"' . $selected . '>&lt;hidden&gt;</option>';
         $selected = $inputType == 'category' ? ' selected="selected"' : '';
         echo '<option value="category"' . $selected . '>Catergory select</option>';
         echo '</select>';
         echo '</td>';
         echo '</tr>';
     }
     //foreach
     echo '</table>';
     /* Draws the submit button */
     EcrHtmlButton::autoCode($requireds);
 }
示例#2
0
 /**
  * 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');
     $var_scope = $input->get('var_scope');
     $element_scope = $input->get('element_scope');
     if (!$table_name) {
         JFactory::getApplication()->enqueueMessage(jgettext('No table given'), 'error');
         return false;
     }
     $db = JFactory::getDBO();
     $prefix = $db->getPrefix();
     $fields = $db->getTableFields($prefix . $table_name);
     $table_vars = '';
     $autoCodeFields = array();
     $reqFields = $input->get('field', array(), 'array');
     if (count($fields)) {
         foreach ($fields[$prefix . $table_name] as $name => $type) {
             $reqField = $reqFields[$name];
             if (isset($project->autoCodes[$this->key]->fields[$this->key . '.var'][$name])) {
                 $field = $project->autoCodes[$this->key]->fields[$this->key . '.var'][$name];
                 $field->label = $reqField['label'];
             } else {
                 $field = new EcrTableField();
                 $field->name = $name;
                 $field->label = $name;
                 $field->type = $type;
             }
             $autoCodeFields[] = $field;
             $adds = array($field->label);
             $table_vars .= EcrTableHelper::formatTableVar($name, $type, $adds, $var_scope);
         }
         //foreach
     }
     $AutoCode = new EcrProjectAutocode($this->group, $this->name, $table_name, $element_scope);
     $AutoCode->options = array();
     $AutoCode->options['varscope'] = $var_scope;
     $AutoCode->fields[$AutoCode->getKey() . '.var'] = $autoCodeFields;
     $AutoCode->codes[$AutoCode->getKey() . '.var'] = $AutoCode->enclose($table_vars, $AutoCode->getKey() . '.var');
     $project->addAutoCode($AutoCode);
     /*
      * Add substitutes
      *
      * Define keys that will be substitutes in the code
      */
     $project->addSubstitute('ECR_SUBPACKAGE', 'Tables');
     $project->addSubstitute('_ECR_TABLE_NAME_', $table_name);
     foreach ($AutoCode->codes as $key => $code) {
         $project->addSubstitute($key, $code);
     }
     //foreach
     /* Insert the part to your project and return the results */
     return $project->insertPart($options, $logger);
 }
示例#3
0
 /**
  * Adds AutoCode to the project.
  *
  * @param EcrProjectAutocode $autoCode The AutoCode
  *
  * @return void
  */
 public function addAutoCode(EcrProjectAutocode $autoCode)
 {
     $this->autoCodes[$autoCode->getKey()] = $autoCode;
 }
示例#4
0
 /**
  * Open the AutoCode for edit.
  *
  * @param EcrProjectAutocode $AutoCode The AutoCode
  *
  * @return void
  */
 public function edit(EcrProjectAutocode $AutoCode)
 {
     JFactory::getApplication()->enqueueMessage(__METHOD__ . ' not finished', 'warning');
     /* 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'));
     $tableFields = EcrTableHelper::getTableColumns($this->element);
     $elements = array('header', 'cell');
     echo '<br />';
     /*
      * Header
      */
     $key = $AutoCode->getKey() . '.header';
     if (array_key_exists($key, $AutoCode->fields)) {
         $acFields = $AutoCode->fields[$key];
     } else {
         $acFields = array();
     }
     echo '<div style="background-color: #f3fbe6;">Header</div>';
     echo '<table>';
     echo '<tr>';
     echo '<th>' . jgettext('Field') . '</th>';
     echo '<th>' . jgettext('Label') . '</th>';
     echo '<th>' . jgettext('Display') . '</th>';
     echo '<th>' . jgettext('Width') . '</th>';
     echo '</tr>';
     foreach ($tableFields as $name => $tableField) {
         if (array_key_exists($name, $acFields)) {
             //-- Autocode present
             $label = $acFields[$name]->label;
             $display = $acFields[$name]->display;
             $width = $acFields[$name]->width;
         } else {
             //-- New field
             $label = $tableField->Field;
             $display = 'on';
             $width = 0;
         }
         echo '<tr>';
         echo '<th>';
         echo $name;
         echo '</th>';
         echo '<td>';
         echo '<input type="text" name="field[header][' . $name . '][label]" value="' . $label . '" />';
         echo '</td>';
         echo '<td>';
         echo '<select name="field[header][' . $name . '][display]">';
         $selected = $display == 'on' ? ' selected="selected"' : '';
         echo '<option value="on"' . $selected . '>' . jgettext('On') . '</option>';
         $selected = $display == 'off' ? ' selected="selected"' : '';
         echo '<option value="off"' . $selected . '>' . jgettext('Off') . '</option>';
         echo '</select>';
         echo '</td>';
         echo '<td>';
         echo '<input type="text" name="field[header][' . $name . '][width]" value="' . $width . '" />';
         echo '</td>';
         echo '</tr>';
     }
     //foreach
     echo '</table>';
     /*
      * Cell
      */
     $key = $AutoCode->getKey() . '.cell';
     if (array_key_exists($key, $AutoCode->fields)) {
         $acFields = $AutoCode->fields[$key];
     } else {
         $acFields = array();
     }
     echo '<div style="background-color: #f3fbe6;">Cell</div>';
     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->Field;
         }
         echo '<tr>';
         echo '<th>';
         echo $name;
         echo '<input type="hidden" name="field[cell][' . $name . '][name]" value="' . $name . '" />';
         echo '</th>';
         echo '</tr>';
     }
     //foreach
     echo '</table>';
     /* Draws the submit button */
     EcrHtmlButton::autoCode($requireds);
 }