/**
  * Create and return an instance of the Middleware.
  *
  * @param  Interop\Container\ContainerInterface $container
  * @param  string $requestedName
  * @param  array $options
  * @return MiddlewareInterface
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $rqlParser = new Rest\Rql\RqlParser();
     $responseEncoder = new Rest\ResponseEncoder();
     $resourceName = $requestedName;
     //is there config for this resource?
     $config = $container->get('config');
     if (isset($config['resource'][$resourceName]['storeMiddleware'])) {
         $storeMiddlewareServiceName = $config['resource'][$resourceName]['storeMiddleware'];
         $storeMiddleware = $container->get($storeMiddlewareServiceName);
         return new restActionPipe($rqlParser, $storeMiddleware, $responseEncoder);
     }
     //is there table with same name?
     $db = $container->has('db') ? $container->get('db') : null;
     if (isset($db)) {
         $dbMetadata = new Zend\Db\Metadata\Metadata($db);
         $tableNames = $dbMetadata->getTableNames();
         if (isset($tableNames[$resourceName])) {
             $tableGateway = new TableGateway($resourceName, $db);
             $dataStore = new DbTable($tableGateway);
             $storeMiddleware = new StoreMiddleware($dataStore);
             return new Rest\RestActionPipe($rqlParser, $storeMiddleware, $responseEncoder);
         }
     }
     throw new DataStoresException('Can\'t make RestActionPipe' . ' for resource: ' . $resourceName);
 }
Пример #2
0
 /**
  * Função que retorna com os dados de preenchimento do formulário 
  * @return array 
  */
 public function populateForm($id)
 {
     $db = \Cityware\Db\Factory::factory('zend');
     $platform = $db->getAdapter()->getPlatform();
     /* Verifica o schema se está setado ou não */
     $schema = (isset($this->configForm['schema']) and !empty($this->configForm['schema'])) ? $this->configForm['schema'] : null;
     /* Define a tabela */
     $db->from($this->configForm['table'], 'tb', $schema);
     /* Define os campos */
     //$db->select('*');
     /* Define a coluna primária e monta a condição do SELECT */
     $metadata = new \Zend\Db\Metadata\Metadata($db->getAdapter());
     $constraints = $metadata->getTable($this->configForm['table'], $schema)->getConstraints();
     $varColunaPk = null;
     foreach ($constraints as $value) {
         if ($value->getType() == 'PRIMARY KEY') {
             $varColunaPk = $value->getColumns();
         }
     }
     $db->where($platform->quoteIdentifier('tb') . "." . $platform->quoteIdentifier(reset($varColunaPk)) . ' = ' . $id);
     /* Executa o SELECT */
     $db->setDebug(false);
     $rs = $db->executeSelectQuery();
     /* Formata qualquer coluta do tipo data */
     $return = \Cityware\Format\Date::formatDate($rs, 'd/m/Y');
     /* Retorna um array com os dados de preenchimento do formulário */
     return $return[0];
 }
Пример #3
0
 /**
  */
 public function getTableColumns($tableName)
 {
     $sm = $this->getServiceLocator();
     $adapter = $sm->get('Zend\\Db\\Adapter\\Adapter');
     $metadata = new \Zend\Db\Metadata\Metadata($this->adapter);
     $table = $metadata->getTable($tableName);
     return $table->getColumns();
 }
