ACC SHELL
<?php
/**
* CelnoveTymu presenter.
*/
class ClenoveTymuPresenter extends BasePresenter
{
private $name = 'členové týmu';
private $presenter = 'ClenoveTymu';
private $table = 'uzivatele';
private $resource = 'uzivatel';
public function renderDefault()
{
if ($this->user->isAllowed($this->resource, 'view'))
{
$this->template->uzivatele;
$this->template->typickeVlastnostiHracuMohouBytUpraveny = array();
foreach ($this->template->uzivatele as $uzivatel)
{
$typickaVlastnostZmenena = $uzivatel->typickaVlastnostZmenena;
$typickaVlastnostMuzeBytZmenena = clone $typickaVlastnostZmenena;
$typickaVlastnostMuzeBytZmenena->add(DateInterval::createFromDateString($this->typickaVlastnostProdleva));
if ($typickaVlastnostMuzeBytZmenena > new DateTime())
{
$this->template->typickeVlastnostiHracuMohouBytUpraveny[$uzivatel->id] = false;
}
else
{
$this->template->typickeVlastnostiHracuMohouBytUpraveny[$uzivatel->id] = true;
}
}
}
else
{
$this->flashMessage("K prohlížení sekce Členové týmu nemáš oprávnění!", 'error');
$this->redirectToLogin($this->getName(), $this->request->parameters);
}
}
public function renderVsichni()
{
$this->renderDefault();
}
public function renderZmenitStatus($id)
{
if ($this->user->isAllowed('aktivnost', 'edit', $this->user->id, $id))
{
$player = $this->db->table('uzivatele')->get($id);
$player->update(array('aktivni' => !$player->aktivni));
$this->flashMessage("Status hráče změněn!", 'success');
if ($player->aktivni)
{
$this->redirect("$this->presenter:");
}
else
{
$this->redirect("$this->presenter:vsichni");
}
}
else
{
$this->flashMessage("K úpravě této vlastnosti nemáš oprávnění!", 'error');
$this->redirect("$this->presenter:");
}
}
public function renderUpravitVlastnost($id)
{
if (!$this->user->isAllowed('typickaVlastnost', 'edit'))
{
$this->flashMessage("K editaci sekce $this->name nemáš oprávnění!", 'error');
$this->redirect("$this->presenter:");
}
$typickaVlastnostZmenena = $this->db->table($this->table)->get($id)->typickaVlastnostZmenena;
$typickaVlastnostMuzeBytZmenena = clone $typickaVlastnostZmenena;
$typickaVlastnostMuzeBytZmenena->add(DateInterval::createFromDateString($this->typickaVlastnostProdleva));
if ($typickaVlastnostMuzeBytZmenena > new DateTime())
{
$keZmeneZbyva = $typickaVlastnostMuzeBytZmenena->diff(new DateTime());
$this->flashMessage('Upravit vlastnost tohoto hráče půjde až za ' . $keZmeneZbyva->format("%d dny, %h hodin a %i minut."), 'error');
$this->redirect("$this->presenter:");
}
}
// public function renderUpravitHrace($id)
// {
// if (!$this->user->isAllowed('ucet', 'edit'))
// {
// $this->flashMessage("K editaci sekce $this->name nemáš oprávnění!", 'error');
// $this->redirect("$this->presenter:");
// }
//
// if (file_exists('images/hraci/' . $id . '.png'))
// {
// $this->template->fotka = $id;
// }
// else
// {
// $this->template->fotka = 'default-profile';
// }
//
// $typickaVlastnostZmenena = $this->db->table($this->table)->get($id)->typickaVlastnostZmenena;
// $typickaVlastnostMuzeBytZmenena = clone $typickaVlastnostZmenena;
// $typickaVlastnostMuzeBytZmenena->add(DateInterval::createFromDateString($this->typickaVlastnostProdleva));
// if ($typickaVlastnostMuzeBytZmenena > new DateTime())
// {
// $keZmeneZbyva = $typickaVlastnostMuzeBytZmenena->diff(new DateTime());
// $this->flashMessage('Upravit vlastnost tohoto hráče půjde až za ' . $keZmeneZbyva->format("%d dny, %h hodin a %i minut."), 'error');
// $this->redirect("$this->presenter:");
// }
// }
protected function createComponentEditPropertyForm()
{
$form = new Nette\Application\UI\Form;
$form->addHidden('id');
$form->addText('jmeno', 'Jméno:')
->setDisabled();
$form->addText('prijmeni', 'Příjmení:')
->setDisabled();
$form->addText('prezdivka', 'Přezdívka:')
->setDisabled();
$form->addText('email', 'Email:', 30)
->setDisabled();
$form->addText('typickaVlastnost', 'Typická vlastnost:');
$form->addHidden('typickaVlastnostZmenena');
$typickaVlastnostZmenena = $this->db->table($this->table)->get($this->getParam('id'))->typickaVlastnostZmenena;
$typickaVlastnostMuzeBytZmenena = clone $typickaVlastnostZmenena;
$typickaVlastnostMuzeBytZmenena->add(DateInterval::createFromDateString($this->typickaVlastnostProdleva));
if ($typickaVlastnostMuzeBytZmenena > new DateTime())
{
$keZmeneZbyva = $typickaVlastnostMuzeBytZmenena->diff(new DateTime());
$form['typickaVlastnost']
->setAttribute('readonly', 'readonly')
->setAttribute('class', 'qtip questionmark')
->setAttribute('title', 'Půjde znovu změnit až za ' . $keZmeneZbyva->format("%d dny, %h hod a %i min") . '.');
}
else
{
$form['typickaVlastnost']
->setAttribute('class', 'qtip exclamationmark')
->setAttribute('title', 'Pokud upravíš tuto vlastnost, půjde znovu změnit až za ' . DateInterval::createFromDateString($this->typickaVlastnostProdleva)->format("%d") . ' dny.');
}
$defaults = $this->db->table($this->table)->get($this->getParam('id'))->toArray();
$form->setDefaults($defaults);
$form->addSubmit('edit', 'Uložit')
->onClick[] = callback($this, 'editPropertyFormSubmitted');
$presenter = $this;
$form->addSubmit('cancel', 'Zrušit')
->setValidationScope(FALSE)
->onClick[] = function() use ($presenter) {$presenter->redirect("ClenoveTymu:");};
return $form;
}
// protected function createComponentEditPlayerForm()
// {
// $form = new Nette\Application\UI\Form;
//
// $form->addHidden('id');
// $form->addText('jmeno', 'Jméno:');
// $form->addText('prijmeni', 'Příjmení:');
// $form->addText('prezdivka', 'Přezdívka:');
// $form->addText('email', 'Email:', 30);
//
// $defaults = $this->db->table($this->table)->get($this->getParam('id'))->toArray();
// $form->setDefaults($defaults);
//
// $form->addSubmit('edit', 'Uložit')
// ->onClick[] = callback($this, 'editPlayerFormSubmitted');
// $presenter = $this;
// $form->addSubmit('cancel', 'Zrušit')
// ->setValidationScope(FALSE)
// ->onClick[] = function() use ($presenter) {$presenter->redirect("ClenoveTymu:");};
//
// return $form;
// }
public function editPropertyFormSubmitted(Nette\Forms\Controls\SubmitButton $submitButton)
{
$values = $submitButton->getForm()->getValues();
if ($this->db->table($this->table)->get($values['id'])->typickaVlastnost != $values['typickaVlastnost'])
{
$values['typickaVlastnostZmenena'] = date('Y-m-d H:i');
if ($this->user->isAllowed('typickaVlastnost', 'edit', @$this->user->identity->id, $values->id))
{
$this->db->table($this->table)->get($values->id)->update($values);
$this->flashMessage('Typická vlastnost hráče byla upravena!', 'success');
$this->redirect("$this->presenter:");
}
else
{
$this->flashMessage("K editaci vlastnosti hráče nemáš oprávnění!", 'error');
$this->redirect("$this->presenter:");
}
}
else
{
$this->flashMessage("Nic nebylo změněno.", 'error');
$this->redirect("$this->presenter:");
} }
public function editPlayerFormSubmitted(Nette\Forms\Controls\SubmitButton $submitButton)
{
$values = $submitButton->getForm()->getValues();
if ($this->user->isAllowed('ucet', 'edit', @$this->user->identity->id, $values->id))
{
$this->db->table($this->table)->get($values->id)->update($values);
$this->flashMessage('Informace o hráči byly upraveny!', 'success');
$this->redirect("$this->presenter:");
}
else
{
$this->flashMessage("K editaci vlastnosti hráče nemáš oprávnění!", 'error');
$this->redirect("$this->presenter:");
}
}
protected function createComponentZmenaHeslaForm()
{
$form = new Nette\Application\UI\Form;
$form->addPassword('heslo', 'Heslo:', 20)
->setRequired('Vyplň heslo, chceš-li ho změnit.')
->addRule(Nette\Application\UI\Form::MIN_LENGTH, 'Heslo musí mít alespoň %d znaky.', 4);
$form->addPassword('heslo2', 'Heslo (podruhé):', 20)
->setRequired('Zadej heslo ještě jednou pro kontrolu.')
->addRule(Nette\Application\UI\Form::EQUAL, 'Hesla se neshodují.', $form['heslo']);
$form->addSubmit('submit', 'Změnit')
->onClick[] = callback($this, 'zmenaHeslaFormSubmitted');
return $form;
}
public function zmenaHeslaFormSubmitted(Nette\Forms\Controls\SubmitButton $submitButton)
{
$values = $submitButton->getForm()->getValues();
$values["heslo"] = md5($values["heslo"]);
unset($values["heslo2"]);
$this->db->table($this->table)->get($this->user->identity->id)->update($values);
$this->flashMessage('Heslo bylo změněno!', 'success');
$this->redirect("$this->presenter:");
}
}
ACC SHELL 2018