/** * 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; }
/** * 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; }