Пример #4
0
 /**
  * Função de criação dos arquivos de Formulário
  * @throws \Exception
  */
 private function createFormFiles()
 {
     $db = \Cityware\Db\Factory::factory('zend');
     $tableMetadata = new \Zend\Db\Metadata\Metadata($db->getAdapter());
     $tableInfo = $tableMetadata->getTable($this->getTable(), $this->getSchema());
     $iniFile = $this->genConfigFormIni();
     $iniFile .= $this->genFieldsFormIni($tableInfo);
     $iniFile .= $this->genButtonsFormIni();
     $translateFile = $this->genTranslateFormArray($tableInfo);
     $moduleName = ucfirst($this->getModule());
     $moduleNameLower = strtolower($this->getModule());
     try {
         if (!empty($this->formName)) {
             file_put_contents($this->dstIniDirectory . $this->formName . '.ini', $iniFile);
             chmod($this->dstIniDirectory . $this->formName . '.ini', 0777);
             file_put_contents($this->dstTranslateDirectory . $this->formName . '.php', $translateFile);
             chmod($this->dstTranslateDirectory . $this->formName . '.php', 0777);
             $template_Form = file_get_contents($this->srcTemplateDirectory . 'Template_Form.tmpl');
             $templateForm = str_replace("%moduleName%", $moduleName, str_replace("%moduleNameLower%", $moduleNameLower, $template_Form));
             file_put_contents($this->dstViewDirectory . $this->formName . '.phtml', $templateForm);
             chmod($this->dstViewDirectory . $this->formName . '.phtml', 0644);
         } else {
             file_put_contents($this->dstIniDirectory . 'add.ini', $iniFile);
             chmod($this->dstIniDirectory . 'add.ini', 0777);
             file_put_contents($this->dstTranslateDirectory . 'add.php', $translateFile);
             chmod($this->dstTranslateDirectory . 'add.php', 0777);
             file_put_contents($this->dstIniDirectory . 'edit.ini', $iniFile);
             chmod($this->dstIniDirectory . 'edit.ini', 0777);
             file_put_contents($this->dstTranslateDirectory . 'edit.php', $translateFile);
             chmod($this->dstTranslateDirectory . 'edit.php', 0777);
             $template_Form = file_get_contents($this->srcTemplateDirectory . 'Template_Form.tmpl');
             $templateForm = str_replace("%moduleName%", $moduleName, str_replace("%moduleNameLower%", $moduleNameLower, $template_Form));
             file_put_contents($this->dstViewDirectory . 'add.phtml', $templateForm);
             chmod($this->dstViewDirectory . 'add.phtml', 0644);
             file_put_contents($this->dstViewDirectory . 'edit.phtml', $templateForm);
             chmod($this->dstViewDirectory . 'edit.phtml', 0644);
         }
     } catch (Exception $exc) {
         throw new Exception('Não foi possivel criar o arquivo de configuração do formulário! <br />' . $exc->getMessage(), 500);
     }
 }
Пример #5
0
 public function selectVar($tableName, $where, $order = null, $fieldName = null)
 {
     //select name from table where id = 1;
     //ambil isi field di row 1 col 1
     $sql = new Sql($this->_storage->getAdapter());
     $metadata = new \Zend\Db\Metadata\Metadata($this->_storage->getAdapter());
     $field = $metadata->getColumns($tableName);
     $result = array();
     $query = $sql->select()->from($tableName)->columns(array($field[0]->getName()))->where($where)->limit(1);
     if ($order) {
         $query->order($order);
     }
     if ($fieldName) {
         $query->columns(array($fieldName));
     }
     $statement = $sql->prepareStatementForSqlObject($query);
     $response = $statement->execute();
     foreach ($response as $key => $value) {
         $result[$key] = $value;
     }
     return $result[$key];
 }
Пример #6
0
 function __construct(ServiceLocatorInterface $sl, $table, $id = null, $id_column = 'id')
 {
     $dbAdapter = $sl->get('Zend\\Db\\Adapter\\Adapter');
     $this->id_column = $id_column;
     $this->id_value = $id;
     $this->tableGateway = new TableGateway($table, $dbAdapter);
     if (!empty($this->id_value)) {
         $rs = $this->tableGateway->select(array($id_column => $id));
         if ($rs->count() > 0) {
             $data = $rs->current();
             foreach ($data as $k => $v) {
                 $this->addColumn($k, $v);
             }
         }
     } else {
         $metadata = new \Zend\Db\Metadata\Metadata($this->tableGateway->adapter);
         $columns = $metadata->getColumnNames($table);
         foreach ($columns as $column_name) {
             $this->addColumn($column_name, null);
         }
     }
 }
