예제 #1
0
 public function __construct($module, $item, $value, $defaults = null)
 {
     $this->value = $value;
     $this->module = $module;
     $this->item = $item;
     $this->defaults = $defaults;
     parent::__construct($module);
     if (file_exists(Manager::getModulePath($module, 'db/lookup.class')) && Manager::uses('/db/lookup.class', $module) || Manager::uses('/classes/lookup.class', $module)) {
         eval("\$object = new Business{$module}Lookup();");
         eval("\$info   = \$object->autoComplete{$item}(\$this,\$defaults);");
         parent::__construct($this->module);
         if ($info) {
             $this->result = $info;
         } else {
             //faz consulta
             $sql = new Msql('');
             $sql->createFrom($this->sql);
             $sql->prepare($value);
             $db = Manager::getDatabase($this->module);
             //$this->sql = MSql::prepare($this->sql,$value);
             //$result = $this->_db->query($value ? $sql->command : str_replace('?','NULL',$this->sql));
             $result = $db->query($value ? $sql->command : str_replace('?', 'NULL', $this->sql));
             $this->result = $result[0];
         }
     }
 }
예제 #2
0
 public function getDatabase($name)
 {
     return Manager::getDatabase($name);
 }
예제 #3
0
 /**
  * Brief Description.
  * Complete Description.
  *
  * @param $msg (tipo) desc
  *
  * @returns (tipo) desc
  *
  */
 private function handlerDb($msg)
 {
     $login = Manager::getLogin();
     $uid = $login ? $login->getLogin() : '';
     $ts = Manager::getSysTime();
     $db = Manager::getDatabase('manager');
     $idLog = $db->getNewId('seq_manager_log');
     $sql = new MSQL('idlog, timestamp, login, msg, host', 'manager_log');
     $db->execute($sql->insert(array($idLog, $ts, $uid, $msg, $this->host)));
 }
예제 #4
0
 public function generate()
 {
     $db = Manager::getDatabase($this->databaseName);
     $pf = $db->getPlatForm();
     $queryTables = $db->getQueryCommand($pf->getListTablesSQL());
     foreach ($queryTables->getResult() as $tables) {
         $table = $tables[0];
         $classes[$table]['name'] = $table;
         $queryColumns = $db->getQueryCommand($pf->getListTableColumnsSQL("`" . $table . "`"));
         $pk = 0;
         $binding = false;
         foreach ($queryColumns->getResult() as $column) {
             $col = "attributes['" . $column[0] . "'] = " . '"' . $column[0] . ',' . $this->getType($column[1]) . ',';
             $col .= ($column[2] == 'NO' ? 'not null' : '') . ',';
             if ($column[3] == 'PRI') {
                 ++$pk;
             }
             $col .= $column[3] == 'PRI' ? 'primary' : ($column[3] == 'MUL' ? 'foreign' : '');
             $col .= ($column[5] == 'auto_increment' ? ',identity' : '') . '"';
             $classes[$table]['columns'][] = $col;
         }
         if ($pk > 1) {
             $binding = $classes[$table]['binding'] = true;
         }
         $queryFK = $db->getQueryCommand($pf->getListTableForeignKeysSQL($table, $db->getConfig('dbname')));
         foreach ($queryFK->getResult() as $fk) {
             $associationName = str_ireplace('fk_', '', $fk[0]);
             $associationName = str_ireplace('has_', '', $associationName);
             $associationName = str_ireplace("{$table}_", '', $associationName);
             $associationName = str_ireplace(array('1', '2', '3'), '', $associationName);
             $associationName = strtolower($associationName);
             if (!$binding) {
                 $assoc = "association['" . $associationName . "'] = " . '"\\' . $this->appName . "\\models\\" . $fk[2] . ',';
                 $assoc .= "oneToOne," . $fk[1] . ':' . $fk[3] . '"';
                 $classes[$table]['associations'][$associationName] = $assoc;
                 // cria a inversa oneToMany
                 $associationName2 = ($fk[2] != $associationName ? $table . $associationName : $table) . 's';
                 $assoc2 = "association['" . $associationName2 . "'] = " . '"\\' . $this->appName . "\\models\\" . $table . ',oneToMany,' . $fk[3] . ':' . $fk[1] . '"';
                 $classes[$fk[2]]['associations'][$associationName2] = $assoc2;
             } else {
                 $classes[$table]['associations'][$associationName] = $fk[2];
             }
         }
         if ($binding) {
             // cria as inversas manyToMany
             foreach ($classes[$table]['associations'] as $associationName => $tableRef) {
                 foreach ($classes[$table]['associations'] as $associationName2 => $tableRef2) {
                     if ($associationName != $associationName2) {
                         $assoc2 = "association['" . $associationName2 . 's' . "'] = " . '"\\' . $this->appName . "\\models\\" . $tableRef2 . ',manyToMany,' . $table . '"';
                         $classes[$tableRef]['associations'][$associationName . 's'] = $assoc2;
                     }
                 }
             }
         }
     }
     $dbName = $this->databaseName;
     $moduleName = $this->moduleName;
     $document = array();
     $document[] = "[globals]";
     $document[] = "database = \"{$dbName}\"";
     $document[] = "app = \"{$this->appName}\"";
     $document[] = "module = \"{$this->moduleName}\"";
     $document[] = '';
     foreach ($classes as $class) {
         if ($class['name'] != '' && !$class['binding']) {
             $document[] = '[' . $class['name'] . ']';
             $document[] = 'table = "' . $class['name'] . '"';
             foreach ($class['columns'] as $column) {
                 $document[] = $column;
             }
             foreach ($class['associations'] as $association) {
                 $document[] = $association;
             }
             $document[] = '';
         }
     }
     $map = implode("\n", $document);
     $filename = $this->baseDir . '/' . $this->fileScript;
     file_put_contents($filename, $map);
 }