Exemple #1
0
 public function init()
 {
     $moduleName = $this->getRequest()->getModuleName();
     $tableName = $this->getRequest()->getParam('table');
     $objectName = ZendT_Lib::convertTableNameToClassName($tableName);
     var_dump($moduleName, $tableName, $objectName);
     exit;
 }
Exemple #2
0
 /**
  * Remove o Controlador Gerado
  * 
  * @param string $pathBase
  * @param array $config 
  */
 public static function remove($pathBase, $config)
 {
     if (!isset($config['table']['modelName'])) {
         $config['table']['modelName'] = $config['table']['name'];
     }
     $table = ucfirst($config['table']['modelName']);
     $module = $config['table']['moduleName'];
     $pathBase = $path . '/application/configs/modules/' . strtolower($module);
     $tableClass = ZendT_Lib::convertTableNameToClassName($table);
     /**
      * Controller 
      */
     @unlink($pathBase . '/controllers/' . $tableClass . 'Controller.php');
 }
Exemple #3
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Monitor_Model_LogServerProcess_Element
  */
 public function getElement($columnName)
 {
     $_element = new Monitor_Form_LogServerProcess_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #4
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Tools_Model_Maillist_Element
  */
 public function getElement($columnName)
 {
     $_element = new Tools_Model_Maillist_Element();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #5
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Profile_Model_ObjectView_Element
  */
 public function getElement($columnName)
 {
     $_element = new Profile_Form_ObjectView_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #6
0
    /**
     * Cria as classes de Elemento 
     * 
     * @param string $pathBase
     * @param array $config 
     */
    public static function create($pathBase, $config)
    {
        if (!isset($config['table']['modelName'])) {
            $config['table']['modelName'] = $config['table']['name'];
        }
        $modelName = ZendT_Lib::convertTableNameToClassName($config['table']['modelName']);
        if ($config['table']['moduleName'] == '' || $config['table']['moduleName'] == 'Application') {
            $config['table']['moduleName'] = 'Application';
            $path = 'application/forms/Crud';
        } else {
            $path = 'application/modules/' . $config['table']['moduleName'] . '/forms/' . $modelName . '/Crud';
        }
        ZendT_Lib::createDirectory($pathBase, $path);
        $filename = $pathBase . '/' . $path . '/Elements.php';
        $strBody = '';
        foreach ($config['table']['columns'] as $column => $prop) {
            //echo $column . ' :: ' . $prop['object']['type'] . "\n";
            if (strpos($column, '_type') !== false || strpos($column, '_name') !== false) {
                $name = str_replace(array('_type', '_name'), '', $column);
                $_propLob = $config['table']['columns'][$name];
                if ($_propLob['object']['type'] == 'File') {
                    continue;
                }
            }
            $tableColumn = $column;
            $strValidators = '';
            if (is_array($prop['object']['validators'])) {
                foreach ($prop['object']['validators'] as $validator) {
                    $strValidators .= ",'{$validator['name']}'";
                }
            }
            $strValidators = 'array(' . substr($strValidators, 1) . ')';
            if ($prop['object']['type'] == 'Seeker') {
                $strAttrId = '';
                if (isset($prop['object']['seeker']['id'])) {
                    foreach ($prop['object']['seeker']['id'] as $key => $value) {
                        if ($value) {
                            $strAttrId .= ",'{$key}'=>'{$value}'";
                        }
                    }
                }
                $strAttrId = 'array(' . substr($strAttrId, 1) . ')';
                $strAttrSearch = '';
                if ($prop['object']['seeker']['search']) {
                    foreach ($prop['object']['seeker']['search'] as $key => $value) {
                        if ($value) {
                            $strAttrSearch .= ",'{$key}'=>'{$value}'";
                        }
                    }
                    //$strAttrSearch.= ",'id'=>'$tableColumn'";
                    $strAttrSearch = 'array(' . substr($strAttrSearch, 1) . ')';
                }
                $strAttrDisplay = '';
                if ($prop['object']['seeker']['display']) {
                    foreach ($prop['object']['seeker']['display'] as $key => $value) {
                        if ($value) {
                            $strAttrDisplay .= ",'{$key}'=>'{$value}'";
                        }
                    }
                }
                $strAttrDisplay = 'array(' . substr($strAttrDisplay, 1) . ')';
                $namePrepare = '';
                if (substr(strtolower($tableColumn), 0, 3) == 'id_') {
                    $nameSeeker = substr(strtolower($tableColumn), 3);
                    $namePrepare = "\$element->setSuffix('{$nameSeeker}');";
                } elseif (substr(strtolower($tableColumn), 0, 2) == 'id') {
                    $nameSeeker = substr(strtolower($tableColumn), 2);
                    $namePrepare = "\$element->setSuffix('{$nameSeeker}');";
                } elseif (substr(strtolower($tableColumn), strlen($tableColumn) - 3, 3) == '_id') {
                    $nameSeeker = substr(strtolower($tableColumn), 0, strlen($tableColumn) - 3);
                    $namePrepare = "\$element->setPrefix('{$nameSeeker}');";
                } elseif (substr(strtolower($tableColumn), strlen($tableColumn) - 2, 2) == 'id') {
                    $nameSeeker = substr(strtolower($tableColumn), 0, strlen($tableColumn) - 2);
                    $namePrepare = "\$element->setPrefix('{$nameSeeker}');";
                } else {
                    $nameSeeker = $tableColumn;
                    $namePrepare = "\$element->setSuffix('{$nameSeeker}');";
                }
                //
                if (!isset($prop['object']['seeker']['url']['mapperView'])) {
                    $mapperViewAux = explode('/', $prop['object']['seeker']['url']['grid']);
                    $mapperView['module'] = ucfirst($mapperViewAux[1]);
                    $mapperViewAux = explode('-', $mapperViewAux[2]);
                    $mapperView['name'] = '';
                    foreach ($mapperViewAux as $mapperViewName) {
                        $mapperView['name'] .= ucfirst($mapperViewName);
                    }
                    $prop['object']['seeker']['url']['mapperView'] = $mapperView['module'] . '_DataView_' . $mapperView['name'] . '_MapperView';
                }
                $commentElement = 'ZendT_Form_Element_Seeker';
                if ($prop['object']['seeker']['url']['retrieve'] == '') {
                    $prop['object']['seeker']['url']['retrieve'] = $prop['object']['seeker']['url']['retrive'];
                }
                $suffix = '';
                if (substr($column, 0, 3) == 'id_') {
                }
                if (!$config['table']['alias']) {
                    $config['table']['alias'] = $config['table']['name'];
                }
                $strElement = "\n        \$element = new ZendT_Form_Element_Seeker('{$column}');\n        {$namePrepare}\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setIdField('{$prop['object']['seeker']['field']['id']}');\n        \$element->setIdAttribs({$strAttrId});\n        \$element->setSearchField('{$prop['object']['seeker']['field']['search']}');\n        \$element->setSearchAttribs({$strAttrSearch});\n        \$element->modal()->setWidth({$prop['object']['seeker']['modal']['width']});\n        \$element->modal()->setHeight({$prop['object']['seeker']['modal']['height']});\n        \$element->url()->setGrid('{$prop['object']['seeker']['url']['grid']}');\n        \$element->url()->setSearch('{$prop['object']['seeker']['url']['search']}');\n        \$element->url()->setRetrieve('{$prop['object']['seeker']['url']['retrieve']}');\n        \$element->setMapperView('{$prop['object']['seeker']['url']['mapperView']}');\n        \$element->addValidators({$strValidators});\n                ";
                if ($prop['object']['seeker']['field']['display']) {
                    $strElement .= "\n        \$element->setDisplayField('{$prop['object']['seeker']['field']['display']}');\n        \$element->setDisplayAttribs({$strAttrDisplay});";
                }
                /* $strElement.= "
                   \$element->renderSeeker();"; */
            } elseif ($prop['object']['type'] == 'Hidden') {
                $commentElement = 'ZendT_Form_Element_Hidden';
                $strElement = "\n        \$element = new ZendT_Form_Element_Hidden('{$tableColumn}');\n        \$element->addValidators({$strValidators});\n                ";
            } elseif ($prop['object']['type'] == 'Select') {
                $strOptions = '';
                foreach ($prop['object']['listOptions'] as $key => $value) {
                    $strOptions .= "\n        \$element->addMultiOption('{$key}', '{$value}');";
                }
                $commentElement = 'ZendT_Form_Element_Select';
                $strElement = "\n        \$element = new ZendT_Form_Element_Select('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');{$strOptions}        \n                ";
            } elseif ($prop['object']['type'] == 'Date') {
                $strAttrbs = '';
                foreach ($prop['object']['date'] as $key => $value) {
                    if ($value) {
                        $strAttrbs .= ",'{$key}'=>'{$value}'";
                    }
                }
                $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                $commentElement = 'ZendT_Form_Element_Date';
                $strElement = "\n        \$element = new ZendT_Form_Element_Date('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setAttribs({$strAttrbs});\n        \$element->addValidators({$strValidators});\n                ";
            } elseif ($prop['object']['type'] == 'DateTime') {
                $strAttrbsDate = '';
                if ($prop['object']['date']) {
                    foreach ($prop['object']['date'] as $key => $value) {
                        if ($value) {
                            $strAttrbsDate .= ",'{$key}'=>'{$value}'";
                        }
                    }
                }
                $strAttrbsDate = 'array(' . substr($strAttrbsDate, 1) . ')';
                $strAttrbsTime = '';
                if ($prop['object']['time']) {
                    foreach ($prop['object']['time'] as $key => $value) {
                        $strAttrbsTime .= ",'{$key}'=>'{$value}'";
                    }
                    $strAttrbsTime = 'array(' . substr($strAttrbsTime, 1) . ')';
                }
                $commentElement = 'ZendT_Form_Element_DateTime';
                $strElement = "\n        \$element = new ZendT_Form_Element_DateTime('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setDateAttribs({$strAttrbsDate});\n        \$element->setTimeAttribs({$strAttrbsTime});\n        \$element->addValidators({$strValidators});\n        /*\$element->renderDateTime();*/\n                ";
            } elseif ($prop['object']['type'] == 'Time') {
                $strAttrbs = '';
                if ($prop['object']['time']) {
                    foreach ($prop['object']['time'] as $key => $value) {
                        if ($value) {
                            $strAttrbs .= ",'{$key}'=>'{$value}'";
                        }
                    }
                }
                $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                $commentElement = 'ZendT_Form_Element_Time';
                $strElement = "\n        \$element = new ZendT_Form_Element_Time('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setAttribs({$strAttrbs});\n        \$element->addValidators({$strValidators});\n                ";
            } elseif ($prop['object']['type'] == 'Textare' || $prop['object']['type'] == 'Textarea') {
                if (!$prop['object']['textare']) {
                    $prop['object']['textare'] = $prop['object']['textarea'];
                }
                if ($prop['object']['textare']['html']) {
                    $prop['object']['textare']['html'] = 1;
                } else {
                    $prop['object']['textare']['html'] = 0;
                }
                $strAttrbs = '';
                if ($prop['object']['textare']) {
                    foreach ($prop['object']['textare'] as $key => $value) {
                        if ($value) {
                            $strAttrbs .= ",'{$key}'=>'{$value}'";
                        }
                    }
                    $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                }
                $commentElement = 'ZendT_Form_Element_Textarea';
                $strElement = "\n        \$element = new ZendT_Form_Element_Textarea('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->enableEditorHtml({$prop['object']['textare']['html']});\n        \$element->setAttribs({$strAttrbs});        \n        \$element->addValidators({$strValidators});\n                ";
            } elseif ($prop['object']['type'] == 'File') {
                $strAttrbs = '';
                if ($prop['object']['file']) {
                    foreach ($prop['object']['file'] as $key => $value) {
                        if ($value) {
                            $strAttrbs .= ",'{$key}'=>'{$value}'";
                        }
                    }
                    $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                }
                $commentElement = 'ZendT_Form_Element_FileUpload';
                $strElement = "\n        \$element = new ZendT_Form_Element_FileUpload('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setAttribs({$strAttrbs});\n        \$element->enableMultiple(false);\n        \$element->addValidators({$strValidators});\n                ";
            } elseif ($prop['object']['type'] == 'Numeric' || $prop['object']['type'] == 'Decimal' || $prop['object']['type'] == 'decimal') {
                $strAttrbs = '';
                foreach ($prop['object']['numeric'] as $key => $value) {
                    if (!in_array($key, array('numDecimal', 'numInteger'))) {
                        if ($value) {
                            $strAttrbs .= ",'{$key}'=>'{$value}'";
                        }
                    }
                }
                $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                $commentElement = 'ZendT_Form_Element_Numeric';
                $strElement = "\n        \$element = new ZendT_Form_Element_Numeric('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setAttribs({$strAttrbs});\n        \$element->setJQueryParam('numDecimal','{$prop['object']['numeric']['numDecimal']}');\n        \$element->setJQueryParam('numInteger','{$prop['object']['numeric']['numInteger']}');\n        \$element->addValidators({$strValidators});\n                ";
            } elseif ($prop['object']['type'] == 'Text') {
                $strAttrbs = '';
                foreach ($prop['object']['text'] as $key => $value) {
                    if ($value) {
                        $strAttrbs .= ",'{$key}'=>'{$value}'";
                    }
                }
                $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                $commentElement = 'ZendT_Form_Element_Text';
                $strElement = "\n        \$element = new ZendT_Form_Element_Text('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setAttribs({$strAttrbs});        \n        \$element->addValidators({$strValidators});";
                if (count($prop['object']['filter']) > 0) {
                    $onBlur = '';
                    foreach ($prop['object']['filter'] as $function => $param) {
                        if (is_numeric($function)) {
                            $function = $param;
                            $param = array();
                        }
                        $function = $function . '(this.value';
                        if (count($param) > 0) {
                            $function .= ",'" . implode("','", $param) . "'";
                        }
                        $onBlur .= 'this.value=' . $function . ');';
                    }
                    $strElement .= "\n        \$element->addAttr('onBlur',\"" . $onBlur . "\");";
                }
                if ($prop['object']['mask']) {
                    if (!is_array($prop['object']['mask'])) {
                        $prop['object']['mask'] = array($prop['object']['mask']);
                    }
                    $charMask = $prop['object']['charMask'];
                    if (!is_array($charMask)) {
                        $charMask = "'" . $charMask . "'";
                    } else {
                        $charMask = " " . var_export($charMask, true) . " ";
                    }
                    $strElement .= "\n        \$element->setMask(" . var_export($prop['object']['mask'], true) . ");\n        \$element->setCharMask({$charMask});";
                }
            } elseif ($prop['object']['type'] == 'CgcCpf') {
                $strAttrbs = '';
                foreach ($prop['object']['text'] as $key => $value) {
                    if ($value) {
                        $strAttrbs .= ",'{$key}'=>'{$value}'";
                    }
                }
                $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                $commentElement = 'ZendT_Form_Element_CgcCpf';
                $strElement = "\n        \$element = new ZendT_Form_Element_CgcCpf('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setAttribs({$strAttrbs});        \n        \$element->addValidators({$strValidators});\n                ";
            } elseif ($prop['object']['type'] == 'Password') {
                $strAttrbs = '';
                if (isset($prop['object']['password'])) {
                    $prop['object']['text'] = $prop['object']['password'];
                }
                foreach ($prop['object']['text'] as $key => $value) {
                    if ($value) {
                        $strAttrbs .= ",'{$key}'=>'{$value}'";
                    }
                }
                $strAttrbs = 'array(' . substr($strAttrbs, 1) . ')';
                $commentElement = 'ZendT_Form_Element_Password';
                $strElement = "\n        \$element = new ZendT_Form_Element_Password('{$tableColumn}');\n        \$element->setLabel(\$this->_translate->_('{$config['table']['alias']}.{$tableColumn}') . ':');\n        \$element->setAttribs({$strAttrbs});        \n        \$element->addValidators({$strValidators});\n                ";
            }
            $strBody .= "\n    /**\n     *\n     * @return \\" . $commentElement . "\n     */\n    public function get" . ZendT_Lib::convertTableNameToClassName($column) . "(){\n{$strElement}\n        return \$element;\n    }\n            ";
        }
        $ucModuleName = ucfirst($config['table']['moduleName']);
        $contentText = <<<EOS
<?php
/**
 * Classe de mapeamento dos pontos de entrada da tabela {$config['table']['name']}
 */
class {$ucModuleName}_Form_{$modelName}_Crud_Elements
{
    protected \$_translate;

    public function __construct(){
        \$this->_translate = Zend_Registry::get('translate_{$config['table']['moduleName']}');
    }
        
    /**
     * Retorna as configurações do elemento HTML
     *
     * @param string \$columnName
     * @return {$ucModuleName}_Form_{$modelName}_Elements
     */
    public function getElement(\$columnName){
        \$method = 'get' . ZendT_Lib::convertTableNameToClassName(\$columnName);
        return \$this->\$method();
    }
     
    {$strBody}
}
?>
EOS;
        file_put_contents($filename, $contentText);
        $contentText = <<<EOS
<?php
/**
 * Classe de mapeamento dos pontos de entrada da tabela {$config['table']['name']}
 */
class {$ucModuleName}_Form_{$modelName}_Elements extends {$ucModuleName}_Form_{$modelName}_Crud_Elements
{

}
?>
EOS;
        $filename = str_replace("/Crud", "", $filename);
        if (!file_exists($filename)) {
            file_put_contents($filename, $contentText);
        }
    }
Exemple #7
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Wf_Model_WfProcesso_Element
  */
 public function getElement($columnName)
 {
     $_element = new Wf_Model_WfProcesso_Element();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #8
0
    /**
     * Cria as classes de Serviço 
     * 
     * @param string $pathBase
     * @param array $config 
     */
    public static function create($pathBase, $name, $module)
    {
        $modelName = ZendT_Lib::convertTableNameToClassName($name);
        $moduleName = $module;
        if ($moduleName == '' || $moduleName == 'Application') {
            $moduleName = 'Application';
            $path = 'application/reports';
        } else {
            $path = 'application/modules/' . $moduleName . '/reports';
        }
        $ucModuleName = ucfirst($moduleName);
        ZendT_Lib::createDirectory($pathBase, $path);
        $filename = $path . '/' . $modelName . '.php';
        $contentText = <<<EOS
<?php
    /**
     * Classe de relatório {$modelName}
     *
     * @package ZendT
     * @subpackage Report
     */
    class {$ucModuleName}_Report_{$modelName}{
        /**
         * @var ZendT_Report_Abstract
         */
        protected \$_report;
        /**
         * @var ZendT_Db_Mapper
         */
        protected \$_mapper;
        /**
         * Construtor
         */
        public function __construct(\$driver,ZendT_Db_Mapper \$_mapper){
            \$this->_report = ZendT_Report::factory(\$driver);
            \$this->_mapper = \$_mapper;
            
            \$this->_report->setTitle('Título do Relatório');
            \$this->_report->addPage();
            
            \$row = array();
            \$row['column'] = 'column';
            \$this->_addRow(\$row,true);
            \$this->_report->drawLine();
        }
        /**
         *
         * @param array \$row
         * @param bool \$title
         */
        private function _addRow(\$row,\$title=false){
            \$_cell = new ZendT_Report_Cell();
            \$_cell->setValue(\$row['column']);
            \$_cell->setWidth(200);
            \$_cell->setType('String');
            \$_cell->setFontWeight(\$title);
            \$this->_report->addCell(\$_cell);
            
            \$this->_report->printCells();
        }
        /**
         *
         * @return ZendT_Db_Recordset
         */
        private function _getRecodset(){
            \$sql = "SELECT * FROM ".\$this->_mapper->getModel()->getTableName();
            \$stmt = \$this->_mapper->getModel()->getAdapter()->query(\$sql);
            \$columnMappers = new ZendT_Db_Column_Mapper();
            \$columnMappers->add('column', \$this->_mapper->getColumn(true));
            \$rs = new ZendT_Db_Recordset(\$stmt,\$columnMappers,true);
            return \$rs;
        }
        /**
         *
         */
        private function _make(){
            \$recordset = \$this->_getRecodset();
            while(\$row = \$recordset->getRow()){
                \$this->_addRow(\$row,false);
            }
            \$this->_report->drawLine();
        }
        /**
         *
         */
        public function show(\$dest='S'){
            \$this->_make();
            return \$this->_report->output('relatorio',\$dest);
        }
    }
?>
EOS;
        file_put_contents($filename, $contentText);
    }
Exemple #9
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Log_Model_LogTabela_Element
  */
 public function getElement($columnName)
 {
     $_element = new Log_Form_LogTabela_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #10
0
    public static function createView($pathBase, $name, $configTable)
    {
        $modelName = ZendT_Lib::convertTableNameToClassName($configTable['table']['name']);
        $className = ZendT_Lib::convertTableNameToClassName($name);
        if ($configTable['table']['moduleName'] == '' || $configTable['table']['moduleName'] == 'Application') {
            $configTable['table']['moduleName'] = 'Application';
            $path = 'application/models/View';
        } else {
            $path = 'application/modules/' . $configTable['table']['moduleName'] . '/models/' . $modelName . '/View';
        }
        $ucModuleName = ucfirst($configTable['table']['moduleName']);
        ZendT_Lib::createDirectory($pathBase, $path);
        $contentText = <<<EOS
<?php
    /**
    * Classe de visão da tabela {$configTable['table']['name']}
    */
    class {$ucModuleName}_Model_{$modelName}_View_{$className} extends {$ucModuleName}_Model_{$modelName}_Mapper implements ZendT_Db_View
    {
        /**
         * Retorna as configurações padrão da visualização
         *
         * @return array
         */
        protected function _getSettingsDefault(){
           \$profile = array();
           \$profile['order'] = array();
           \$profile['width'] = array();
           \$profile['align'] = array();
           \$profile['hidden'] = array();
           \$profile['remove'] = array();
           \$profile['listOptions'] = array();
           return \$profile;
        }
        /**
         * Carrega as colunas com suas configurações 
         */
        protected function _loadColumns(){
            \$this->_columns = new ZendT_Db_Column_View('{$ucModuleName}_Model_{$modelName}_View_{$className}',\$this->_getSettingsDefault());
        }
        /**
         * Retorna o SQL Base
         */
        protected function _getSqlBase() {
            \$sql = \$this->getModel()->getTableName() . ' {$configTable['table']['name']} ';
            return \$sql;
        }
    }
?>
EOS;
        $filename = $path . '/' . $className . '.php';
        echo $filename;
        file_put_contents($filename, $contentText);
    }
Exemple #11
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Ca_Model_RegraContrato_Element
  */
 public function getElement($columnName)
 {
     $_element = new Ca_Form_RegraContrato_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #12
0
    /**
     * Cria as classes de Mappero 
     * 
     * @param string $pathBase
     * @param array $config 
     */
    public static function create($pathBase, $config)
    {
        if (!isset($config['table']['modelName'])) {
            $config['table']['modelName'] = $config['table']['name'];
        }
        $modelName = ZendT_Lib::convertTableNameToClassName($config['table']['modelName']);
        if ($config['table']['moduleName'] == '' || $config['table']['moduleName'] == 'Application') {
            $config['table']['moduleName'] = 'Application';
            $path = 'application/models/Crud';
        } else {
            $path = 'application/modules/' . $config['table']['moduleName'] . '/models/' . $modelName . '/Crud';
        }
        $ucModuleName = ucfirst($config['table']['moduleName']);
        ZendT_Lib::createDirectory($pathBase, $path);
        $tabs = $config['table']['tabs'];
        if (!$tabs) {
            $tabs = array();
        }
        $tabs = var_export($tabs, true);
        $strReferenceMap = '';
        foreach ($config['table']['referenceMaps'] as $prop) {
            $referenceName = ZendT_Lib::convertTableNameToClassName($prop['columnName']);
            $strReferenceMap .= ",\n                '" . $prop['columnName'] . "' => array(\n                    'mapper' => '" . str_replace('_Model_', '_DataView_', $prop['objectNameReference']) . "_MapperView',\n                    'column' => '" . $prop['columnReference'] . "'\n                )";
        }
        $strReferenceMap = substr($strReferenceMap, 1);
        $strBody = '';
        $strRequired = '';
        foreach ($config['table']['columns'] as $column => $prop) {
            //print_r($prop['object']['filter']);
            $strFilter = 'array(';
            if (isset($prop['object']['filter'])) {
                foreach ($prop['object']['filter'] as $key => $value) {
                    if (is_array($value)) {
                        $strFilter .= "'{$key}' => array('" . implode("','", $value) . "'), ";
                    } else {
                        $strFilter .= "'{$value}', ";
                    }
                }
            }
            $strFilter .= ')';
            $set = "\$this->_data['{$column}'] = \$value;";
            if (in_array($prop['object']['type'], array('Date', 'DateTime', 'Time'))) {
                $set = "\$this->_data['{$column}'] = new ZendT_Type_Date(\$value,'{$prop['object']['type']}');";
                $set .= "\n         if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                    ";
            } elseif (in_array($prop['object']['type'], array('Numeric', 'Integer')) || in_array($prop['type'], array('Numeric', 'Integer'))) {
                #echo $column . "\n";
                $numDecimal = $prop['object']['numeric']['numDecimal'];
                if (strtolower($prop['object']['type']) == strtolower('Seeker') || in_array(strtolower($column), $config['table']['primary'])) {
                    $numDecimal = 'null';
                } else {
                    if (!$numDecimal) {
                        $numDecimal = 0;
                    }
                }
                $set = "\$this->_data['{$column}'] = new ZendT_Type_Number(\$value,array('numDecimal'=>{$numDecimal}));";
                $set .= "\n         if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                    ";
            } else {
                if (in_array($prop['type'], array('StringLong'))) {
                    $set = "\n         \$this->_data['{$column}'] = new ZendT_Type_Clob(\$value);";
                    $set .= "\n         if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                ";
                } else {
                    if (in_array($prop['object']['type'], array('File'))) {
                        $set = "\$this->_data['{$column}'] = new ZendT_Type_Blob(\$value);\n         if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                ";
                    } else {
                        if ($prop['object']['mask'] != NULL) {
                            $set = "\$this->_data['{$column}'] = new ZendT_Type_String(\$value,array('mask'=>" . var_export($prop['object']['mask'], true) . "\n                                                                   ,'charMask'=>" . var_export($prop['object']['charMask'], true) . "\n                                                                   ,'filterDb'=>" . var_export($prop['object']['filterDb'], true) . "\n                                                                   ,'filter'=>" . $strFilter . "));\n        if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                ";
                        } else {
                            if (in_array($prop['object']['type'], array('Text'))) {
                                $set = "\$this->_data['{$column}'] = new ZendT_Type_String(\$value,array('mask'=>''\n                                                                   ,'charMask'=>''\n                                                                   ,'filterDb'=>" . var_export($prop['object']['filterDb'], true) . "\n                                                                   ,'filter'=>" . $strFilter . "));\n        if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                ";
                            } else {
                                if (in_array($prop['object']['type'], array('Select'))) {
                                    $varListOptions = array();
                                    foreach ($prop['object']['listOptions'] as $key => $value) {
                                        if ((string) $key != '') {
                                            $varListOptions[] = "'" . $key . "'=>'" . $value . "'";
                                        }
                                    }
                                    $set = "\n        \$options['listOptions']=array(" . implode(',', $varListOptions) . ");\n        \$this->_data['{$column}'] = new ZendT_Type_String(\$value,\$options);\n        if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                ";
                                } else {
                                    $set = "\$this->_data['{$column}'] = new ZendT_Type_String(\$value);\n        if (\$options['db'])\n            \$this->_data['{$column}']->setValueFromDb(\$value);\n                ";
                                }
                            }
                        }
                    }
                }
            }
            $strValidators = '';
            if ($prop['object']['required']) {
                $strRequired .= ",'{$column}'";
                $strValidators .= "\n         if (\$options['required'])\n            \$this->isRequired(\$value,'{$column}');\n                    ";
            }
            if (is_array($prop['object']['validators'])) {
                foreach ($prop['object']['validators'] as $validator) {
                    $strValidators .= "\n            \$valid = new " . $validator['name'] . "(" . str_replace("\n", " ", var_export($validator['param'], true)) . " );\n            \$valueValid = \$this->_data['{$column}']->getValueToDb();\n            if (\$valueValid && !\$valid->isValid(\$valueValid)){\n                throw new ZendT_Exception_Business(implode(\"\\n\",\$valid->getMessages()));\n            }\n                    ";
                }
            }
            $strBody .= "\n    /**\n     * Retorna os dados da coluna {$column}\n     *\n     * @return string\n     */\n    public function get" . ZendT_Lib::convertTableNameToClassName($column) . "(\$instance=false){\n        if (\$instance && !is_object(\$this->_data['{$column}'])){\n            \$this->set" . ZendT_Lib::convertTableNameToClassName($column) . "('',array('required'=>false));\n        }\n        return \$this->_data['{$column}'];\n    }\n    /**\n     * Seta o valor da coluna {$column}\n     *\n     * @param string \$value\n     * @return {$ucModuleName}_Model_{$modelName}_Crud_Mapper\n     */\n    public function set" . ZendT_Lib::convertTableNameToClassName($column) . "(\$value,\$options=array('required'=>true)){        \n        {$set}\n        if (!\$options['db']){\n            {$strValidators}\n        }\n        return \$this;\n    }\n\n            ";
        }
        if (!isset($config['table']['columns']['id'])) {
            $get = '';
            $set = "\n            \$this->_id = \$value;\n            \$values = explode('-',\$value);\n";
            foreach ($config['table']['primary'] as $key => $column) {
                $get .= ".'-'.\$this->_data['{$column}']";
                $set .= "\n            \$this->_data['{$column}'] = \$values[{$key}];";
            }
            $get = substr($get, 5);
            $strBody .= "\n    /**\n     * Retorna o dado da coluna ID\n     *\n     * @return string\n     */\n    public function getId(\$instance=false,\$retDataId=true){\n        if (\$retDataId && \$this->_id){\n            \$string = \$this->_id;\n        }else{            \n            \$string = {$get};\n            \$this->_id = \$string;\n        }\n        \$result = new ZendT_Type_Default(\$string);\n        return \$result;\n    }\n    /**\n     * Configura o dado na coluna ID\n     *\n     * @param string \$value\n     * @return {$ucModuleName}_Model_{$modelName}_Crud_Mapper\n     */\n    public function setId(\$value,\$options=array('required'=>true)){\n        #if (!\$options['db']){\n            {$set}\n        #}\n        return \$this;\n    }\n    /**\n     * Altera o registro da tabela\n     *\n     * @param ZendT_Db_Where\n     * @return int|array\n     */\n    public function update(\$where=null){\n        if (\$where == null){\n            \$where = \$this->getValueOld()->getWhere();\n        }\n        return parent::update(\$where);\n    }\n            ";
        }
        $strRequired = substr($strRequired, 1);
        $contentText = <<<EOS
<?php
/**
 * Classe de mapeamento do registro da tabela {$config['table']['name']}
 */
class {$ucModuleName}_Model_{$modelName}_Crud_Mapper extends ZendT_Db_Mapper
{
    protected \$_required = array({$strRequired});
    protected \$_model = '{$ucModuleName}_Model_{$modelName}_Table';
    public static \$table = '{$config['table']['schema']}.{$config['table']['name']}';
    /**
     *
     * @var {$ucModuleName}_Model_{$modelName}_Mapper
     */
    protected \$_dataOld = null;     
    /**
     * Retorna o valor antigo do registro antes de realizar a atualização
     *
     * @return {$ucModuleName}_Model_{$modelName}_Mapper
     */
    public function getValueOld(){
        if (!\$this->_dataOld instanceof {$ucModuleName}_Model_{$modelName}_Mapper){
            \$this->_dataOld = new {$ucModuleName}_Model_{$modelName}_Mapper();
            \$this->_dataOld->setId(\$this->getId());
            \$this->_dataOld->retrive();
        }
        return \$this->_dataOld;
    }
    /**
     * Retorna as referências do objeto
     */
    public function getReferenceMap(){
        return array({$strReferenceMap});
    }
    /**
     * @retun array
     */
    public function getTabs(){
        return {$tabs};
    }
    
    {$strBody}
}
?>
EOS;
        $filename = $path . '/Mapper.php';
        file_put_contents($filename, $contentText);
        $contentText = <<<EOS
<?php
/**
 * Classe de mapeamento do registro da tabela {$config['table']['name']}
 */
class {$ucModuleName}_Model_{$modelName}_Mapper extends {$ucModuleName}_Model_{$modelName}_Crud_Mapper
{

}
?>
EOS;
        $filename = str_replace("/Crud", "", $filename);
        if (!file_exists($filename)) {
            file_put_contents($filename, $contentText);
        }
    }
Exemple #13
0
    /**
     * Cria o modelo do desenvolvedor que pode manipular os dados
     * 
     * @param string $pathBase
     * @param array $config 
     */
    public static function developerTable($pathBase, $config)
    {
        if (!isset($config['table']['modelName'])) {
            $config['table']['modelName'] = $config['table']['name'];
        }
        $modelName = ZendT_Lib::convertTableNameToClassName($config['table']['modelName']);
        if ($config['table']['moduleName'] == '' || $config['table']['moduleName'] == 'Application') {
            $config['table']['moduleName'] = 'Application';
            $path = 'application/models';
        } else {
            $path = 'application/modules/' . $config['table']['moduleName'] . '/models/' . $modelName;
        }
        ZendT_Lib::createDirectory($pathBase, $path);
        $filename = $pathBase . '/' . $path . '/Table.php';
        $ucModuleName = ucfirst($config['table']['moduleName']);
        $contentText = <<<EOS
<?php
    /**
     * Classe de mapeamento da tabela {$config['table']['name']}
     */
    class {$ucModuleName}_Model_{$modelName}_Table extends {$ucModuleName}_Model_{$modelName}_Crud_Table{

    }
?>
EOS;
        if (!file_exists($filename)) {
            file_put_contents($filename, $contentText);
        }
    }
Exemple #14
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Financeiro_Model_Banco_Element
  */
 public function getElement($columnName)
 {
     $_element = new Financeiro_Form_Banco_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #15
0
 public function factory($table, $module)
 {
     $this->_loadProfile(self::NO_PROFILE_THROW_EXCEPTION);
     $path = $this->_loadedProfile->getAttribute('projectDirectory');
     $dirModules = $path . '/application/configs/modules';
     if (!is_dir($dirModules)) {
         mkdir($dirModules);
     }
     $dirModule = $dirModules . '/' . $module;
     if (!is_dir($dirModule)) {
         mkdir($dirModule);
     }
     $fileName = $dirModule . '/' . $table . '.php';
     if (!file_exists($fileName)) {
         throw new Zend_Tool_Project_Provider_Exception('Para executar essa ação é necessário criar o arquivo ' . $fileName);
     }
     $config = (require $fileName);
     $path .= '/application/modules/' . strtolower($module);
     /**
      * Gerando o DataView 
      */
     if (!isset($config['table']['modelName'])) {
         $config['table']['modelName'] = $config['table']['name'];
     }
     $modelName = ZendT_Lib::convertTableNameToClassName($config['table']['modelName']);
     /**
      * 
      */
     if (file_exists($path . '/models/' . $modelName . '/MapperView.php')) {
         ZendT_Lib::createDirectory($path, '/data-views/' . $modelName . '/Crud');
         copy($path . '/models/' . $modelName . '/Crud/MapperView.php', $path . '/data-views/' . $modelName . '/Crud/MapperView.php');
         unlink($path . '/models/' . $modelName . '/Crud/MapperView.php');
         $content = file_get_contents($path . '/data-views/' . $modelName . '/Crud/MapperView.php');
         $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_Crud_MapperView', $content);
         file_put_contents($path . '/data-views/' . $modelName . '/Crud/MapperView.php', $content);
         copy($path . '/models/' . $modelName . '/MapperView.php', $path . '/data-views/' . $modelName . '/MapperView.php');
         unlink($path . '/models/' . $modelName . '/MapperView.php');
         $content = file_get_contents($path . '/data-views/' . $modelName . '/MapperView.php');
         $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_MapperView', $content);
         $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_Crud_MapperView', $content);
         file_put_contents($path . '/data-views/' . $modelName . '/MapperView.php', $content);
         $content = file_get_contents($path . '/controllers/' . $modelName . 'Controller.php');
         $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_MapperView', $content);
         file_put_contents($path . '/controllers/' . $modelName . 'Controller.php', $content);
         $this->_print('Objeto MapperView fatorado com sucesso!');
     } else {
         $this->_print('Objeto MapperView já fatorado');
     }
     /**
      * 
      */
     if (file_exists($path . '/models/' . $modelName . '/Element.php')) {
         copy($path . '/models/' . $modelName . '/Crud/Element.php', $path . '/forms/' . $modelName . '/Crud/Elements.php');
         unlink($path . '/models/' . $modelName . '/Crud/Element.php');
         $content = file_get_contents($path . '/forms/' . $modelName . '/Crud/Elements.php');
         $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_Element', ucfirst($module) . '_Form_' . $modelName . '_Crud_Elements', $content);
         file_put_contents($path . '/forms/' . $modelName . '/Crud/Elements.php', $content);
         copy($path . '/models/' . $modelName . '/Element.php', $path . '/forms/' . $modelName . '/Elements.php');
         unlink($path . '/models/' . $modelName . '/Element.php');
         $content = file_get_contents($path . '/forms/' . $modelName . '/Elements.php');
         $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Element', ucfirst($module) . '_Form_' . $modelName . '_Elements', $content);
         $content = str_replace(ucfirst($module) . '_Model_' . $modelName . '_Crud_Element', ucfirst($module) . '_Form_' . $modelName . '_Crud_Elements', $content);
         file_put_contents($path . '/forms/' . $modelName . '/Elements.php', $content);
         $this->_print('Objeto Element fatorado com sucesso!');
     } else {
         $this->_print('Objeto Element já fatorado');
     }
     ZendT_Lib::replaceFiles($path, ucfirst($module) . '_Model_' . $modelName . '_MapperView', ucfirst($module) . '_DataView_' . $modelName . '_MapperView');
     ZendT_Lib::replaceFiles($path, ucfirst($module) . '_Model_' . $modelName . '_Element', ucfirst($module) . '_Form_' . $modelName . '_Elements');
     $path = $this->_loadedProfile->getAttribute('projectDirectory');
     $this->_print(' Criando Tables ');
     ZendT_Tool_Crud_Table::create($path, $config);
     $this->_print(' Criando Mappers ');
     ZendT_Tool_Crud_Mapper::create($path, $config);
     $this->_print(' Criando MapperView ');
     ZendT_Tool_Crud_MapperView::create($path, $config);
     $this->_print(' Criando Elements ');
     ZendT_Tool_Crud_Element::create($path, $config);
     $this->_print(' Criando Form ');
     ZendT_Tool_Crud_Form::create($path, $config);
     $this->_print(' Criando Bootstrap ');
     ZendT_Tool_Crud_Bootstrap::create($path, $config, 1);
     $this->_print('Finalizado Factory ' . $table);
 }
Exemple #16
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Cms_Model_Notificacao_Element
  */
 public function getElement($columnName)
 {
     $_element = new Cms_Form_Notificacao_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #17
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Auth_Model_ContaEmpresa_Element
  */
 public function getElement($columnName)
 {
     $_element = new Auth_Form_ContaEmpresa_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #18
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Vendas_Model_ItemLanc_Element
  */
 public function getElement($columnName)
 {
     $_element = new Vendas_Form_ItemLanc_Elements();
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $_element->{$method}();
 }
Exemple #19
0
 /**
  * Retorna as configurações do elemento HTML
  *
  * @param string $columnName
  * @return Auth_Form_Privilegio_Elements
  */
 public function getElement($columnName)
 {
     $method = 'get' . ZendT_Lib::convertTableNameToClassName($columnName);
     return $this->{$method}();
 }
Exemple #20
0
    /**
     * Cria o formulário de edição
     * 
     * @param string $pathBase
     * @param array $config 
     */
    public static function editForm($pathBase, $config)
    {
        if (!isset($config['table']['modelName'])) {
            $config['table']['modelName'] = $config['table']['name'];
        }
        $modelName = ZendT_Lib::convertTableNameToClassName($config['table']['modelName']);
        if ($config['table']['moduleName'] == '' || $config['table']['moduleName'] == 'Application') {
            $config['table']['moduleName'] = 'Application';
            $path = 'application/forms';
        } else {
            $path = 'application/modules/' . $config['table']['moduleName'] . '/forms/' . $modelName . '/Crud';
        }
        $ucModuleName = ucfirst($config['table']['moduleName']);
        ZendT_Lib::createDirectory($pathBase, $path);
        $filename = $path . '/Edit.php';
        $strBody = '';
        foreach ($config['table']['columns'] as $column => $prop) {
            if (strpos($column, '_type') !== false || strpos($column, '_name') !== false) {
                $name = str_replace(array('_type', '_name'), '', $column);
                $_propLob = $config['table']['columns'][$name];
                if ($_propLob['object']['type'] == 'File') {
                    continue;
                }
            }
            if ($prop['multiple']) {
                $strBody .= "\n        for(\$i=0; \$i<\$this->_multiple['{$column}']; \$i++){\n            \$element = \$model->getElement('{$column}[\$i]');";
                if ($prop['object']['required']) {
                    $strBody .= "\n            \$element->setRequired(true);";
                }
                $strBody .= "\n            \$element->setBelongsTo('{$column}');\n        }\n                ";
            } else {
                $strBody .= "\n            \$element = \$model->getElement('{$column}');";
                if ($prop['object']['required']) {
                    $strBody .= "\n            \$element->setRequired(true);";
                }
            }
            if (count($config['table']['primary']) == 1) {
                if (strtolower($config['table']['primary'][0]) == strtolower($column)) {
                    $strBody .= "\n            \$element->addDecorator(new ZendT_Form_Decorator_Hidden());\n            \$element->setRequired(false);\n                    ";
                }
            }
            $strBody .= "\n            \$this->addElement(\$element);\n\n            ";
        }
        $elementId = '';
        if (count($config['table']['primary']) > 1) {
            $elementId .= "\n            \$element = new ZendT_Form_Element_Hidden('id');\n            \$element->addDecorator(new ZendT_Form_Decorator_Hidden());\n            \$element->setRequired(false);\n            \$this->addElement(\$element);\n            ";
        }
        $url = 'array()';
        if (count($config['table']['form']['url']) > 1) {
            $url = var_export($config['table']['form']['url'], true);
        }
        $formName = strtolower($config['table']['name']);
        $contentText = <<<EOS
<?php
    class {$ucModuleName}_Form_{$modelName}_Crud_Edit extends ZendT_Form {
        /**
         * Configura se uma coluna é multipla
         * @var array
         */
        protected \$_multiple;
        /**
         * @var array
         */
        protected \$_url = {$url};
        /**
         * Carrega os elementos no formulário para serem renderizado
         * @return void
         */
        public function loadElements(\$action='insert') {
            \$this->setName('frm_{$formName}');
            {$elementId}
    
            \$model = new {$ucModuleName}_Form_{$modelName}_Elements();
            {$strBody}
        }
        /**
         * Configura uma coluna para ser multipla, ou seja,
         * transformar um dado em array
         *
         * @return void
         */        
        public function setMultiple(\$column,\$numRepeat){
            \$this->_multiple[\$column] = \$numRepeat;
        }
    }
?>
EOS;
        file_put_contents($filename, $contentText);
        $contentText = <<<EOS
<?php
    class {$ucModuleName}_Form_{$modelName}_Edit extends {$ucModuleName}_Form_{$modelName}_Crud_Edit {
        /**
         * Carrega os elementos no formulário para serem renderizado
         * @return void
         */
        public function loadElements(\$action='insert') {
            parent::loadElements(\$action);
        }
    }
?>
EOS;
        if (!file_exists(str_replace('/Crud', '', $filename))) {
            file_put_contents(str_replace('/Crud', '', $filename), $contentText);
        }
    }