Пример #7
0
 /**
  * Função de criação dos arquivos do Datagrid
  * @throws \Exception
  */
 private function createDatagridFiles()
 {
     $db = \Cityware\Db\Factory::factory('zend');
     $tableMetadata = new \Zend\Db\Metadata\Metadata($db->getAdapter());
     $tableInfo = $tableMetadata->getTable($this->getTable(), $this->getSchema());
     $iniFile = $this->genConfigDatagridIni();
     $iniFile .= $this->genFieldsDatagridIni($tableInfo);
     $translateFile = $this->genTranslateDatagridArray($tableInfo);
     $moduleName = ucfirst($this->getModule());
     $moduleNameLower = strtolower($this->getModule());
     try {
         if (!empty($this->datagridName)) {
             file_put_contents(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'ini' . DS . strtolower($this->getController()) . DS . $this->datagridName . '.ini', $iniFile);
             chmod(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'ini' . DS . strtolower($this->getController()) . DS . $this->datagridName . '.ini', 0777);
             file_put_contents(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'translate' . DS . 'pt_BR' . DS . strtolower($this->getController()) . DS . $this->datagridName . '.php', $translateFile);
             chmod(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'translate' . DS . 'pt_BR' . DS . strtolower($this->getController()) . DS . $this->datagridName . '.php', 0777);
             $datagrid_template_phtml = file_get_contents(dirname(__FILE__) . DS . 'Datagrid' . DS . 'Template_Datagrid_Index.tpl');
             $datagridTemplatePhtml = str_replace("%moduleName%", $moduleName, str_replace("%moduleNameLower%", $moduleNameLower, $datagrid_template_phtml));
             file_put_contents(MODULES_PATH . ucfirst($this->getModule()) . DS . 'view' . DS . strtolower($this->getModule()) . DS . strtolower($this->getController()) . DS . $this->datagridName . '.phtml', $datagridTemplatePhtml);
             chmod(MODULES_PATH . ucfirst($this->getModule()) . DS . 'view' . DS . strtolower($this->getModule()) . DS . strtolower($this->getController()) . DS . $this->datagridName . '.phtml', 0644);
         } else {
             file_put_contents(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'ini' . DS . strtolower($this->getController()) . DS . 'datagrid.ini', $iniFile);
             chmod(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'ini' . DS . strtolower($this->getController()) . DS . 'datagrid.ini', 0777);
             file_put_contents(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'translate' . DS . 'pt_BR' . DS . strtolower($this->getController()) . DS . 'datagrid.php', $translateFile);
             chmod(MODULES_PATH . ucfirst($this->getModule()) . DS . 'src' . DS . ucfirst($this->getModule()) . DS . 'translate' . DS . 'pt_BR' . DS . strtolower($this->getController()) . DS . 'datagrid.php', 0777);
             $datagrid_template_phtml = file_get_contents(dirname(__FILE__) . DS . 'Datagrid' . DS . 'Template_Datagrid_Index.tpl');
             $datagridTemplatePhtml = str_replace("%moduleName%", $moduleName, str_replace("%moduleNameLower%", $moduleNameLower, $datagrid_template_phtml));
             file_put_contents(MODULES_PATH . ucfirst($this->getModule()) . DS . 'view' . DS . strtolower($this->getModule()) . DS . strtolower($this->getController()) . DS . 'index.phtml', $datagridTemplatePhtml);
             chmod(MODULES_PATH . ucfirst($this->getModule()) . DS . 'view' . DS . strtolower($this->getModule()) . DS . strtolower($this->getController()) . DS . 'index.phtml', 0644);
             $datagrid_template_trash = file_get_contents(dirname(__FILE__) . DS . 'Datagrid' . DS . 'Template_Datagrid_Trash.tpl');
             $datagridTemplateTrash = str_replace("%moduleName%", $moduleName, str_replace("%moduleNameLower%", $moduleNameLower, $datagrid_template_trash));
             file_put_contents(MODULES_PATH . ucfirst($this->getModule()) . DS . 'view' . DS . strtolower($this->getModule()) . DS . strtolower($this->getController()) . DS . 'trash.phtml', $datagridTemplateTrash);
             chmod(MODULES_PATH . ucfirst($this->getModule()) . DS . 'view' . DS . strtolower($this->getModule()) . DS . strtolower($this->getController()) . DS . 'trash.phtml', 0644);
         }
     } catch (Exception $exc) {
         throw new Exception('Não foi possivel criar o arquivo de configuração do Datagrid! <br />' . $exc->getMessage(), 500);
     }
 }
