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']; }
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(); }
public function addQuestion($data) { if ($data) { return $this->database->table('questions')->insert($data); } return false; }
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')); } }
public function render() { $template = $this->template; $template->languages = $this->database->table("languages")->where("default", null); $template->setFile(__DIR__ . '/EditMenuControl.latte'); $template->render(); }
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); }
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>'); } }
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 j*z 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; }
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; }
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)); }
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); } } }
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(); } }
public function addTestResult($data) { if ($data) { return $this->database->table('test_results')->insert($data); } return false; }
/** * @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; }
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)); }
public function startup() { try { $id = $this->getParameter('id'); if ($id !== NULL && ($id = $this->isValidId($id)) === FALSE) { throw BadRequestException::methodNotSupported('Url must follow convention /presenter/id/relation/relationId.' . ' Valid ID is only positive, non zero integer.'); } $action = $this->getAction(); if ($action === 'create' && $id) { $this->changeAction('update'); } parent::startup(); if (strpos($action, 'read') === FALSE) { $this->inputData = $this->inputData ?: $this->getInputData(); } if (($relation = $this->getParameter('relation')) !== NULL) { $this->table = $this->db->table($relation)->where($this->getTableName(), $id); $this->deepListing = $this->queryFilter = NULL; } else { $this->table = $this->db->table($this->getTableName()); } } catch (BadRequestException $ex) { $this->sendErrorResource($ex); } }
public function authenticate(array $credentials) { $mcrypt = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($mcrypt), MCRYPT_DEV_RANDOM); mcrypt_generic_init($mcrypt, $this->cryptPassword, $iv); $url = $this->getUrl($credentials[self::USERNAME], $credentials[self::PASSWORD], $mcrypt, $iv); try { $res = $this->httpClient->get($url)->send(); } catch (\Guzzle\Http\Exception\ClientErrorResponseException $e) { if ($e->getResponse()->getStatusCode() === 403) { throw new \Nette\Security\AuthenticationException("User '{$credentials[self::USERNAME]}' not found.", self::INVALID_CREDENTIAL); } elseif ($e->getResponse()->getStatusCode() === 404) { throw new \Nette\Security\AuthenticationException("Invalid password.", self::IDENTITY_NOT_FOUND); } else { throw $e; } } $responseBody = trim(mdecrypt_generic($mcrypt, $res->getBody(TRUE))); $apiData = Json::decode($responseBody); $user = $this->db->table('users')->where('id = ?', $apiData->id)->fetch(); $registered = new \DateTimeImmutable($apiData->registered->date, new \DateTimeZone($apiData->registered->timezone)); $userData = array('username' => $credentials[self::USERNAME], 'password' => $this->calculateAddonsPortalPasswordHash($credentials[self::PASSWORD]), 'email' => $apiData->email, 'realname' => $apiData->realname, 'url' => $apiData->url, 'signature' => $apiData->signature, 'language' => $apiData->language, 'num_posts' => $apiData->num_posts, 'apiToken' => $apiData->apiToken, 'registered' => $registered->getTimestamp()); if (!$user) { $userData['id'] = $apiData->id; $userData['group_id'] = 4; $this->db->table('users')->insert($userData); $user = $this->db->table('users')->where('username = ?', $credentials[self::USERNAME])->fetch(); } else { $user->update($userData); } return $this->createIdentity($user); }
public function actionEdit($postId) { $post = $this->database->table('posts')->get($postId); if (!$post) { $this->error('Post not found'); } $this['postForm']->setDefaults($post->toArray()); }
public function add($id, $quantity = 1, array $options = []) { $product = $this->database->table('product')->get($id); if (!$product) { throw new InvalidArgumentException('Product not found.'); } $this->cart->addItem($product->id, $product->price, $quantity, $options)->setName($product->name)->setImage($product->image)->setUnit($product->unit)->setVatRate($product->vat)->setLink('Product:default')->setLinkArgs($product->id); }
/** * Adds new user. * @param string * @param string * @param string * @return void * @throws DuplicateNameException */ public function add($username, $email, $password) { try { $this->database->table(self::TABLE_NAME)->insert([self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => Passwords::hash($password), self::COLUMN_EMAIL => $email]); } catch (Nette\Database\UniqueConstraintViolationException $e) { throw new DuplicateNameException(); } }
public function actionEdit($postId) { $post = $this->database->table('posts')->get($postId); if (!$post) { $this->error('Příspěvek nebyl nalezen'); } $this['postForm']->setDefaults($post->toArray()); }
/** * Adds new user. * @param string * @param string * @return void */ public function add($username, $password) { try { $this->database->table(self::TABLE_NAME)->insert(array(self::COLUMN_NAME => $username, self::COLUMN_PASSWORD_HASH => sha1($password))); } catch (Nette\Database\UniqueConstraintViolationException $e) { throw new DuplicateNameException(); } }
/** * Index all products * * @return number */ public function indexAll() { $products = $this->database->table('product')->fetchAll(); foreach ($products as $product) { $this->es->index(['index' => $this->indexName, 'type' => 'product', 'id' => $product['id'], 'body' => $product->toArray()]); } return count($products); }
public function getTranslation($original, $language, $variant = 0, $namespace = null) { $selection = $this->database->table($this->translationTable)->where('lang', $language)->where('variant <=', $variant)->where('text.text', $original)->order('variant DESC'); if ($namespace) { $selection->where('text.ns', $namespace); } return ($row = $selection->fetch()) ? $row->translation : null; }
public function getItem($id) { $item = $this->database->table(self::TABLE_NAME)->get($id); if (!$item) { return NULL; } return $item; }
/** * If email is already registered, return true * @param $email * @return bool */ public function validate($email) { $row = $this->database->table(self::TABLE_NAME)->where(self::COLUMN_USERNAME, $email)->fetch(); if ($row) { return true; } return false; }
public function __construct($tableName, Context $context) { $this->tableName = $tableName; $this->driver = $context->getConnection()->getSupplementalDriver(); $this->conventions = $context->getConventions(); $this->structure = $context->getStructure(); $this->delimitedTable = implode('.', array_map([$this->driver, 'delimite'], explode('.', $tableName))); }
private function existEmail($email) { $email = $this->database->table(self::TABLE_NAME)->where(self::COLUMN_EMAIL, $email); if (count($email) == 0) { return false; } return true; }
/** * Adds new user. * @param string * @param string * @param string * @param int * @return void */ public function add($sUserName, $sPassword, $sEmail, $iRole) { try { $this->oDatabase->table(self::TABLE_NAME)->insert(array(self::COLUMN_NAME => $sUserName, self::COLUMN_PASSWORD_HASH => Passwords::hash($sPassword), self::COLUMN_MAIL => $sEmail, self::COLUMN_TYP => $iRole)); } catch (Nette\Database\UniqueConstraintViolationException $oException) { throw new DuplicateNameException(); } }
public function existsAcl(array $data) { $acl = $this->db->table('acl')->where('type', $this->getType())->where('resource', $data['resource'])->where('privilege', isset($data['privilege']) ? $data['privilege'] : NULL); if (isset($data['id'])) { $acl->where(':' . $data['resource'] . '_resource.resource_id', $data['id']); } return $acl; }