protected function createSource() { $source = new \Mesour\Sources\NetteDbTableSource('users', 'id', $this->user, $this->context); $dataStructure = $source->getDataStructure(); $dataStructure->renameColumn('groups', 'group'); $dataStructure->renameColumn('user_addresses', 'addresses'); $dataStructure->renameColumn('wallets', 'wallet'); /** @var \Mesour\Sources\Structures\Columns\ManyToOneColumnStructure $groupColumn */ $groupColumn = $dataStructure->getColumn('group'); $groupColumn->setPattern('{name} ({members})'); /** @var \Mesour\Sources\Structures\Columns\OneToManyColumnStructure $addressColumn */ $addressColumn = $dataStructure->getColumn('addresses'); $addressColumn->setPattern('{street}, {zip} {city}, {country}'); /** @var \Mesour\Sources\Structures\Columns\ManyToManyColumnStructure $companiesColumn */ $companiesColumn = $dataStructure->getColumn('companies'); $companiesColumn->setPattern('{name}'); /** @var \Mesour\Sources\Structures\Columns\OneToOneColumnStructure $walletColumn */ $walletColumn = $dataStructure->getColumn('wallet'); $walletColumn->setPattern('{amount}'); return $source; }
\Tracy\Debugger::$strictMode = true; $loader = new Nette\Loaders\RobotLoader(); $loader->addDirectory(SRC_DIR); $loader->setCacheStorage(new Nette\Caching\Storages\FileStorage(__DIR__ . '/tmp')); $loader->register(); // CONNECTION & NDBT $connection = new \Nette\Database\Connection('mysql:host=127.0.0.1;dbname=mesour_editable', 'root', 'root'); $cacheMemoryStorage = new \Nette\Caching\Storages\MemoryStorage(); $structure = new \Nette\Database\Structure($connection, $cacheMemoryStorage); $conventions = new \Nette\Database\Conventions\DiscoveredConventions($structure); $context = new \Nette\Database\Context($connection, $structure, $conventions, $cacheMemoryStorage); // SELECTION $selection = $context->table('users'); $selection->select('users.*'); // SOURCE $source = new \Mesour\Sources\NetteDbTableSource('users', 'id', $selection, $context); $dataStructure = $source->getDataStructure(); $dataStructure->renameColumn('groups', 'group'); $dataStructure->renameColumn('user_addresses', 'addresses'); $dataStructure->renameColumn('wallets', 'wallet'); /** @var \Mesour\Sources\Structures\Columns\ManyToOneColumnStructure $groupColumn */ $groupColumn = $dataStructure->getColumn('group'); $groupColumn->setPattern('{name} ({members})'); /** @var \Mesour\Sources\Structures\Columns\OneToManyColumnStructure $addressColumn */ $addressColumn = $dataStructure->getColumn('addresses'); $addressColumn->setPattern('{street}, {zip} {city}, {country}'); /** @var \Mesour\Sources\Structures\Columns\ManyToManyColumnStructure $companiesColumn */ $companiesColumn = $dataStructure->getColumn('companies'); $companiesColumn->setPattern('{name}'); /** @var \Mesour\Sources\Structures\Columns\OneToOneColumnStructure $walletColumn */ $walletColumn = $dataStructure->getColumn('wallet');