/** * @return Form */ public function create($kat = null, $page = null, $id_user = null) { // nastaveni paginatoru $paginator = new Nette\Utils\Paginator(); $paginator->setItemsPerPage(6); // def počtu položek na stránce $paginator->setPage($page); // def stranky // selekce upozorneni $alerts = $this->database->findAll('alert')->where('id_user', $id_user); if ($kat == 'read') { // prectene $alerts = $alerts->where('visited', 1); } else { // neprectene $alerts = $alerts->where('visited', 0); } $alerts = $alerts->order('added DESC')->order('id DESC'); // prideleni produktu na stranku $paginator->setItemCount($alerts->count('*')); $this->alerts = $alerts->limit($paginator->getLength(), $paginator->getOffset()); $this->kat = $kat; // form $form = new Form(); $form->getElementPrototype()->class('ajax form'); foreach ($this->alerts as $alert) { $form->addCheckbox($alert->id); } $form->addSubmit('btndel', 'Smazat upozornění')->setAttribute('class', 'btn btn-primary'); $form->addSubmit('btnvis', 'Označit jako přečtené')->setAttribute('class', 'btn btn-default'); $form->onSuccess[] = array($this, 'formSucceeded'); $form->onError[] = array($this, 'formNotSucceeded'); return $form; }
public function add($values) { $values['added'] = $this->now; // potreba zjistit na kolik dni ma byt aukce spustena $duration = $this->database->findById('duration_auction', $values['id_duration_auction']); $values['expire'] = date('Y-m-d H', strtotime($this->now . ' + ' . $duration->duration_days . ' day')); return $this->database->findAll('product')->insert($values); }
public function renderDefault($idkat = 0, $page = 1) { $this->template->paginator = new Nette\Utils\Paginator(); $this->template->paginator->setItemsPerPage(9); // počet položek na stránce $this->template->paginator->setPage($page); if ($idkat == 0) { $this->template->paginator->setItemCount($this->database->findAll('inzeraty')->where('NOW() <= expire')->count("*")); $this->template->inzeraty = $this->database->findAll('inzeraty')->where('NOW() <= expire')->order('added DESC')->limit($this->template->paginator->getLength(), $this->template->paginator->getOffset()); } elseif ($idkat == 10) { $this->template->paginator->setItemCount($this->database->findAll('inzeraty')->where('NOW() <= expire AND id_user = ?', $this->user->id)->count("*")); $this->template->inzeraty = $this->database->findAll('inzeraty')->where('NOW() <= expire AND id_user = ?', $this->user->id)->order('added DESC')->limit($this->template->paginator->getLength(), $this->template->paginator->getOffset()); } else { $this->template->paginator->setItemCount($this->database->findAll('inzeraty')->where('NOW() <= expire AND id_kategorie = ?', $idkat)->count("*")); $this->template->inzeraty = $this->database->findAll('inzeraty')->where('NOW() <= expire AND id_kategorie = ?', $idkat)->order('added DESC')->limit($this->template->paginator->getLength(), $this->template->paginator->getOffset()); } $this->template->kategorie = $this->database->findAll('kategorie'); $this->template->vybranakat = $this->database->findById('kategorie', $idkat); $this->template->dbUser = $this->database->findById('user', 1); // vytvorim objekt pomoci me modelove tridy v app/model $mujZooObjekt = new Model\TestModelClass(); // do promenne pro template nactu pole zvirat $this->template->zviratka = $mujZooObjekt->vratPole(); if ($this->template->vybranakat == null and $idkat == 10) { $this->template->vybranakat = (object) array('nazev' => 'Moje inzeráty', 'id' => $idkat); } $this->template->pictures = $this->database->findAll('image'); }
public function renderDefault() { // posledni 4 nemovitosti $this->template->nemovitosti = $this->database->findAll('nemovitost')->where('is_public', 1)->order('public_date DESC')->order('id DESC')->limit(4); $contact = $this->database->findById('contact', 1); if (!$contact) { $this->template->about_us = null; } else { $this->template->about_us = $contact->about_us; } }
public function renderVypis($id = null) { // nejdriv si overim ze nemovitost opravdu existuje $this->template->nemovitost = $this->database->findById('nemovitost', $id); if (!$this->template->nemovitost) { $this->flashMessage('Tato nemovitost neexistuje. Je možné, že ji někdo smazal.'); $this->redirect('Homepage:default'); } // pokud existuje vyhleam prilozene soubory a zjistim nastaveni $this->template->files = $this->database->findAll('file')->where('id_property', $id); $this->drazba->zahrnPocatecniNastaveni($id); $this->template->status = $this->drazba->vratStatus(); }
/** * @return Form */ public function create() { // nahrani kategorii $this->categories = $this->database->findAll('category'); // form $form = new Form(); $form->getElementPrototype()->class('ajax form'); foreach ($this->categories as $c) { $form->addCheckbox($c->id); } $form->addSubmit('send', 'Smazat vybrané')->setAttribute('class', 'btn btn-primary'); $form->onSuccess[] = array($this, 'formSucceeded'); $form->onError[] = array($this, 'formNotSucceeded'); return $form; }
public function renderDetailNemovitosti($id = null) { $this->template->nemovitost = $this->database->findById('nemovitost', $id); if (!$this->template->nemovitost) { $this->flashMessage('Tato nemovitost neexistuje. Je možné, že ji někdo smazal.'); $this->redirect('Homepage:default'); } // vyberu fotky k dane nemovitosti $this->template->fotky = $this->database->findall('photo')->where('id_property', $id)->order("order DESC"); // jako hlavni fotku vemu prvni z vyberu $this->template->hlavni_fotka = $this->template->fotky->fetch(); // vyberu soubory k dane nemovitosti $this->template->files = $this->database->findall('file')->where('id_property', $id); // resim aukci $prihozy = $this->database->findAll('drazba')->where('id_nemovitost', $id); $this->template->drazba = $this->drazba->vyhodnotDrazbu($id, $prihozy); $this->template->status = $this->drazba->vratStatus(); }
/** * @return Form */ public function create($id_product = null) { // nacteni id nemovitosti $this->id_product = $id_product; // form $form = new Form(); $form->getElementPrototype()->class('ajax form'); // uchovani kvuli pozdejsimu presmerovani $form->addText('id_product')->setValue($this->id_product); $this->photos = $this->database->findAll('image')->where('id_product', $this->id_product); foreach ($this->photos as $photo) { $form->addCheckbox($photo->id); } $form->addSubmit('send', 'Odeslat formulář')->setAttribute('class', 'btn btn-primary'); $form->onSuccess[] = array($this, 'formSucceeded'); $form->onError[] = array($this, 'formNotSucceeded'); return $form; }
public function bidClasicAuction($product, $id_user, $deposit) { // aukce "kup hned" if ($this->now > $product->expire) { // dosel cas pro aukci -> chyba $this->error = 'Je nám líto, ale čas určený pro aukci vypršel.'; } elseif ($id_user == $product->id_user) { // nelze koupit svuj produkt -> chyba $this->error = 'Je nám líto, ale produkt nelze koupit.'; } else { // uprava prihozu $values['id_product'] = $product->id; $values['id_user'] = $id_user; $values['added'] = $this->now; $values['deposit'] = $deposit; $this->database->findAll('bid')->insert($values); } return $this->error; }
public function deleteAllProductPhotos($id_product) { $photos = $this->database->findAll('image')->where('id_product', $id_product); foreach ($photos as $p) { unlink($this->root_img_dir . 'products/' . $p->id_product . '_' . $p->id . '_' . $p->name . '.' . $p->extension); // smazu ve slozce $p->delete(); // smazu v db } }
public function beforeRender() { /* --- --- promenne --- --- */ $this->template->systemName = $this->database->findAll('setings')->where('id_parameter', 1)->fetch(); $this->template->categories = $this->database->findAll('category'); $this->template->alerts = $this->database->findAll('alert')->where('id_user', $this->user->id)->where('visited', 0)->order('added DESC')->order('id DESC'); $this->template->id_category = (int) $this->getParameter('kat'); /* --- --- vlastni helpery --- --- */ // filtr na tvorbu "hezkeho" datumu $this->template->addFilter('mydate', function ($date) { if ($date >= date('Y-m-d', strtotime('today'))) { return 'Dnes'; } elseif ($date >= date('Y-m-d', strtotime('yesterday'))) { return 'Včera'; } else { $months = array(1 => 'leden', 'únor', 'březen', 'duben', 'květen', 'červen', 'červenec', 'srpen', 'září', 'říjen', 'listopad', 'prosinec'); return date('j', strtotime($date)) . '. ' . $months[date('n', strtotime($date))]; } }); }
/** * @return Form */ public function create($id_product = null) { // nacteni id nemovitosti $this->id_product = $id_product; // form $form = new Form(); $form->getElementPrototype()->class('ajax form'); // uchovani kvuli pozdejsimu presmerovani $form->addText('id_product')->setValue($this->id_product); $this->photos = $this->database->findAll('image')->where('id_product', $this->id_product); $i = 0; $first_checkbox = null; $is_set_any_main_photo = false; // pridam tolik checkboxu kolik je fotek foreach ($this->photos as $photo) { if ($i == 0) { // ulozim si id prvniho checkboxu $first_checkbox = $photo->id; } ++$i; if ($photo->order == 1) { // pokud mam v db nastavenou hlavni fotku $form->addCheckbox($photo->id)->setValue(true); // nastavim checkbox zaskrtnuty $is_set_any_main_photo = true; // a dam si vedet ze nastaveno j*z mam } else { $form->addCheckbox($photo->id); } } // pokud uzivatel nenastavil doposud hlavni fotku if ($first_checkbox != null && $is_set_any_main_photo == false) { $form["{$first_checkbox}"]->setValue(true); } // defaultne je brana prvni jako hlavni $form->addSubmit('send', 'Odeslat formulář')->setAttribute('class', 'btn btn-primary'); $form->onSuccess[] = array($this, 'formSucceeded'); $form->onError[] = array($this, 'formNotSucceeded'); return $form; }
public function endOfAuction($product) { // priprava na posilani emailu $email_manager = new Model\Email($this->database); // celkova cena $cost = $product->cost + $product->related('bid.id_product')->sum('deposit'); /* --- vyrozumneni pro vyherce aukce --- */ $winners_bid = $this->database->findAll('bid')->where('id_product', $product->id)->order('id DESC')->fetch(); // priprava alertu pro viteze aukce $val['id_user'] = $winners_bid->id_user; $val['id_type_alert'] = 1; $val['added'] = $this->now; $val['visited'] = 0; $val['body'] = 'Vyhráli jste aukci produktu ' . $product->name . ' (id ' . $product->id . '). Cena produktu činí ' . number_format($cost) . ' Kč. Pro další informace k předání produktu kontaktujte ' . $product->user->name . ' (tel: ' . $product->user->phone . ', email: ' . $product->user->email . ').'; // vlozeni alertu pro viteze do db $row = $this->database->insert('alert', $val); // a poslani emailu vitezi aukce $email_manager->sendEmail($winners_bid->user->email, 'end_auction_winner', $product, $winners_bid, $cost, $row->type_alert->name); /* --- vyrozumneni pro zbyle ucastniky aukce --- */ $bids = $this->database->findAll('bid')->where('id_product', $product->id)->group('id_user'); foreach ($bids as $bid) { if ($bid->id_user != $winners_bid->id_user) { // vitez aukce uz informovan byl // uprava alertu $val['id_user'] = $bid->id_user; $val['body'] = 'Aukci produktu ' . $product->name . ' (id ' . $product->id . '), do které jste zasáhli, vyhrál jiný účastník.'; // vlozeni do db $row = $this->database->insert('alert', $val); // a poslani emailu porazenym $email_manager->sendEmail($bid->user->email, 'end_auction_others', $product, $bid, $cost, $row->type_alert->name); } } /* --- vyrozumneni pro zadavatele aukce --- */ $val['id_user'] = $product->id_user; $val['body'] = 'Aukce produktu ' . $product->name . ' (id ' . $product->id . ') je u konce. Výherce aukce je ' . $winners_bid->user->name . ' (tel: ' . $winners_bid->user->phone . ', email: ' . $winners_bid->user->email . '), který produkt koupil za ' . number_format($cost) . ' Kč.'; // vlozeni do db $row = $this->database->insert('alert', $val); // a poslani emailu zadavateli $email_manager->sendEmail($product->user->email, 'end_auction_seller', $product, $winners_bid, $cost, $row->type_alert->name); }
public function prvniPrihozFormSucceeded($button) { $values = $button->getForm()->getValues(true); $values['datum_vkladu'] = date('Y-m-d H:i:s'); $values['vkladana_castka'] = 0; // prvni prihoz je nulovy, pouze se potvrdi zadana castka if ($values['pocet'] == $this->database->findAll('drazba')->where('id_nemovitost', $values['id_nemovitost'])->count('*')) { // pokud se shoduji pocty prihozu pri nacteni a tesne pred prihozenim, pak vse ok unset($values['pocet']); $this->database->insert('drazba', $values); $this->flashMessage('Podal(a) jste první nabídku.'); $this->redirect('Nemovitosti:detailNemovitosti', $values['id_nemovitost']); } else { $this->flashMessage('Znovu zvažte přihození, někdo před Vámi ještě navýšil cenu.'); $this->redirect('Aukce:prihodit', $values['id_nemovitost']); } }
public function setMainPhotoFormSucceeded($button) { $values = $button->getForm()->getValues(true); // priprava pomocnyh prom $id = (int) $this->getParameter('id'); $photos = $this->database->findAll('photo')->where('id_property', $id); $selected_main_photo = null; $prev_main_photo = null; // projdu vsechny fotky k dane udalosti foreach ($photos as $photo) { // najdu predchozi hlavni a nastavim ji na 0 if ($photo->order == 1) { $prev_main_photo = $photo->id; } // vyberu kterou vybral uzivatel a nastavim ji jako hlavni (1) if ($values["{$photo->id}"] == true) { $selected_main_photo = $photo->id; } } // uprava stare hlavni fotky if ($prev_main_photo != null) { // pokud vubec mame nejakou vybranou starou fotku $photo = $this->database->findById('photo', $prev_main_photo); if ($photo && $photo->id_property == $id) { // pokud ji tedy mam v db // tak ji odoznacime jako hlavni fotku $upArr["order"] = 0; $photo->update($upArr); } } // uprava nove hlavni fotky if ($selected_main_photo != null) { // pokud vubec mame nejakou vybranou novou fotku $photo = $this->database->findById('photo', $selected_main_photo); if ($photo && $photo->id_property == $id) { // pokud ji tedy mam v db // tak ji oznacime jako hlavni fotku $upArr["order"] = 1; $photo->update($upArr); } } // informace pro uzivatele + presmerovani $this->flashMessage('Hlavni fotografie byla upravena.'); $this->redirect('Nemovitosti:detailNemovitosti', $id); }
public function renderRozsireneVyhledavani($id = null, $q = null) { $this->template->id = $id; $min = 0; $max = 0; $t1 = $t2 = $t3 = $t4 = 1; $this->template->n_nemovitosti = $this->template->p_nemovitosti = $this->template->i_nemovitosti = $this->template->a_nemovitosti = array(); $this->template->is_q = false; // aby nemizel vyhledavany text ze search baru $form = $this['searchForm']; $form['search']->defaultValue = $q; // vycteni informaci z id $info = explode("-", $id); $id = intval($info[0]); // ziskam id if (isset($info[1])) { $min = intval($info[1]); } // ziskam min if (isset($info[2])) { $max = intval($info[2]); } // ziskam max if (isset($info[3])) { $t1 = intval($info[3]); } // vyhledavam v bytech if (isset($info[4])) { $t2 = intval($info[4]); } // vyhledavam v domech if (isset($info[5])) { $t3 = intval($info[5]); } // vyhledavam v pozemcich if (isset($info[6])) { $t4 = intval($info[6]); } // vyhledavam v ostatnich $form['t1']->defaultValue = $t1; $form['t2']->defaultValue = $t2; $form['t3']->defaultValue = $t3; $form['t4']->defaultValue = $t4; // pokud uzivatel zadal kladne cislo tak to opet nahraji do formu if ($min > 0) { $form['min']->defaultValue = $min; } if ($max > 0) { $form['max']->defaultValue = $max; } if ($q != null || $q != "" || $min > 0 || $max > 0) { // obsazeno v nazvech $this->template->n_nemovitosti = $this->database->findAll('nemovitost')->where('nazev LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); if ($q != null || $q != "") { // hledany retezec je zadan $this->template->is_q = true; switch ($id) { case 1: // vyhledavani v popisu $this->template->p_nemovitosti = $this->database->findAll('nemovitost')->where('popis LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $form['s1']->defaultValue = 1; break; case 2: // hledano v adrese $this->template->a_nemovitosti = $this->database->findAll('nemovitost')->where('adresa LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $form['s2']->defaultValue = 1; break; case 3: // hledano v idn $this->template->i_nemovitosti = $this->database->findAll('nemovitost')->where('idn LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $form['s3']->defaultValue = 1; break; case 12: // hledano v popisu a adrese $this->template->p_nemovitosti = $this->database->findAll('nemovitost')->where('popis LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $this->template->a_nemovitosti = $this->database->findAll('nemovitost')->where('adresa LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $form['s1']->defaultValue = 1; $form['s2']->defaultValue = 1; break; case 13: // hledano v popisu a idn $this->template->p_nemovitosti = $this->database->findAll('nemovitost')->where('popis LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $this->template->i_nemovitosti = $this->database->findAll('nemovitost')->where('idn LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $form['s1']->defaultValue = 1; $form['s3']->defaultValue = 1; break; case 23: // hledano v adrese a idn $this->template->a_nemovitosti = $this->database->findAll('nemovitost')->where('adresa LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $this->template->i_nemovitosti = $this->database->findAll('nemovitost')->where('idn LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $form['s2']->defaultValue = 1; $form['s3']->defaultValue = 1; break; case 123: // hledano v popisu, adrese i idn $this->template->p_nemovitosti = $this->database->findAll('nemovitost')->where('popis LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $this->template->a_nemovitosti = $this->database->findAll('nemovitost')->where('adresa LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $this->template->i_nemovitosti = $this->database->findAll('nemovitost')->where('idn LIKE ?', '%' . $q . '%')->where('is_public', 1)->order('public_date DESC')->order('id DESC'); $form['s1']->defaultValue = 1; $form['s2']->defaultValue = 1; $form['s3']->defaultValue = 1; break; } } if ($min > 0 && $max > 0) { // jestli uzivatel vyhledava i min a max $this->template->n_nemovitosti = $this->template->n_nemovitosti->where('pocatecni_cena >= ?', $min)->where('pocatecni_cena <= ?', $max); if (!is_array($this->template->p_nemovitosti)) { $this->template->p_nemovitosti = $this->template->p_nemovitosti->where('pocatecni_cena >= ?', $min)->where('pocatecni_cena <= ?', $max); } if (!is_array($this->template->a_nemovitosti)) { $this->template->a_nemovitosti = $this->template->a_nemovitosti->where('pocatecni_cena >= ?', $min)->where('pocatecni_cena <= ?', $max); } if (!is_array($this->template->i_nemovitosti)) { $this->template->i_nemovitosti = $this->template->i_nemovitosti->where('pocatecni_cena >= ?', $min)->where('pocatecni_cena <= ?', $max); } } elseif ($min > 0) { // jestli uzivatel vyhledava jen dle min $this->template->n_nemovitosti = $this->template->n_nemovitosti->where('pocatecni_cena >= ?', $min); if (!is_array($this->template->p_nemovitosti)) { $this->template->p_nemovitosti = $this->template->p_nemovitosti->where('pocatecni_cena >= ?', $min); } if (!is_array($this->template->a_nemovitosti)) { $this->template->a_nemovitosti = $this->template->a_nemovitosti->where('pocatecni_cena >= ?', $min); } if (!is_array($this->template->i_nemovitosti)) { $this->template->i_nemovitosti = $this->template->i_nemovitosti->where('pocatecni_cena >= ?', $min); } } elseif ($max > 0) { // jestli uzivatel vyhledava jen v max $this->template->n_nemovitosti = $this->template->n_nemovitosti->where('pocatecni_cena <= ?', $max); if (!is_array($this->template->p_nemovitosti)) { $this->template->p_nemovitosti = $this->template->p_nemovitosti->where('pocatecni_cena <= ?', $max); } if (!is_array($this->template->a_nemovitosti)) { $this->template->a_nemovitosti = $this->template->a_nemovitosti->where('pocatecni_cena <= ?', $max); } if (!is_array($this->template->i_nemovitosti)) { $this->template->i_nemovitosti = $this->template->i_nemovitosti->where('pocatecni_cena <= ?', $max); } } // nette sql where id_typ = $arr[0] OR id_typ = $arr[1] OR ... $where = ""; $whereArr = array(); if ($t1 == 1) { $where = $where . "id_typ = ?"; $whereArr[0] = 1; } if ($t2 == 1) { if ($t1 == 1) { $where = $where . " OR "; } $where = $where . "id_typ = ?"; $i = count($whereArr); $whereArr[$i] = 2; } if ($t3 == 1) { if ($t2 == 1) { $where = $where . " OR "; } elseif ($t1 == 1) { $where = $where . " OR "; } $where = $where . "id_typ = ?"; $i = count($whereArr); $whereArr[$i] = 3; } if ($t4 == 1) { if ($t3 == 1) { $where = $where . " OR "; } elseif ($t2 == 1) { $where = $where . " OR "; } elseif ($t1 == 1) { $where = $where . " OR "; } $where = $where . "id_typ = ?"; $i = count($whereArr); $whereArr[$i] = 4; } if ($where != "") { if (count($whereArr) > 1) { $this->template->n_nemovitosti = $this->template->n_nemovitosti->where($where, $whereArr); if (!is_array($this->template->p_nemovitosti)) { $this->template->p_nemovitosti = $this->template->p_nemovitosti->where($where, $whereArr); } if (!is_array($this->template->a_nemovitosti)) { $this->template->a_nemovitosti = $this->template->a_nemovitosti->where($where, $whereArr); } if (!is_array($this->template->i_nemovitosti)) { $this->template->i_nemovitosti = $this->template->i_nemovitosti->where($where, $whereArr); } } else { // osetreni chyby aby to nepadalo kvuli 1 prvkovemu poli $this->template->n_nemovitosti = $this->template->n_nemovitosti->where($where, $whereArr[0]); if (!is_array($this->template->p_nemovitosti)) { $this->template->p_nemovitosti = $this->template->p_nemovitosti->where($where, $whereArr[0]); } if (!is_array($this->template->a_nemovitosti)) { $this->template->a_nemovitosti = $this->template->a_nemovitosti->where($where, $whereArr[0]); } if (!is_array($this->template->i_nemovitosti)) { $this->template->i_nemovitosti = $this->template->i_nemovitosti->where($where, $whereArr[0]); } } } else { // pokud jsou vsechny typy ve formu uzivatelem vykliknuty, tak nema cenu nic vracet $this->template->n_nemovitosti = $this->template->p_nemovitosti = $this->template->i_nemovitosti = $this->template->a_nemovitosti = array(); } } }
public function renderZajemci() { $this->template->zajemci = $this->database->findAll('uzivatel')->where('id_typ_uzivatele', 3)->order('nick'); }