Пример #8
0
 /**
  * Generates PHP files with field names as constants
  */
 public function generateDbConstants()
 {
     $metadata = new \Zend\Db\Metadata\Metadata($this->dbAdapter);
     $schema = $this->dbAdapter->getDriver()->getConnection()->getCurrentSchema();
     $tables = $metadata->getTableNames($schema, true);
     foreach ($tables as $table) {
         $words = explode('_', $table);
         $class = 'Db';
         foreach ($words as $word) {
             $word[0] = strtoupper($word[0]);
             $class = $class . $word;
         }
         $filename = __DIR__ . '/../Utils/DbConsts/' . $class . '.php';
         if (file_exists($filename)) {
             unlink($filename);
         }
         $writer = new \Zend\Log\Writer\Stream($filename);
         $writer->setFormatter(new \Zend\Log\Formatter\Simple('%message%'));
         $logger = new \Zend\Log\Logger();
         $logger->addWriter($writer);
         $logger->info('<?php');
         $logger->info('');
         $logger->info('namespace Application\\Utils\\DbConsts;');
         $logger->info('');
         $logger->info("class {$class}");
         $logger->info('{');
         $logger->info("    const TABLE = '{$table}';");
         $columns = $metadata->getColumnNames($table, $schema);
         foreach ($columns as $column) {
             $logger->info(vsprintf("    const %s = '%s';", array(strtoupper($column), $column)));
         }
         $logger->info('');
         $hasConst = '
 static public function hasField($field) 
 {
     if (!is_string($field)) {
         return false;
     }
     $field = strtoupper($field);
     $reflect = new \\ReflectionClass(__CLASS__);
     foreach ($reflect->getConstants() as $name => $value) {
         if (strtoupper($value) === $field) {
             return true;
         }
     };
     return false;
 }';
         $logger->info($hasConst);
         $logger->info('}');
         $logger = null;
         chmod($filename, 0777);
     }
 }
