Example #1
0
 protected function createComponentSongList($name)
 {
     $grid = new Grido\Grid($this, $name);
     $grid->setModel($this->songy);
     $grid->addColumnDate("datum", "Datum", "d.m.y")->setSortable();
     $grid->addColumnText("interpret_name", "Interpret")->setCustomRender(function ($item) {
         $template = $this->createTemplate();
         $template->setFile(__DIR__ . "/../templates/components/Grid/interpret.latte");
         $template->song = $item;
         return $template;
     })->setSortable()->setFilterText()->setSuggestion();
     $grid->addColumnText("name", "Song")->setCustomRender(function ($item) {
         $template = $this->createTemplate();
         $template->setFile(__DIR__ . "/../templates/components/Grid/song.latte");
         $template->song = $item;
         return $template;
     })->setSortable()->setFilterText()->setSuggestion();
     $filter = array('' => 'Všechny');
     $filter = \Nette\Utils\Arrays::mergeTree($filter, $this->zanry->getList());
     $grid->addColumnText("zanr_id", "Žánr")->setCustomRender(function ($item) {
         return $item->zanr ? $item->zanr->name : null;
     })->setFilterSelect($filter);
     $grid->addColumnText("zadatel", "Přidal(a)")->setCustomRender(function ($item) {
         $template = $this->createTemplate();
         $template->setFile(__DIR__ . "/../templates/components/Grid/zadatel.latte");
         $template->song = $item;
         return $template;
     })->setSortable()->setFilterText()->setSuggestion();
     $statuses = array('' => 'Všechny', 'approved' => 'Zařazené', 'rejected' => 'Vyřazené', 'waiting' => 'Čekající');
     $grid->addColumnText("status", "Status")->setCustomRender(function ($item) {
         $status = $item->status;
         $revizor = $item->revisor ? $item->ref("user", "revisor")->username : "******";
         switch ($status) {
             case "approved":
                 return Html::el("span", array("class" => "label label-success", "title" => "Schválil(a) " . $revizor))->setText("Zařazen");
             case "waiting":
                 return Html::el("span", array("class" => "label label-warning", "title" => "Čeká ve frontě ke schválení"))->setText("Čeká");
             case "rejected":
                 return Html::el("span", array("class" => "label label-danger", "title" => "Zamítl(a) " . $revizor))->setText("Vyřazen");
             default:
                 return Html::el("i")->setText("Neznámý");
         }
     })->setSortable()->setFilterSelect($statuses);
     $grid->addColumnText("vzkaz", "Vzkaz DJovi")->setCustomRender(function ($item) {
         $elm = Html::el("span");
         if ($item->private_vzkaz) {
             if (!$this->user->isAllowed("privateMsg", "view") && $this->user->id != $item->user_id) {
                 $elm->addAttributes(array("class" => "msg-hidden", "title" => "Tento vzkaz je určen pouze pro DJe"));
                 $elm->setText("Soukromý vzkaz");
                 return $elm;
             }
             $elm->addAttributes(array("class" => "msg-private", "title" => "Tento vzkaz je určen pouze pro DJe"));
             $elm->setText($item->vzkaz);
         } else {
             return $item->vzkaz;
         }
         return $elm;
     });
     $myLikes = $this->songList->getMyLikes($this->user);
     $grid->addColumnText("likes", "")->setCustomRender(function ($item) use($myLikes) {
         $likes = count($item->related('song_likes'));
         $isLiked = isset($myLikes[$item->id]) ?: false;
         $el = Html::el('a')->addAttributes(['class' => 'like' . ($isLiked ? ' liked' : '')]);
         $el->add(Html::el('i')->addAttributes(['class' => 'glyphicon glyphicon-heart']));
         $el->add(Html::el()->setText(' ' . $likes));
         $el->href($this->link('like!', ['id' => $item->id]));
         return $el;
     });
     if ($this->user->isAllowed("song", "approve")) {
         $grid->addActionHref("approve", "")->setIcon("ok")->setElementPrototype(Html::el("a", array("class" => "btn btn-success", "data-toggle" => "modal", "data-target" => ".modal")));
     }
     if ($this->user->isAllowed("song", "reject")) {
         $grid->addActionHref("reject", "")->setIcon("remove")->setElementPrototype(Html::el("a", array("class" => "btn btn-danger", "data-toggle" => "modal", "data-target" => ".modal")));
     }
     if ($this->user->isAllowed("song", "play")) {
         $grid->addActionHref("play", "")->setDisable(function ($item) {
             if ($item->link) {
                 return false;
             }
             return true;
         })->setIcon("play")->setElementPrototype(Html::el("a", array("class" => "btn btn-info", "data-toggle" => "modal", "data-target" => ".modal")));
     }
     if ($this->user->isAllowed("song", "edit")) {
         $grid->addActionHref("edit", "", "admin:song:editor")->setIcon("pencil")->setElementPrototype(Html::el("a", array("class" => "btn btn-default", "target" => "_blank")));
     }
     $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_OUTER);
     $grid->setDefaultSort(array("datum" => "DESC"));
     //Set face for grid
     $gridTemplate = __DIR__ . "/../templates/components/Grid.latte";
     if (file_exists($gridTemplate)) {
         $grid->setTemplateFile($gridTemplate);
     }
     return $grid;
 }
Example #2
0
 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;
 }