protected function createComponentUserList() { $grid = new Grid(); $grid->setModel($this->users->getUsers()); $grid->addColumnDate('registered', 'Registrován')->setSortable()->setFilterDateRange(); $grid->addColumnText('username', 'Uživatelské jméno')->setSortable()->setFilterText()->setSuggestion(); $grid->addColumnText('realname', 'Skutečné jméno')->setSortable()->setFilterText()->setSuggestion(); $grid->addColumnMail('email', 'Email')->setSortable()->setFilterText()->setSuggestion(); $roles = ['' => 'Vše'] + $this->perms->getRoles(); $grid->addColumnText('role', 'Role')->setSortable()->setFilterSelect($roles); $grid->addColumnText('auth_service', 'Aut. služba')->setSortable()->setFilterSelect(['' => 'Vše', 'twitter' => 'Twitter', 'songator' => 'Songator']); $grid->addActionHref('editor', 'Upravit')->setIcon('pencil'); $grid->addActionHref('selete', 'Smazat', 'delete!')->setConfirm('Opravdu smazat tohoto uživatele?')->setIcon('trash'); return $grid; }
protected function createComponentSongEditor() { $form = new Form(); $form->addText('name', 'Song')->setRequired('Zadejte název songu'); $form->addText('interpret_name', 'Interpret')->setRequired('Zadejte jméno interpreta'); $form->addSelect('interpret_id', 'Asociovat s', $this->interpreti->findAll()->fetchPairs('id', 'nazev'))->setPrompt('Vyberte asociaci'); $form->addSelect('zanr_id', 'Žánr', $this->zanry->findAll()->fetchPairs('id', 'name'))->setPrompt('Vyberte žánr')->setRequired('Vyberte žánr songu'); $form->addSelect('status', 'Status', ['waiting' => 'Čeká na schválení', 'approved' => 'Schválen', 'rejected' => 'Zamítnut'])->setRequired('Zadejte stav songu'); $form->addSelect('reason_code', 'Kód zamítnutí', \Rejections::$reasons)->setPrompt('Vyberte kód zamítnutí')->addConditionOn($form['status'], Form::EQUAL, 'rejected')->addRule(Form::FILLED, 'Musíte udat kód zamítnutí'); $form->addText('zadatel', 'Přezdívka žadatele')->addCondition(Form::FILLED)->addRule(Form::MIN_LENGTH, 'Přezdívka žadatele musí mít minimálně %s znaků', 3); $form->addSelect('user_id', 'Účet žadatele', $this->users->getUsers()->fetchPairs('id', 'username'))->setPrompt('Vyberte uživatele'); $form->addCheckboxList('flags', 'Flagy', ['pecka' => 'Pecka', 'instro' => 'Má instro', 'remix' => 'Remix', 'wishlist_only' => 'Pouze na přání']); $form->addText('link', 'URL k poslechu')->addCondition(Form::FILLED)->addRule(Form::URL, 'URL není v platném formátu'); $form->addTextArea('note', 'Poznámka DJe'); $form->addTextArea('vzkaz', 'Vzkaz pro DJe'); $form->addCheckbox('private_vzkaz', 'Vzkaz je soukromý'); $form->addHidden('id'); $form->addSubmit('send', 'Přidat'); $form->onSuccess[] = function (Form $f) { $val = $f->getValues(true); foreach ($val['flags'] as $flag) { $val[$flag] = true; } unset($val['flags']); //clear bordel //If requester not filled => assign to you if (!$val['zadatel'] && !$val['user_id']) { $val['zadatel'] = $this->user->identity->username; $val['user_id'] = $this->user->id; } //If requester not filled BUT USER ID engaged => fetch username for requester name if (!$val['zadatel'] && $val['user_id']) { $val['zadatel'] = $this->users->getUser($val['user_id'])->username; } try { if ($val['id']) { $original = $this->songy->find($val['id']); if ($original->status != $val['status']) { $val['revisor'] = $this->user->id; } $original->update($val); $this->logger->log('Song', 'edit', "%user% upravila(a) song {$original->name}"); $msg = $this->flashMessage("Song '{$val['interpret_name']} - {$val['name']}' upraven.", 'success'); $msg->title = 'A je tam!'; $msg->icon = 'check'; } else { $val['image'] = json_encode($this->lfm->getTrackImage($val['interpret_name'], $val['name'])) ?: ''; $val['revisor'] = $this->user->id; $song = $this->songy->add($val); $this->logger->log('Song', 'create', "%user% vytvořila(a) song {$song->name}"); $msg = $this->flashMessage("Song '{$val['interpret_name']} - {$val['name']}' přidán.", 'success'); $msg->title = 'A je tam!'; $msg->icon = 'check'; } } catch (\UnexpectedValueException $e) { $msg = $this->flashMessage($e->getMessage(), 'danger'); $msg->title = 'Oh shit!'; $msg->icon = 'exclamation'; } $this->redirect('this'); }; return $form; }