Пример #9
0
 /**
  * Returns the column descriptions for a table.
  *
  * The return value is an associative array keyed by the column name,
  * as returned by the RDBMS.
  *
  * The value of each array element is an associative array
  * with the following keys:
  *
  * SCHEMA_NAME      => string; name of database or schema
  * TABLE_NAME       => string;
  * COLUMN_NAME      => string; column name
  * COLUMN_POSITION  => number; ordinal position of column in table
  * DATA_TYPE        => string; SQL datatype name of column
  * DEFAULT          => string; default expression of column, null if none
  * NULLABLE         => boolean; true if column can have nulls
  * LENGTH           => number; length of CHAR/VARCHAR
  * SCALE            => number; scale of NUMERIC/DECIMAL
  * PRECISION        => number; precision of NUMERIC/DECIMAL
  * UNSIGNED         => boolean; unsigned property of an integer type
  * PRIMARY          => boolean; true if column is part of the primary key
  * PRIMARY_POSITION => integer; position of column in primary key
  * IDENTITY         => integer; true if column is auto-generated with unique values
  *
  * @param string $tableName
  * @param string $schemaName OPTIONAL
  * @return array
  */
 public function describeTable($tableName, $schemaName = null)
 {
     $desc = [];
     $ddl = new \Zend\Db\Metadata\Metadata($this);
     $ddlTable = $ddl->getTable($tableName, $schemaName);
     $constraints = $ddlTable->getConstraints();
     foreach ($ddlTable->getColumns() as $ddlColumn) {
         $primary = false;
         foreach ($constraints as $constraint) {
             $primary = in_array($ddlColumn->getName(), $constraint->getColumns()) && $constraint->isPrimaryKey();
         }
         $desc[$ddlColumn->getName()] = array('SCHEMA_NAME' => null, 'TABLE_NAME' => $tableName, 'COLUMN_NAME' => $ddlColumn->getName(), 'COLUMN_POSITION' => $ddlColumn->getOrdinalPosition(), 'DATA_TYPE' => $ddlColumn->getDataType(), 'DEFAULT' => $ddlColumn->getColumnDefault(), 'NULLABLE' => $ddlColumn->isNullable(), 'LENGTH' => $ddlColumn->getCharacterMaximumLength(), 'SCALE' => $ddlColumn->getNumericScale(), 'PRECISION' => $ddlColumn->getNumericPrecision(), 'UNSIGNED' => $ddlColumn->isNumericUnsigned(), 'PRIMARY' => $primary, 'PRIMARY_POSITION' => 0, 'IDENTITY' => false);
     }
     return $desc;
 }
 public function fetchAllByUser($user_id, $assoc = false)
 {
     $select = new Select($this->table);
     $select->columns(array('id', 'user', 'table_name', 'columns_visible', 'sort', 'sort_order', STATUS_COLUMN_NAME, 'title', 'search_string'));
     $select->where->equalTo('user', $user_id)->isNull('title');
     $select->where('table_name NOT IN(
                 "directus_columns",
                 "directus_ip_whitelist",
                 "directus_preferences",
                 "directus_privileges",
                 "directus_settings",
                 "directus_storage_adapters",
                 "directus_tables",
                 "directus_tab_privileges",
                 "directus_ui"
             )');
     $metadata = new \Zend\Db\Metadata\Metadata($this->getAdapter());
     $tables = $metadata->getTableNames(DB_NAME);
     $tables = array_diff($tables, array("directus_columns", "directus_ip_whitelist", "directus_preferences", "directus_privileges", "directus_settings", "directus_storage_adapters", "directus_tables", "directus_tab_privileges", "directus_ui"));
     $rows = $this->selectWith($select)->toArray();
     $preferences = array();
     $tablePrefs = array();
     foreach ($rows as $row) {
         $tablePrefs[$row['table_name']] = $row;
     }
     //Get Default Preferences
     foreach ($tables as $key => $table) {
         // Honor ACL. Skip the tables that the user doesn't have access too
         if (!TableSchema::canGroupViewTable($table)) {
             continue;
         }
         $tableName = $table;
         if (!isset($tablePrefs[$table])) {
             $table = null;
         } else {
             $table = $tablePrefs[$table];
         }
         if (!isset($table['user'])) {
             $table = null;
         }
         $table = $this->constructPreferences($user_id, $tableName, $table);
         $preferences[$tableName] = $table;
     }
     return $preferences;
 }
Пример #11
0
 public function getForeignKey()
 {
     if ($this->getServiceLocator()->has('service_cache') && $this->getServiceLocator()->get('cache_metadata')['mode'] == 'enabled') {
         $this->foreign_key = $this->getCache()->getItem($this->table . '_ForeignKey');
         if (!empty($this->foreign_key) || $this->getCache()->hasItem($this->table . '_ForeignKey')) {
             return $this->foreign_key;
         }
     }
     $metaData = new \Zend\Db\Metadata\Metadata($this->getAdapter()->getAdapter());
     $table = $metaData->getTable($this->table);
     $contraints = $table->getConstraints();
     foreach ($contraints as $contraint) {
         if ($contraint->getType() == self::FOREIGN_KEY) {
             $this->foreign_key[implode("_", $contraint->getColumns())] = array("column" => $contraint->getColumns(), "tableref" => $contraint->getReferencedTableName(), "columnref" => $contraint->getReferencedColumns());
         }
     }
     if ($this->getServiceLocator()->has('service_cache') && $this->getServiceLocator()->get('cache_metadata')['mode'] == 'enabled') {
         $this->getCache()->setItem($this->table . '_ForeignKey', $this->foreign_key);
         # Tag the key when saving
         if (method_exists($this->getCache(), 'setTags')) {
             $this->getCache()->setTags($this->table . '_ForeignKey', array($this->table));
         }
     }
     return $this->foreign_key;
 }
