本文整理汇总了PHP中Nette\Database\Context类的典型用法代码示例。如果您正苦于以下问题:PHP Context类的具体用法?PHP Context怎么用?PHP Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: invoke
public function invoke(Container $container, Context $db)
{
$driver = new PostgreSqlNetteDbDriver($db, 'migrations');
$printer = new Console();
$runner = new Runner($driver, $printer);
if ($this->in->getOption('init')) {
ob_start();
$runner->run($runner::MODE_INIT);
$sql = ob_get_clean();
$db->query($sql);
$this->out->writeln('<info>Migrations table created</info>');
return;
}
$g = new Group();
$g->directory = __DIR__ . '/../../../migrations/struct';
$g->dependencies = [];
$g->enabled = TRUE;
$g->name = 'struct';
$runner->addGroup($g);
$runner->addExtensionHandler('sql', new Extensions\NetteDbSql($db));
$runner->addExtensionHandler('php', new PhpClass(['db' => $db], $container));
try {
$runner->run();
return;
} catch (\PDOException $e) {
if ($e->getCode() !== '42S02') {
throw $e;
}
// lets hope locale is english
if (!preg_match("~Table '.*?\\.migrations' doesn't exist~", $e->getMessage())) {
throw $e;
}
$this->out->writeln('<error>Migrations table does not exist, init migrations first</error>');
}
}
示例2: renderDefault
public function renderDefault()
{
$id = '4';
$this->template->program = $this->database->table('posts')->order('created_at DESC')->where('id = ?', $id);
$title = $this->database->table('posts')->get($id);
$this->template->titulek = $title['title'];
}
示例3: createComponentGrid
protected function createComponentGrid($name)
{
$grid = new Grid($this, $name);
$grid->model = $this->database->table('user');
$grid->addColumnText('firstname', 'Firstname')->setFilterText()->setSuggestion();
$grid->addColumnText('surname', 'Surname')->setSortable()->setFilterText()->setSuggestion();
$grid->addColumnText('gender', 'Gender')->setSortable()->cellPrototype->class[] = 'center';
$grid->addColumnDate('birthday', 'Birthday', \Grido\Components\Columns\Date::FORMAT_TEXT)->setSortable()->setFilterDate()->setCondition($grid->birthdayFilterCondition);
$grid->getColumn('birthday')->cellPrototype->class[] = 'center';
$templatePath = "{$this->context->parameters['appDir']}/templates/{$this->name}";
$renderer = function ($row) {
return $row->country->title;
};
$grid->addColumnText('country', 'Country')->setSortable()->setColumn('country.title')->setCustomRender("{$templatePath}/grid.country.latte")->setCustomRenderExport($renderer)->setFilterText()->setSuggestion($renderer);
$grid->addColumnText('card', 'Card')->setSortable()->setColumn('cctype')->setReplacement(array('MasterCard' => Html::el('b')->setText('MasterCard')))->cellPrototype->class[] = 'center';
$grid->addColumnEmail('emailaddress', 'Email')->setSortable()->setFilterText();
$grid->getColumn('emailaddress')->cellPrototype->class[] = 'center';
$grid->addColumnText('centimeters', 'Height')->setSortable()->setFilterNumber();
$grid->getColumn('centimeters')->cellPrototype->class[] = 'center';
$grid->addFilterSelect('gender', 'Gender', array('' => '', 'female' => 'female', 'male' => 'male'));
$grid->addFilterSelect('card', 'Card', array('' => '', 'MasterCard' => 'MasterCard', 'Visa' => 'Visa'))->setColumn('cctype');
$grid->addFilterCheck('preferred', 'Only preferred girls :)')->setCondition(array(TRUE => array(array('gender', 'AND', 'centimeters'), array('= ?', '>= ?'), array('female', 170))));
$grid->addActionHref('edit', 'Edit')->setIcon('pencil');
$grid->addActionHref('delete', 'Delete')->setIcon('trash')->setConfirm(function ($item) {
return "Are you sure you want to delete {$item->firstname} {$item->surname}?";
});
$operation = array('print' => 'Print', 'delete' => 'Delete');
$grid->setOperation($operation, $this->handleOperations)->setConfirm('delete', 'Are you sure you want to delete %i items?');
$grid->filterRenderType = $this->filterRenderType;
$grid->setExport();
}
示例4: addQuestion
public function addQuestion($data)
{
if ($data) {
return $this->database->table('questions')->insert($data);
}
return false;
}
示例5: startup
protected function startup()
{
parent::startup();
// Login check
if ($this->getName() != 'Admin:Sign') {
$role = $this->user->getRoles();
$roleCheck = $this->database->table("users_roles")->get($role[0]);
if ($roleCheck->admin_access == 0) {
$this->flashMessage($this->translator->translate('messages.sign.invalidLogin'), "error");
$this->redirect(':Admin:Sign:in');
}
if ($this->user->isLoggedIn()) {
} else {
if ($this->user->logoutReason === Nette\Security\IUserStorage::INACTIVITY) {
$this->flashMessage($this->translator->translate('messages.sign.youWereLoggedIn'), "note");
}
$this->redirect('Sign:in', array('backlink' => $this->storeRequest()));
}
}
if ($this->user->isLoggedIn()) {
$this->template->isLoggedIn = TRUE;
$this->template->member = $this->database->table("users")->get($this->user->getId());
}
// Set values from db
$this->template->settings = $this->database->table("settings")->fetchPairs("setkey", "setvalue");
$this->template->appDir = APP_DIR;
$this->template->signed = TRUE;
$this->template->langSelected = $this->translator->getLocale();
// Set language from cookie
if ($this->context->httpRequest->getCookie('language_admin') == '') {
$this->translator->setLocale($this->translator->getDefaultLocale());
} else {
$this->translator->setLocale($this->context->httpRequest->getCookie('language_admin'));
}
}
示例6: render
public function render()
{
$template = $this->template;
$template->languages = $this->database->table("languages")->where("default", null);
$template->setFile(__DIR__ . '/EditMenuControl.latte');
$template->render();
}
示例7: createComponentCarouselGrid
public function createComponentCarouselGrid($name)
{
$grid = new \Ublaboo\DataGrid\DataGrid($this, $name);
$test = $this->database->table("carousel")->order("sorted");
$grid->setDataSource($test);
$grid->setSortable(true);
$grid->addGroupAction('Smazat')->onSelect[] = [$this, 'handleDelete'];
$grid->addColumnText('title', 'dictionary.main.Title')->setRenderer(function ($item) {
if ($item->title == '') {
$title = \Nette\Utils\Html::el('a')->href('/admin/appearance/carousel-detail/' . $item->id)->setText('- nemá název - ');
} else {
$title = \Nette\Utils\Html::el('a')->href('/admin/appearance/carousel-detail/' . $item->id)->setText($item->title);
}
return $title;
});
$grid->addColumnText('test', 'dictionary.main.Image')->setRenderer(function ($item) {
if ($item->image == '') {
$fileImage = '';
} else {
$fileImage = \Nette\Utils\Html::el('img', array('style' => 'max-height: 130px;'))->src('/images/carousel/' . $item->image);
}
return $fileImage;
});
$grid->setTranslator($this->presenter->translator);
}
示例8: renderDefault
public function renderDefault()
{
// 1. Vlozeni noveho zaznamu do tabulky se zavody
// 2. Vyber zavodu (identifikatoru), vetsinou toho, ktery byl vytvoren v predchozim bode
$id_event = "VCHOD2015";
// 3. Kontrola identifikatoru zavodu - nesmi byt pouzit v tabulce casu
$data = $this->database->query('select id from sm_time where id_event = ?', $id_event);
if ($data->getRowCount() > 0) {
// Chyba! Vyzadovat novou volbu zavodu
// Pozor! VCHOD2015 jiz v tabulce casu je!
}
// 4. Zadani textoveho souboru s vysledky s predepsanym DR
// $input_file = "/home/vencs88/php/import_time/data/cp_praha2015.txt";
// $input_file = "/home/vencs88/php/import_time/data/vysledky_blbec.txt";
$input_file = "/home/vencs88/php/import_time/data/mem2015.txt";
// 5. Vizualni kontrola chyb po nacteni vysledku do pomocne tabulky
$this->template->status = $this->importTimeManager->getImportData($input_file, $id_event);
$this->template->data = $this->database->table('sm_import');
// 6. Nejsou-li chyby, umoznit import vysledku do tabulky casu
// INSERT INTO sm_time
// (
// id_stroke,
// id_swimmer,
// time,
// rank,
// point
// )
// SELECT * FROM sm_import;
//
// // Zvazit vymaz pomocne tabulky
// DELETE FROM sm_import;
}
示例9: parseSnippets
public function parseSnippets($s)
{
preg_match_all("/\\[snippet\\=\"([0-9]{1,10})\"\\]/s", $s, $valsimp, PREG_SET_ORDER);
if (count($valsimp) > 0) {
for ($n = 0; $n < count($valsimp); $n++) {
$snippet = $this->database->table("snippets")->get($valsimp[$n][1]);
if ($snippet) {
if ($this->presenter->translator->getLocale() == $this->presenter->translator->getDefaultLocale()) {
$results = $snippet->content;
} else {
$results = $snippet->{'content_' . $this->presenter->translator->getLocale()};
}
} else {
$results = null;
}
$s = str_replace($valsimp[$n][0], "{$results}", $s);
}
}
preg_match_all("/\\[file\\=([0-9]{1,10})\\]/s", $s, $valsimp, PREG_SET_ORDER);
if (count($valsimp) > 0) {
for ($n = 0; $n < count($valsimp); $n++) {
$snippet = $this->database->table("media")->get($valsimp[$n][1]);
if ($snippet) {
$results = '/media/' . $snippet->pages_id . '/' . $snippet->name;
} else {
$results = null;
}
$s = str_replace($valsimp[$n][0], "{$results}", $s);
}
}
return $s;
}
示例10: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->database->query($this->getFile(self::FILE_EMAILS_TABLE));
$this->database->query($this->getFile(self::FILE_GROUPS_TABLE));
$this->database->query($this->getFile(self::FILE_SENDER_LIST_TABLE));
$this->database->query($this->getFile(self::FILE_GROUP_EMAIL_TABLE));
}
示例11: updateAddon
private function updateAddon(ActiveRow $addon)
{
$this->writeln('Updating: ' . $addon->name);
$github = $this->normalizeGithubUrl($addon->repository);
if ($github) {
$guzzle = new \Guzzle\Http\Client();
try {
$guzzle->get($github)->send();
$this->db->table('addons_resources')->insert(array('addonId' => $addon->id, 'type' => 'github', 'resource' => $github));
} catch (\Guzzle\Http\Exception\RequestException $e) {
$this->writeln((string) $e);
}
}
if ($addon->type === 'composer') {
$version = $addon->related('versions')->order('id', 'DESC')->fetch();
$composerData = Json::decode($version->composerJson);
$packagist = $this->generatePackagistUrl($composerData->name);
$guzzle = new \Guzzle\Http\Client();
try {
$guzzle->get($packagist . '.json')->send();
$this->db->table('addons_resources')->insert(array('addonId' => $addon->id, 'type' => 'packagist', 'resource' => $packagist));
} catch (\Guzzle\Http\Exception\RequestException $e) {
$this->writeln((string) $e);
}
}
if ($addon->demo) {
$guzzle = new \Guzzle\Http\Client();
try {
$guzzle->get($addon->demo)->send();
$this->db->table('addons_resources')->insert(array('addonId' => $addon->id, 'type' => 'demo', 'resource' => $addon->demo));
} catch (\Guzzle\Http\Exception\RequestException $e) {
$this->writeln((string) $e);
}
}
}
示例12: render
public function render()
{
$template = $this->template;
$template->settings = $this->presenter->template->settings;
if ($this->presenter->template->settings['store:enabled']) {
$template->orders = $this->database->table("orders")->where("orders_states_id NOT", null)->count();
$template->carts = $this->database->table("orders")->where("orders_states_id", null)->count();
$stats = new \App\Model\Store\Statistics($this->database);
$statsParam = $this->presenter->getParameter('stats');
if ($statsParam == 'td') {
$arrTurnover = $stats->getData('d', 'price');
$template->statsLabel = 'Obraty - denní';
} elseif ($statsParam == 'am') {
$arrTurnover = $stats->getData('m', 'amount');
$this->presenter->template->statsLabel = 'Počty objednávek - měsíční';
} elseif ($statsParam == 'ad') {
$arrTurnover = $stats->getData('d', 'amount');
$template->statsLabel = 'Počty objednávek - denní';
} else {
$arrTurnover = $stats->getData('m', 'price');
$template->statsLabel = 'Obraty - denní';
}
$template->turnoverDays = $stats->convertKeysToString($arrTurnover);
if (is_array($arrTurnover)) {
$template->turnoverValues = implode(",", $arrTurnover);
}
$template->setFile(__DIR__ . '/DashboardControl.latte');
$template->render();
}
}
示例13: addTestResult
public function addTestResult($data)
{
if ($data) {
return $this->database->table('test_results')->insert($data);
}
return false;
}
示例14: create
/**
* @return Form
*/
public function create($role)
{
$rights = $this->database->table('rights')->fetchPairs('id', 'name');
$form = new Form();
$form->addHidden('id');
$form->addText('username', 'uživatelské jméno: ')->addRule(Form::FILLED, 'Zadejte prosím jméno.');
$form->addText('email', 'email: ')->addRule(Form::FILLED, 'Zadejte prosím email.')->addRule(Form::EMAIL, 'Email by měl mít platný formát');
if (in_array("admin", $role)) {
// editace prav jen adminem
$form->addSelect('rights_id', 'level práv: ', $rights);
}
$form->addSubmit('submit', 'uložit');
$form->addProtection('Vypršel časový limit, odešlete formulář znovu');
//bootstrap vzhled
$renderer = $form->getRenderer();
$renderer->wrappers['controls']['container'] = NULL;
$renderer->wrappers['pair']['container'] = 'div class=form-group';
$renderer->wrappers['pair']['.error'] = 'has-error';
$renderer->wrappers['control']['container'] = '';
$renderer->wrappers['label']['container'] = 'div class="control-label col-sm-5"';
$renderer->wrappers['control']['description'] = 'span class=help-block';
$renderer->wrappers['control']['errorcontainer'] = 'span class=help-block';
$form->getElementPrototype()->class('form-horizontal col-sm-12');
return $form;
}
示例15: editEventFormSucceeded
function editEventFormSucceeded(\Nette\Forms\BootstrapUIForm $form)
{
$values = $form->getHttpData($form::DATA_TEXT);
$date_start = \DateTime::createFromFormat('j. n. Y', $form->values->date_event);
$date1 = $date_start->format('Y-m-d');
$date_start = \DateTime::createFromFormat('j. n. Y', $form->values->date_event_end);
$date2 = $date_start->format('Y-m-d');
if ($form->values->date_event == '') {
$dateEvent = null;
} else {
if ($form->values->allday) {
$dateEvent = $date1 . ' 00:00:00';
} else {
$dateEvent = $date1 . ' ' . $values["hour_event"] . ':' . $values["minute_event"];
}
}
if ($form->values->date_event_end == '') {
$dateEventEnd = null;
} else {
if ($form->values->allday) {
$dateEventEnd = $date2 . ' 23:55:00';
} else {
$dateEventEnd = $date2 . ' ' . $values["hour_event_end"] . ':' . $values["minute_event_end"];
}
}
$arr = array("date_event" => $dateEvent, "date_event_end" => $dateEventEnd, "all_day" => $form->values->allday, "price" => $form->values->price, "capacity" => $form->values->capacity, "capacity_start" => $form->values->capacity_start, "time_range" => $form->values->time_range);
if ($form->values->contact) {
$arr["contacts_id"] = $form->values->contact;
}
$this->database->table("events")->get($form->values->event_id)->update($arr);
$this->presenter->redirect(":Admin:Events:detail", array("id" => $form->values->id));
}