Ejemplo n.º 1
0
 public function createCSS()
 {
     $images = array();
     $results = array();
     $name = array();
     $app = $this->data->app;
     $images = scandir("/home/ematos/public_html/maestro/apps/{$app}/public/images/32x32");
     foreach ($images as $image) {
         preg_match_all("/^[a-zA-Z0-9-_]+[^\\.]/", $image, $results[]);
     }
     $i = 0;
     foreach ($results as $r) {
         foreach ($r as $result) {
             $filename = $result[0];
             if ($filename[0] != NULL) {
                 $result[0] = ucfirst($result[0]);
                 $name[] = '.appIcon' . $result[0] . "{\nbackground-image: url(../images/32x32/" . $images[$i] . ");\n}\n";
             }
             $i++;
         }
     }
     $template = new MWizardTemplate();
     $template->resultFile = implode('', $name);
     $template->saveResult("/{$app}/public/css/style.css", 'public/files/base');
     $this->renderPrompt('information', 'Arquivo gerado com sucesso!');
 }
Ejemplo n.º 2
0
 function handleClass($elements)
 {
     //        $classNodes = $this->nodes['uml:Class'];
     $tab = '    ';
     $classNodes = $elements;
     $dbName = $this->databaseName;
     foreach ($classNodes as $node) {
         $properties = $methods = '';
         $id = $node->getAttributeNode('xmi:id')->value;
         $this->moduleName = $moduleName = $this->nodes['classModule'][$id];
         $this->className = $className = strtolower($node->getAttributeNode('name')->value);
         //mdump('handleClass = ' . $className);
         $document = $docassoc = $docattr = $attributes = array();
         $document[] = '';
         $document[] = $tab . 'public static function ORMMap() {';
         $document[] = '';
         $document[] = $tab . $tab . 'return array(';
         $document[] = $tab . $tab . $tab . "'class' => \\get_called_class(),";
         $document[] = $tab . $tab . $tab . "'database' => '{$dbName}',";
         if ($t = $this->getChild($node->firstChild->nextSibling, 'ormDetail')) {
             $tableId = $t->getAttributeNode('tableModel')->value;
             $table = $this->nodes['dbTable'][$tableId];
             if ($table->nodeType == XML_ELEMENT_NODE) {
                 $tableName = $table->getAttributeNode('name')->value;
                 $document[] = $tab . $tab . $tab . "'table' => '{$tableName}',";
             }
         }
         $extends = '';
         if ($generalization = $this->nodes['classGeneralization'][$id]) {
             $moduleSuperClass = $this->nodes['classModule'][$generalization];
             $superClass = $this->nodes['uml:Class'][$generalization];
             $extends = "\\" . $moduleSuperClass . "\\models\\" . $superClass->getAttributeNode('name')->value;
             $document[] = $tab . $tab . $tab . "'extends' => '{$extends}',";
             $reference = $this->getChild($node->firstChild->nextSibling, 'ormDetail');
             if ($reference) {
                 // //mdump('reference='.$reference->getAttributeNode('inheritanceStrategy')->value);
                 ////mdump($this->nodes['PK'][$generalization]);
                 $key = $this->nodes['PK'][$generalization];
                 $docattr[] = $tab . $tab . $tab . $tab . "'{$key[0]}' => array('column' => '{$key[1]}', 'key' => 'reference'),";
             }
         }
         $comment = $this->nodes['classComment'][$id];
         $noGenerator = $this->hasChild($node->firstChild->nextSibling, 'appliedStereotype', "Class_ORM No Generator_id");
         $idIdentity = $this->hasChild($node->firstChild->nextSibling, 'appliedStereotype', "Class_ORM ID Identity_id");
         $getterSetter = '';
         $n = $node->firstChild->nextSibling;
         while ($n) {
             if ($n->nodeType == XML_ELEMENT_NODE) {
                 if ($n->nodeName == 'ownedAttribute') {
                     $at = $n->getAttributeNode('name')->value;
                     $attributes[$at] = $at;
                     $attribute = $tab . $tab . $tab . "'{$at}' => array(";
                     if ($cmt = $this->getChild($n, 'ownedComment')) {
                         $c = $this->getChild($cmt, 'body');
                         $attrComment = str_replace("\n", "\n * ", $c->nodeValue);
                     }
                     if ($c = $this->getChild($n->firstChild->nextSibling, 'ormDetail')) {
                         $colId = $c->getAttributeNode('columnModel')->value;
                         $col = $this->nodes['dbColumn'][$colId];
                         if ($col->nodeType == XML_ELEMENT_NODE) {
                             $colName = $col->getAttributeNode('name')->value;
                             $attribute .= "'column' => '{$colName}'";
                         }
                     }
                     $isPK = false;
                     if ($c = $this->getChild($n->firstChild->nextSibling, 'appliedStereotype')) {
                         if ($c->getAttributeNode('xmi:value')->value == 'Attribute_PK_id') {
                             $attribute .= ",'key' => 'primary'";
                             $isPK = true;
                             if (!$noGenerator) {
                                 if ($idIdentity) {
                                     $attribute .= ",'idgenerator' => 'identity'";
                                 } else {
                                     $attribute .= ",'idgenerator' => 'seq_{$tableName}'";
                                 }
                             }
                         }
                         //if ($c->getAttributeNode('xmi:value')->value == 'Attribute_UpperCase_id') {
                         //    $attribute .= ",'converter' => 'uppercase'";
                         //}
                     }
                     $attrType = str_replace("_id", "", $n->getAttributeNode('type')->value);
                     $properties .= "\n    /**\n     * {$attrComment}\n     * @var {$attrType} \n     */";
                     $properties .= "\n    protected " . "\$" . $at . ";";
                     $getterSetter .= "\n    public function get" . ucfirst($at) . "() {\n        return \$this->{$at};\n    }\n";
                     $setterBody = '';
                     $lowerAttrType = strtolower($attrType);
                     if ($lowerAttrType == 'currency') {
                         $setterBody = "if (!(\$value instanceof \\MCurrency)) {\n            \$value = new \\MCurrency((float) \$value);\n        }\n        ";
                     } elseif ($lowerAttrType == 'date') {
                         $setterBody = "if (!(\$value instanceof \\MDate)) {\n            \$value = new \\MDate(\$value);\n        }\n        ";
                     } elseif ($lowerAttrType == 'timestamp') {
                         $setterBody = "if (!(\$value instanceof \\MTimeStamp)) {\n            \$value = new \\MTimeStamp(\$value);\n        }\n        ";
                     } elseif ($lowerAttrType == 'boolean') {
                         $setterBody = "\$value = ((\$value != '0') && (\$value != 0) && (\$value != '')) ? '1' : '0';\n        ";
                     }
                     if ($isPK) {
                         $setterBody .= "\$this->{$at} = (\$value ? : NULL);";
                     } else {
                         $setterBody .= "\$this->{$at} = \$value;";
                     }
                     $getterSetter .= "\n    public function set" . ucfirst($at) . "(\$value) {\n        {$setterBody}\n    }\n";
                     $columnType = $this->getType($n->getAttributeNode('type'));
                     $attribute .= ",'type' => '{$columnType}'),";
                     $docattr[] = $tab . $attribute;
                 }
             }
             $n = $n->nextSibling;
         }
         $properties .= "\n\n    /**\n     * Associations\n     */";
         if (count($this->nodes['Associations'][$id])) {
             foreach ($this->nodes['Associations'][$id] as $idA => $association) {
                 $i = 0;
                 $j = 0;
                 $class0 = $association[0]->getAttributeNode('type')->value;
                 $name0 = trim($association[0]->getAttributeNode('name')->value);
                 $class1 = $association[1]->getAttributeNode('type')->value;
                 $name1 = trim($association[1]->getAttributeNode('name')->value);
                 $attribute = '';
                 if ($class0 == $id && $name1 != '') {
                     $docassoc[] = $tab . $tab . $this->createAssociationNode($association[1], $association[0], $attribute, $params);
                     if ($attribute != '' && !$attributes[$attribute[0]]) {
                         $properties .= "\n    protected " . "\$" . $attribute[0] . ";";
                         $getterSetter .= "\n    public function get" . ucfirst($attribute[0]) . "() {\n        return \$this->{$attribute[0]};\n    }\n";
                         $getterSetter .= "\n    public function set" . ucfirst($attribute[0]) . "(\$value) {\n        \$this->{$attribute[0]} = \$value;\n    }\n";
                         $docattr[] = $tab . $tab . $tab . $tab . "'{$attribute[0]}' => array('column' => '{$attribute[0]}', 'key' => 'foreign', 'type' => '{$attribute[2]}'),";
                         $attributes[$attribute[0]] = $attribute[0];
                     }
                     $target = $name1;
                     $properties .= "\n    protected " . "\$" . $target . ";";
                     $type = $params['cardinality'] == 'oneToOne' ? $params['toClass'] : 'Association';
                     $methods .= "    /**\n     *\n     * @return {$type}\n     */\n    public function get" . ucfirst($target) . "() {\n        if (is_null(\$this->{$target})){\n            \$this->retrieveAssociation(\"{$target}\");\n        }\n        return  \$this->{$target};\n    }\n";
                     $methods .= "    /**\n     *\n     * @param {$type} \$value\n     */\n    public function set" . ucfirst($target) . "(\$value) {\n        \$this->{$target} = \$value;\n    }\n";
                     $methods .= "    /**\n     *\n     * @return {$type}\n     */\n    public function getAssociation" . ucfirst($target) . "() {\n        \$this->retrieveAssociation(\"{$target}\");\n    }\n";
                 }
                 if ($class1 == $id && $name0 != '') {
                     $docassoc[] = $tab . $tab . $this->createAssociationNode($association[0], $association[1], $attribute, $params);
                     if ($attribute != '' && !$attributes[$attribute[0]]) {
                         $properties .= "\n    protected " . "\$" . $attribute[0] . ";";
                         $getterSetter .= "\n    public function get" . ucfirst($attribute[0]) . "() {\n        return \$this->{$attribute[0]};\n    }\n";
                         $getterSetter .= "\n    public function set" . ucfirst($attribute[0]) . "(\$value) {\n        \$this->{$attribute[0]} = \$value;\n    }\n";
                         $docattr[] = $tab . $tab . $tab . $tab . "'{$attribute[0]}' => array('column' => '{$attribute[0]}', 'key' => 'foreign', 'type' => '{$attribute[2]}'),";
                         $attributes[$attribute[0]] = $attribute[0];
                     }
                     $target = $name0;
                     $properties .= "\n    protected " . "\$" . $target . ";";
                     $type = $params['cardinality'] == 'oneToOne' ? $params['toClass'] : 'Association';
                     $methods .= "    /**\n     *\n     * @return {$type}\n     */\n    public function get" . ucfirst($target) . "() {\n        if (is_null(\$this->{$target})){\n            \$this->retrieveAssociation(\"{$target}\");\n        }\n        return  \$this->{$target};\n    }\n";
                     $methods .= "    /**\n     *\n     * @param {$type} \$value\n     */\n    public function set" . ucfirst($target) . "(\$value) {\n        \$this->{$target} = \$value;\n    }\n";
                     $methods .= "    /**\n     *\n     * @return {$type}\n     */\n    public function getAssociation" . ucfirst($target) . "() {\n        \$this->retrieveAssociation(\"{$target}\");\n    }\n";
                 }
             }
         }
         if (count($especializations = $this->nodes['classEspecialization'][$id])) {
             foreach ($especializations as $especialization) {
                 $moduleSubClass = $this->nodes['classModule'][$especialization];
                 $subClass = $this->nodes['uml:Class'][$especialization];
                 $subClassName = lcfirst($subClass->getAttributeNode('name')->value);
                 $subClassNameFull = "\\" . $moduleSubClass . "\\models\\" . $subClassName;
                 $key = $this->nodes['PK'][$id];
                 $docassoc[] = $tab . $tab . $tab . $tab . "'{$subClassName}' => array('toClass' => '{$subClassNameFull}' , 'cardinality' => 'oneToOne' , 'keys' => '{$key[0]}:{$key[1]}' ),";
             }
         }
         $document[] = $tab . $tab . $tab . "'attributes' => array(";
         foreach ($docattr as $attr) {
             $document[] = $attr;
         }
         $document[] = $tab . $tab . $tab . "),";
         $document[] = $tab . $tab . $tab . "'associations' => array(";
         foreach ($docassoc as $assoc) {
             $document[] = $assoc;
         }
         $document[] = $tab . $tab . $tab . ")";
         $document[] = $tab . $tab . ");";
         $document[] = $tab . "}";
         /*
          $map = "/{$moduleName}/classes/map/{$className}.php";
          $this->generatedMaps[] = $map;
          file_put_contents($this->baseDir . $map, implode("\n", $document));
         */
         $map = implode("\n", $document);
         // generate PHP class
         $var['class'] = $className;
         $var['module'] = $moduleName;
         $var['properties'] = $properties;
         $var['methods'] = $getterSetter . $methods;
         $var['comment'] = $comment;
         $var['package'] = $this->package;
         $var['ormmap'] = $map;
         $var['extends'] = $extends;
         $fileName = array('/public/files/templates/map.php', "public/files/base/{$moduleName}/map/{$className}map.php");
         $template = new MWizardTemplate();
         $template->setVar($var);
         $template->setTemplate($fileName[0]);
         $template->applyClass();
         $template->saveResult($fileName[1]);
         $fileName = array('/public/files/templates/model.php', "public/files/base/{$moduleName}/{$className}.php");
         $template = new MWizardTemplate();
         $template->setVar($var);
         $template->setTemplate($fileName[0]);
         $template->applyClass();
         $template->saveResult($fileName[1]);
     }
 }
Ejemplo n.º 3
0
 public function generateEnumeration($className, $var)
 {
     // Create Model & Map
     $template = new MWizardTemplate();
     $template->setVar($var);
     $template->setTemplate('/public/files/templates/enummap.php');
     $template->applyClass();
     $template->saveResult("{$var['moduleName']}/models/map/{$className}map.php", $this->baseDir);
     $template = new MWizardTemplate();
     $template->setVar($var);
     $template->setTemplate('/public/files/templates/enummodel.php');
     $template->applyClass();
     $template->saveResult("{$var['moduleName']}/models/{$className}.php", $this->baseDir);
 }