Пример #12
0
 /**
  * Returns columns names
  *
  * @todo colocar no cache
  *
  * @return array columns
  */
 public function getColumns()
 {
     if (!isset($this->_columns)) {
         $metadata = new \Zend\Db\Metadata\Metadata($this->getTableGateway()->getAdapter());
         $this->_columns = $metadata->getColumnNames($this->getTable());
     }
     return $this->_columns;
 }
 /**
  */
 public function generateDbMapper()
 {
     $metadata = new \Zend\Db\Metadata\Metadata($this->adapter);
     // get the table names
     $tableNames = $metadata->getTableNames();
     echo "<pre>";
     foreach ($tableNames as $table) {
         echo '<br>Creating<strong> ' . $table . "</strong> ";
         $this->generateDirectoryPath();
         $this->generateClassFile($table, $metadata->getTable($table)->getColumns());
     }
     echo '<hr>---';
 }
Пример #14
0
 /**
  * Converts dtabase content to UTF-8
  *
  * @param string $prefix Specified table prefix
  * @param string $table  the table we want to convert datas from
  *
  * @return void
  */
 private function _convertContentToUTF($prefix, $table)
 {
     try {
         $query = 'SET NAMES latin1';
         $this->_db->query($query, Adapter::QUERY_MODE_EXECUTE);
     } catch (\Exception $e) {
         Analog::log('Cannot SET NAMES on table `' . $table . '`. ' . $e->getMessage(), Analog::ERROR);
     }
     try {
         $metadata = new \Zend\Db\Metadata\Metadata($this->_db);
         $tbl = $metadata->getTable($table);
         $columns = $tbl->getColumns();
         $constraints = $tbl->getConstraints();
         $pkeys = array();
         foreach ($constraints as $constraint) {
             if ($constraint->getType() === 'PRIMARY KEY') {
                 $pkeys = $constraint->getColumns();
             }
         }
         if (count($pkeys) == 0) {
             //no primary key! How to do an update without that?
             //Prior to 0.7, l10n and dynamic_fields tables does not
             //contains any primary key. Since encoding conversion is done
             //_before_ the SQL upgrade, we'll have to manually
             //check these ones
             if (preg_match('/' . $prefix . 'dynamic_fields/', $table) !== 0) {
                 $pkeys = array('item_id', 'field_id', 'field_form', 'val_index');
             } else {
                 if (preg_match('/' . $prefix . 'l10n/', $table) !== 0) {
                     $pkeys = array('text_orig', 'text_locale');
                 } else {
                     //not a know case, we do not perform any update.
                     throw new \Exception('Cannot define primary key for table `' . $table . '`, aborting');
                 }
             }
         }
         $select = $this->_sql->select($table);
         $results = $this->execute($select);
         foreach ($results as $row) {
             $data = array();
             $where = array();
             //build where
             foreach ($pkeys as $k) {
                 $where[] = $k . ' = "' . $row->{$k} . '"';
             }
             //build data
             foreach ($row as $key => $value) {
                 $data[$key] = $value;
             }
             //finally, update data!
             $update = $this->_sql->update($table);
             $update->set($data)->where($where);
             $this->execute($update);
         }
     } catch (\Exception $e) {
         Analog::log('An error occured while converting contents to UTF-8 for table ' . $table . ' (' . $e->getMessage() . ')', Analog::ERROR);
     }
 }
