Example #1
0
 /**
  * Get the AutoCode to insert.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent The string to indent with
  *
  * @return string
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     $fields = array();
     $aliases = '';
     $relations = '';
     $fields = '';
     $charCode = 98;
     // b
     foreach ($table->getFields() as $field) {
         if (!$field->display) {
             continue;
         }
         $fields[] = 'a.' . $field->name;
     }
     //foreach
     $fields = implode(', ', $fields);
     if (count($table->getRelations())) {
         foreach ($table->getRelations() as $relation) {
             $relations .= $indent . ".' " . $relation->type . ' #__' . $relation->onTable . ' AS ' . chr($charCode) . ' ON ' . chr($charCode) . '.' . $relation->onField . ' = a.' . $relation->field . "'";
             if (count($relation->aliases)) {
                 foreach ($relation->aliases as $alias) {
                     $aliases .= ', ' . chr($charCode) . '.' . $alias->aliasField . ' AS ' . $alias->alias;
                 }
                 //foreach
             }
             $charCode++;
         }
         //foreach
         $relations .= NL;
     }
     $ret .= $indent . '$query = \' SELECT ' . $fields . $aliases . "'" . NL . $indent . '.\' FROM #__' . $table->name . ' AS a \'' . NL . $relations . ';';
     $ret .= NL;
     return $ret;
 }
Example #2
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $a = array();
     foreach ($table->getFields() as $field) {
         if (!$field->display) {
             continue;
         }
         $inputType = 'text';
         $this->field = $field;
         if ($field->inputType) {
             if (method_exists($this, 'type' . $field->inputType)) {
                 $inputType = $field->inputType;
             } else {
                 JFactory::getApplication()->enqueueMessage('Unknown inputType: ' . $field->inputType, 'error');
             }
         }
         if ($inputType == 'xxxhidden') {
             $a[] = $this->{'type' . $inputType}() . NL;
             continue;
         }
         $a[] = '<field name="' . $field->name . '" type="' . $inputType . '"';
         if ($inputType != 'hidden') {
             $a[] = 'label="' . $field->label . '"';
             $a[] = 'description="' . $field->comment . '"';
             if ($field->extension) {
                 $a[] = 'extension="' . $field->extension . '"';
             }
         }
         $a[] = '/>';
     }
     //foreach
     $ret = $indent . implode(NL . $indent, $a) . NL;
     return $ret;
 }
Example #3
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $a = array();
     foreach ($table->getFields() as $field) {
         $inputType = 'text';
         $this->field = $field;
         if ($field->inputType) {
             if (method_exists($this, 'type' . $field->inputType)) {
                 $inputType = $field->inputType;
             } else {
                 JFactory::getApplication()->enqueueMessage('Unknown inputType: ' . $field->inputType, 'error');
             }
         }
         if ($inputType == 'hidden') {
             $a[] = $this->{'type' . $inputType}() . NL;
             continue;
         }
         $a[] = '<tr>';
         $a[] = '    <td width="100" align="right" class="key">';
         $a[] = '        <label for="label_' . $field->name . '">' . "<?php echo JText::_('" . $field->label . "'); ?>" . '</label>';
         $a[] = '    </td>';
         $a[] = '    <td>';
         $a[] = $this->{'type' . $inputType}();
         $a[] = '    </td>';
         $a[] = '</tr>';
     }
     //foreach
     $ret = $indent . implode(NL . $indent, $a) . NL;
     return $ret;
 }
Example #4
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table)
 {
     $ret = '';
     foreach ($table->getFields() as $field) {
         $ret .= EcrTableHelper::formatTableVar($field->name, $field->type, array($field->label));
         $ret .= NL;
     }
     //foreach
     return $ret;
 }
Example #5
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     $started = false;
     foreach ($table->getFields() as $field) {
         $ret .= $started ? $indent . ', ' : $indent . '  ';
         $started = true;
         $ret .= EcrTableHelper::formatSqlField($field);
         $ret .= NL;
     }
     //foreach
     return $ret;
 }
Example #6
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     foreach ($table->getFields() as $field) {
         if (!$field->display) {
             continue;
         }
         $ret .= $indent . '<div class="title">' . $field->label . '</div>' . NL;
         $ret .= $indent . '<div class="cell"><?php echo $row->' . $field->name . '; ?></div>' . NL;
     }
     //foreach
     return $ret;
 }
Example #7
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     foreach ($table->getFields() as $field) {
         if (!$field->display || $field->display === 'off') {
             continue;
         }
         $ret .= $indent . '<td>' . NL;
         $ret .= $indent . '    <?php echo $row->' . $field->name . '; ?>' . NL;
         $ret .= $indent . '</td>' . NL;
     }
     //foreach
     return $ret;
 }
Example #8
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     foreach ($table->getFields() as $field) {
         if (!$field->display || $field->display === 'off') {
             continue;
         }
         $width = $field->width ? ' width="' . $field->width . '"' : '';
         $ret .= $indent . '<th' . $width . '>' . NL;
         $ret .= $indent . '    <?php echo JText::_(\'' . $field->label . '\'); ?>' . NL;
         $ret .= $indent . '</th>' . NL;
     }
     //foreach
     return $ret;
 }
Example #9
0
 /**
  * Gets the HTML code.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent Indentation string
  *
  * @return string HTML
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     foreach ($table->getFields() as $field) {
         if (!$field->display) {
             continue;
         }
         $width = $field->width ? ' width="' . $field->width . '"' : '';
         $ret .= $indent . '<td' . $width . ' height="20" class="sectiontableheader' . '<?php echo $this->escape($this->params->get(\'pageclass_sfx\')); ?>">' . NL;
         $ret .= $indent . '    <?php echo JHTML::_(\'grid.sort\', \'' . $field->label . '\', \'' . $field->name . '\', $this->lists[\'order_Dir\'], $this->lists[\'order\']); ?>' . NL;
         $ret .= $indent . '</td>' . NL;
     }
     //foreach
     return $ret;
 }
Example #10
0
 /**
  * Get the AutoCode to insert.
  *
  * @param EcrTable $table A EcrTable object
  * @param string $indent The string to indent with
  *
  * @return string
  */
 public function getCode(EcrTable $table, $indent = '')
 {
     $ret = '';
     $fields = array();
     $aliases = '';
     $relations = '';
     $fields = '';
     $charCode = 98;
     // b
     foreach ($table->getFields() as $field) {
         if (!$field->display) {
             continue;
         }
         $fields[] = 'a.' . $field->name;
     }
     //foreach
     $fields = implode(', ', $fields);
     if (count($table->getRelations())) {
         foreach ($table->getRelations() as $relation) {
             $rType = str_replace(' ', '', strtolower($relation->type));
             $relations .= $indent . '$query->' . $rType . '(\' #__' . $relation->onTable . ' AS ' . chr($charCode) . ' ON ' . chr($charCode) . '.' . $relation->onField . ' = a.' . $relation->field . '\');';
             if (count($relation->aliases)) {
                 foreach ($relation->aliases as $alias) {
                     $aliases .= ', ' . chr($charCode) . '.' . $alias->aliasField . ' AS ' . $alias->alias;
                 }
                 //foreach
             }
             $charCode++;
         }
         //foreach
         $relations .= NL;
     }
     $ret .= $indent . '$query->from(\'#__' . $table->name . ' AS a \');' . NL;
     $ret .= $relations;
     $ret .= $indent . '$query->select(\'' . $fields . $aliases . '\');' . NL;
     return $ret;
 }
