Example #1
0
 /**
  * Edit AutoCode.
  *
  * @return void
  */
 public function edit()
 {
     $input = JFactory::getApplication()->input;
     try {
         //-- Get the project
         $project = EcrProjectHelper::getProject();
     } catch (Exception $e) {
         EcrHtml::message($e);
         return;
     }
     //try
     $group = $input->get('group');
     $part = $input->get('part');
     $element = $input->get('element');
     $scope = $input->get('scope');
     $key = "{$scope}.{$group}.{$part}.{$element}";
     $AutoCode = EcrProjectHelper::getAutoCode($key);
     if (!$AutoCode) {
         echo '<h4 style="color: red;">AutoCode not found</h4>';
         echo $key;
         return;
     }
     if (!method_exists($AutoCode, 'edit')) {
         echo '<h4 style="color: red;">EDIT function not found</h4>';
         echo $key;
         return;
     }
     if (!isset($project->autoCodes[$AutoCode->getKey()])) {
         echo '<h4 style="color: red;">AutoCode not found in project</h4>';
         echo $AutoCode->getKey();
         return;
     }
     echo '<div style="color: blue; font-weight: bold; text-align:center;">' . ucfirst($group) . ' - ' . ucfirst($part) . '</div>';
     //-- Additional request vars
     echo '<input type="hidden" name="group" value="' . $group . '" />';
     echo '<input type="hidden" name="part" value="' . $part . '" />';
     echo $AutoCode->edit($project->autoCodes[$AutoCode->getKey()]);
     return;
 }
Example #2
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 #3
0
 /**
  * Updates AutoCode.
  *
  * @throws Exception
  * @return void
  */
 public function autocode_update()
 {
     $input = JFactory::getApplication()->input;
     $ecr_project = $input->get('ecr_project');
     $group = $input->get('group');
     $part = $input->get('part');
     $element = $input->get('element');
     $scope = $input->get('element_scope');
     $old_task = $input->get('old_task');
     $task = $old_task ? $old_task : 'stuffer';
     $input->set('task', $task);
     $input->set('view', 'stuffer');
     $key = "{$scope}.{$group}.{$part}.{$element}";
     try {
         if (false == ($AutoCode = EcrProjectHelper::getAutoCode($key))) {
             throw new Exception(jgettext('Unable to load Autocode') . sprintf(' [group, part] [%s, %s]', $group, $part));
         }
         if (false == method_exists($AutoCode, 'insert')) {
             throw new Exception(sprintf(jgettext('Insert method not found in Autocode %s'), $key));
         }
         $project = EcrProjectHelper::getProject();
         if (!$project->prepareAddPart($ecr_project)) {
             throw new Exception(sprintf(jgettext('Unable to prepare project [project, group, part] [%s, %s, %s]'), $ecr_project, $group, $part));
         }
         //-- Setup logging
         $buildOpts = $input->get('buildopts', array(), 'array');
         $buildOpts['fileName'] = date('ymd_Hi') . '_add_part.log';
         $logger = EcrLogger::getInstance('ecr', $buildOpts);
         $options = new stdClass();
         $options->ecr_project = $ecr_project;
         $options->group = $group;
         $options->part = $part;
         $options->pathSource = ECRPATH_AUTOCODES . DS . $scope . DS . $group . DS . $part . DS . 'tmpl';
         $string = '';
         $string .= '<h2>Add Element</h2>';
         $string .= 'Project: ' . $ecr_project . BR;
         $string .= 'Group: ' . $group . BR;
         $string .= 'Part:  ' . $part . BR;
         $string .= 'Source:' . BR . $options->pathSource;
         $string .= '<hr />';
         $logger->log($string);
         if (!$AutoCode->insert($project, $options, $logger)) {
             throw new Exception(jgettext('Unable to update AutoCode') . ' [group, part]', $group, $part);
         }
         EcrHtml::message(array(jgettext('AutoCode updated') . ' [group, part]', $group, $part));
     } catch (Exception $e) {
         EcrHtml::message($e);
         $logger->log($e->getMessage());
     }
     $logger->writeLog();
     parent::display();
 }
Example #4
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;
 }