Пример #15
0
<?php

$adapter = (include file_exists('bootstrap.php') ? 'bootstrap.php' : 'bootstrap.dist.php');
refresh_data($adapter);
$metadata = new Zend\Db\Metadata\Metadata($adapter);
// get the table names
$tableNames = $metadata->getTableNames();
foreach ($tableNames as $tableName) {
    echo 'In Table ' . $tableName . PHP_EOL;
    $table = $metadata->getTable($tableName);
    echo '    With columns: ' . PHP_EOL;
    foreach ($table->getColumns() as $column) {
        echo '        ' . $column->getName() . ' -> ' . $column->getDataType() . PHP_EOL;
    }
    echo PHP_EOL;
    echo '    With constraints: ' . PHP_EOL;
    foreach ($metadata->getConstraints($tableName) as $constraint) {
        /** @var $constraint Zend\Db\Metadata\Object\ConstraintObject */
        echo '        ' . $constraint->getName() . ' -> ' . $constraint->getType() . PHP_EOL;
        if (!$constraint->hasColumns()) {
            continue;
        }
        echo '            column: ' . implode(', ', $constraint->getColumns());
        if ($constraint->isForeignKey()) {
            $fkCols = array();
            foreach ($constraint->getReferencedColumns() as $refColumn) {
                $fkCols[] = $constraint->getReferencedTableName() . '.' . $refColumn;
            }
            echo ' => ' . implode(', ', $fkCols);
        }
        echo PHP_EOL;
Пример #16
0
 /**
  * @desc Zwraca tylko nazwy kolumn danej tabeli
  * @param $sTabelaSlownikowa
  * @return array
  */
 public static function KolumnyNazwy($nazwaSlownika)
 {
     $metadata = new \Zend\Db\Metadata\Metadata(\Zend\Db\TableGateway\Feature\GlobalAdapterFeature::getStaticAdapter());
     $table = $metadata->getTable($nazwaSlownika);
     $aColumns = $table->getColumns();
     foreach ($aColumns as $oColumn) {
         $aColumnsName[] = $oColumn->getName();
     }
     return $aColumnsName;
 }
 public function fetchAllByUser($user_id, $assoc = false)
 {
     $select = new Select($this->table);
     $select->columns(['id', 'user', 'table_name', 'columns_visible', 'sort', 'sort_order', 'status', 'title', 'search_string']);
     $select->where->equalTo('user', $user_id)->isNull('title');
     $coreTables = SchemaManager::getDirectusTables(static::$IGNORED_TABLES);
     $select->where->addPredicate(new NotIn('table_name', $coreTables));
     $metadata = new \Zend\Db\Metadata\Metadata($this->getAdapter());
     $tables = $metadata->getTableNames();
     $tables = array_diff($tables, $coreTables);
     $rows = $this->selectWith($select)->toArray();
     $preferences = [];
     $tablePrefs = [];
     foreach ($rows as $row) {
         $tablePrefs[$row['table_name']] = $row;
     }
     //Get Default Preferences
     foreach ($tables as $key => $table) {
         // Honor ACL. Skip the tables that the user doesn't have access too
         if (!TableSchema::canGroupViewTable($table)) {
             continue;
         }
         $tableName = $table;
         if (!isset($tablePrefs[$table])) {
             $table = null;
         } else {
             $table = $tablePrefs[$table];
         }
         if (!isset($table['user'])) {
             $table = null;
         }
         $table = $this->constructPreferences($user_id, $tableName, $table);
         $preferences[$tableName] = $table;
     }
     return $preferences;
 }
Пример #18
0
 public function getColumnsArray()
 {
     $aColumns = array();
     $metadata = new \Zend\Db\Metadata\Metadata($this->adapter);
     $table = $metadata->getTable($this->getTable());
     $aColumnsList = $table->getColumns();
     foreach ($aColumnsList as $oColumn) {
         $aColumns[$oColumn->getName()] = '';
     }
     return $aColumns;
 }