Example #11
0
 /**
  * Read the project XML file.
  *
  * @param string $projectName Projects name
  *
  * @throws Exception
  * @return boolean
  */
 private function readProjectXml($projectName)
 {
     $fileName = ECRPATH_SCRIPTS . DS . $projectName . '.xml';
     if (false == JFile::exists($fileName)) {
         throw new Exception('Project manifest not found');
     }
     $manifest = EcrProjectHelper::getXML($fileName);
     if (!$manifest instanceof SimpleXMLElement || $manifest->getName() != 'easyproject') {
         JFactory::getApplication()->enqueueMessage(jgettext('Invalid project manifest'), 'error');
         return false;
     }
     $this->type = (string) $manifest->attributes()->type;
     $this->scope = (string) $manifest->attributes()->scope;
     $this->name = (string) $manifest->name;
     $this->comName = (string) $manifest->comname;
     //-- @Joomla!-compat 2.5
     $this->JCompat = (string) $manifest->JCompat ? (string) $manifest->JCompat : '2.5';
     $this->langFormat = (string) $manifest->langFormat;
     $this->zipPath = (string) $manifest->zipPath;
     $this->headerType = (string) $manifest->headerType;
     $dbTypes = (string) $manifest->dbTypes;
     if ('' != $dbTypes) {
         $this->dbTypes = explode(',', $dbTypes);
     }
     $this->extensionPrefix = (string) $manifest->extensionPrefix;
     $this->fromTpl = (string) $manifest->attributes()->tpl;
     /*
      * Modules
      */
     if (isset($manifest->modules->module)) {
         foreach ($manifest->modules->module as $e) {
             $c = new stdClass();
             foreach ($e->attributes() as $k => $a) {
                 $c->{$k} = (string) $a;
             }
             $c->scope = (string) $e->attributes()->scope;
             $c->position = (string) $e->attributes()->position;
             $c->ordering = (string) $e->attributes()->ordering;
             $this->modules[] = $c;
         }
     }
     /*
      * Plugins
      */
     if (isset($manifest->plugins->plugin)) {
         /* @var SimpleXMLElement $e */
         foreach ($manifest->plugins->plugin as $e) {
             $c = new stdClass();
             foreach ($e->attributes() as $k => $a) {
                 $c->{$k} = (string) $a;
             }
             $c->scope = (string) $e->attributes()->scope;
             $c->ordering = (string) $e->attributes()->ordering;
             $this->plugins[] = $c;
         }
     }
     /*
      * Tables
      */
     if (isset($manifest->tables->table)) {
         foreach ($manifest->tables->table as $e) {
             $table = new EcrTable($e->name, $e->foreign);
             $t = new stdClass();
             $t->name = (string) $e->name;
             if (isset($e->relations->relation)) {
                 foreach ($e->relations->relation as $r) {
                     $relation = new EcrTableRelation();
                     $relation->type = (string) $r->type;
                     $relation->field = (string) $r->field;
                     $relation->onTable = (string) $r->onTable;
                     $relation->onField = (string) $r->onField;
                     if (isset($r->aliases->alias)) {
                         foreach ($r->aliases->alias as $elAlias) {
                             $alias = new EcrTableRelationalias();
                             $alias->alias = (string) $elAlias->name;
                             $alias->aliasField = (string) $elAlias->field;
                             $relation->addAlias($alias);
                         }
                     }
                     $table->addRelation($relation);
                 }
                 $t->relations = $e->relations;
             } else {
                 $t->relations = array();
             }
             $this->tables[$table->name] = $table;
         }
     }
     /*
      * AutoCodes
      */
     if (isset($manifest->autoCodes->autoCode)) {
         /* @var SimpleXMLElement $code */
         foreach ($manifest->autoCodes->autoCode as $code) {
             $group = (string) $code->attributes()->group;
             $name = (string) $code->attributes()->name;
             $element = (string) $code->attributes()->element;
             $scope = (string) $code->attributes()->scope;
             $key = "{$scope}.{$group}.{$name}.{$element}";
             $EasyAutoCode = EcrProjectHelper::getAutoCode($key);
             if (!$EasyAutoCode) {
                 continue;
             }
             if (isset($code->options->option)) {
                 /* @var SimpleXMLElement $o */
                 foreach ($code->options->option as $o) {
                     $option = (string) $o;
                     $k = (string) $o->attributes()->name;
                     $EasyAutoCode->options[$k] = (string) $option;
                 }
             }
             if (isset($code->fields)) {
                 /* @var SimpleXMLElement $fieldsElement */
                 foreach ($code->fields as $fieldsElement) {
                     $key = (string) $fieldsElement->attributes()->key;
                     $fields = array();
                     if (isset($fieldsElement->field)) {
                         /* @var SimpleXMLElement $field */
                         foreach ($fieldsElement->field as $field) {
                             $f = new EcrTableField($field);
                             $k = '';
                             if ($field->attributes()->name) {
                                 $k = (string) $field->attributes()->name;
                             } else {
                                 if (isset($field->name)) {
                                     $k = (string) $field->name;
                                 }
                             }
                             $fields[$k] = $f;
                         }
                     }
                     $EasyAutoCode->fields[$key] = $fields;
                 }
             }
             $this->addAutoCode($EasyAutoCode);
         }
     }
     /*
      * Package elements - 1.6
      */
     if (isset($manifest->elements->element)) {
         foreach ($manifest->elements->element as $e) {
             $this->elements[(string) $e] = (string) $e;
         }
     }
     /*
      * BuildOptions
      */
     foreach ($manifest->buildoptions as $opt) {
         foreach ($opt as $k => $v) {
             $this->buildOpts[$k] = (string) $v;
         }
     }
     /*
      * Build presets
      */
     //-- Init the defqult preset
     $this->presets['default'] = new EcrProjectModelBuildpreset();
     if (isset($manifest->presets->preset)) {
         /* @var SimpleXMLElement $preset */
         foreach ($manifest->presets->preset as $preset) {
             $p = new EcrProjectModelBuildpreset();
             foreach ($preset as $k => $v) {
                 if ('actions' == $k) {
                     /* @var SimpleXMLElement $action */
                     foreach ($v as $action) {
                         $p->actions[] = EcrProjectAction::getInstance((string) $action->attributes()->type, (string) $action->attributes()->event)->setOptions($action);
                     }
                 } else {
                     if (is_bool($p->{$k})) {
                         $p->{(string) $k} = '1' == (string) $v ? true : false;
                     } else {
                         $p->{(string) $k} = (string) $v;
                     }
                 }
             }
             $this->presets[(string) $preset->attributes()->name] = $p;
         }
     }
     /*
      * Update servers
      */
     if (isset($manifest->updateservers->server)) {
         /* @var SimpleXMLElement $server */
         foreach ($manifest->updateservers->server as $server) {
             $u = new stdClass();
             $u->name = (string) $server->attributes()->name;
             $u->priority = (string) $server->attributes()->priority;
             $u->type = (string) $server->attributes()->type;
             $u->url = (string) $server;
             $this->updateServers[] = $u;
         }
     }
     /*
      * Actions
      */
     /*        if(isset($manifest->actions->action))
             {
                 /* @var SimpleXMLElement $action /
                 foreach($manifest->actions->action as $action)
                 {
                     $a = EcrProjectAction::getInstance(
                         (string)$action->attributes()->type, (string)$action->attributes()->event)
                     ->setOptions($action);
     
                     $this->actions[] = $a;
                 }
             }
     */
     return $this;
 }
Example #12
0
    /**
     * Get the CREATE string for a table.
     *
     * @param EcrTable $table The table
     *
     * @return string
     */
    public static function getTableCreate(EcrTable $table)
    {
        $db = JFactory::getDBO();
        $dbName = JFactory::getApplication()->getCfg('db');
        $tName = $db->getPrefix() . $table->name;
        $s = '';
        $s .= 'CREATE TABLE IF NOT EXISTS `#__' . $table->name . '` (' . NL;
        $pri = '';
        $started = false;
        $indent = '';
        $db->setQuery('SHOW CREATE TABLE ' . $tName);
        $engineQuery = 'SELECT ENGINE
 FROM information_schema.TABLES
 WHERE TABLE_SCHEMA = \'' . $dbName . '\'
 AND TABLE_NAME = \'' . $tName . '\'';
        $db->setQuery($engineQuery);
        $engine = $db->loadResult();
        echo 'A' . $engine;
        /*
        //        $engineQuery = ' SHOW TABLE STATUS LIKE `'.$tName.'`
        // FROM information_schema.TABLES
        // WHERE TABLE_SCHEMA = \''.$dbName.'\'
        // AND TABLE_NAME = \''.$tName.'\'';
        //        $db->setQuery($engineQuery);
        //
        //        $engine = $db->loadResult();
        //        echo 'B'.$engine;
        */
        foreach ($table->getFields() as $field) {
            if ($field->key == 'PRI') {
                $pri = $field->name;
            }
            $s .= $started ? $indent . ', ' : $indent . '  ';
            $started = true;
            $s .= EcrTableHelper::formatSqlField($field);
            $s .= NL;
        }
        //foreach
        if ($pri) {
            $s .= ', PRIMARY KEY (`' . $pri . '`)';
        }
        //-- #       $s .= ') ENGINE='.$engine.' DEFAULT CHARSET='.
        return $s;
    }
Example #13
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');
     $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);
 }
Example #14
0
 /**
  * Process custom options.
  *
  * @param EcrProjectBuilder $builder The Builder class.
  *
  * @return boolean True on sucess.
  */
 public function processOptions(EcrProjectBuilder $builder)
 {
     $fields = JFactory::getApplication()->input->get('fields', array(), 'array');
     if (false == is_array($fields)) {
         JFactory::getApplication()->enqueueMessage('No fields to process', 'error');
         return false;
     }
     $tableName = strtolower($builder->project->name);
     $comName = strtolower($builder->project->prefix . $builder->project->name);
     $builder->replacements->ECR_COM_TBL_NAME = $tableName;
     //-- Add the core categories table
     $table = new EcrTable('categories', true);
     $builder->project->addTable($table);
     //-- Prepare extension table
     $table = new EcrTable($tableName);
     for ($i = 0; $i < count($fields); $i++) {
         //@todo move out
         if ($fields[$i]['name'] == 'catid') {
             $fields[$i]['inputType'] = 'category';
             $fields[$i]['extension'] = $comName;
         }
         if ($fields[$i]['name'] == 'id') {
             $fields[$i]['inputType'] = 'hidden';
         }
         if ($fields[$i]['name'] == 'checked_out') {
             $fields[$i]['display'] = false;
         }
         $field = new EcrTableField($fields[$i]);
         $table->addField($field);
     }
     $relation = new EcrTableRelation();
     $relation->type = 'LEFT JOIN';
     $relation->field = 'catid';
     $relation->onTable = 'categories';
     $relation->onField = 'id';
     $alias = new EcrTableRelationalias();
     $alias->alias = 'category';
     $alias->aliasField = 'title';
     $relation->addAlias($alias);
     $table->addRelation($relation);
     $builder->project->addTable($table);
     $codes = array();
     /*
      * Admin
      */
     $c = EcrProjectHelper::getAutoCode('admin.sql.insert.' . $tableName);
     $c->elements = array('field');
     $codes[] = $c;
     $c = EcrProjectHelper::getAutoCode('admin.models.model.' . $tableName);
     $c->elements = array('buildquery16');
     $codes[] = $c;
     $c = EcrProjectHelper::getAutoCode('admin.forms.edit.' . $tableName);
     $c->elements = array('field');
     $codes[] = $c;
     $c = EcrProjectHelper::getAutoCode('admin.tableclass.classvar.' . $tableName);
     $c->elements = array('var');
     $c->options['varscope'] = $builder->project->phpVersion == '4' ? 'var' : 'protected';
     $codes[] = $c;
     $c = EcrProjectHelper::getAutoCode('admin.viewlist.table.' . $tableName);
     $c->elements = array('header', 'cell');
     $codes[] = $c;
     $c = EcrProjectHelper::getAutoCode('admin.viewform.table.' . $tableName);
     $c->elements = array('row');
     $codes[] = $c;
     /*
      * Site
      */
     $c = EcrProjectHelper::getAutoCode('site.viewitem.div.' . $tableName);
     $c->elements = array('divrow');
     $codes[] = $c;
     $c = EcrProjectHelper::getAutoCode('site.viewcategory.table.' . $tableName);
     $c->elements = array('header', 'cell');
     $codes[] = $c;
     /* @var EcrProjectAutocode $autoCode */
     foreach ($codes as $autoCode) {
         foreach ($autoCode->elements as $acElement) {
             $key = $autoCode->getKey() . '.' . $acElement;
             $code = $autoCode->getCode($acElement, $table);
             $code = $autoCode->enclose($code, $key);
             $builder->replacements->addCustom($autoCode->getFormattedKey($key), $code);
             $autoCode->fields[$key] = $table->getFields();
             $autoCode->codes[$key] = $code;
             $autoCode->tables[$key] = $table;
         }
         $builder->project->addAutoCode($autoCode);
     }
     $builder->replacements->addCustom('#_ECR_ADMIN_LIST_COLSPAN_#', count($fields) + 2);
     return true;
 }