/**
  * @param $id
  * @param $status
  * @throws \Nette\Application\BadRequestException
  */
 public function actionView($id, $status = null)
 {
     $interpret = $this->interpreti->find($id);
     if ($status) {
         $this->template->status = $status;
     }
     if (!$interpret) {
         throw new Nette\Application\BadRequestException("Interpret does not exists!", 404);
     }
     if ($interpret->interpret_id) {
         $msg = $this->flashMessage("Přesměrováno z '{$interpret->nazev}'");
         $msg->title = "Alias";
         $this->redirect("this", array("id" => $interpret->interpret_id));
         //If is alias => redirect to real
     }
     $this->template->interpret = $interpret;
     //Register helper fot fetching song form last.fm
     $this->template->registerhelper('songImage', function ($song, $img = 0) {
         try {
             return $this->lastfm->call('Track.getInfo', ['track' => $song->name, 'artist' => $song->interpret_name])->track->album->image[$img]->{'#text'};
         } catch (Model\Lastfm\LastfmException $e) {
             return null;
         }
     });
     //Last.fm Interpret info (images)
     try {
         $this->template->lastfm = $this->lastfm->call('Artist.getInfo', ['artist' => $interpret->nazev])->artist;
     } catch (Model\Lastfm\LastfmException $e) {
         if ($this->settings->get('lastfm_enabled', false)) {
             Debugger::log($e);
         }
     }
 }
Example #2
0
 /**
  *
  * @param int $songId
  * @param string|int $interpret name or ID
  * @return \Nette\Database\Table\ActiveRow|false
  */
 public function assignInterpret($songId, $interpret)
 {
     if (is_string($interpret)) {
         $ri = $this->interpreti->getByName($interpret);
         if ($ri) {
             return $this->setInterpret($songId, $ri->id);
         }
         return false;
     } elseif (is_integer($interpret)) {
         return $this->setInterpret($songId, $interpret);
     }
     throw new \Nette\InvalidArgumentException(603, "Interpret must be name (string) or ID (integer)");
 }
 protected function createComponentAssociator()
 {
     $form = new Form();
     $form->addSubmit('make', 'Proveď');
     $form->onSuccess[] = function (Form $frm) {
         $data = $frm->getHttpData(Form::DATA_TEXT);
         $created = 0;
         if (isset($data['create'])) {
             foreach ($data['create'] as $toCreate => $on) {
                 $r = $this->interpreti->add($toCreate, '', null, $this->user);
                 $data['assoc'][$toCreate] = $r->id;
                 $created++;
             }
         }
         $this->songy->beginTransaction();
         $count = 0;
         foreach ($data['assoc'] as $key => $value) {
             if ($value) {
                 $this->songy->findBy(['interpret_name' => $key])->where('interpret_id IS NULL')->update(['interpret_id' => $value]);
                 $count++;
             }
         }
         if (!$count) {
             $msg = $this->flashMessage("V seznamu níže vyberte interprety, které chcete asociovat s registrem a ze seznamu položek daného interpreta určete, " . "se kterým interpretem v registru má být asociován, nebo zaškrtněte možnost 'vytvořit' pro přidání " . "interpreta do registru a jeho následnou asociaci.", 'info');
             $msg->title = 'Vyberte interprety k asociaci';
             $msg->icon = 'ticket';
             $this->redirect('this');
         }
         $this->logger->log('Interpret', 'assoc', "%user% provedla asociace interpretů");
         $this->songy->commit();
         $msg = $this->flashMessage("{$count} interpretů bylo úspěšně asiciováno s registrem. ({$created} vytvořeno)", 'success');
         $msg->title = 'Oh yeah!';
         $msg->icon = 'check';
         $this->redirect('this');
     };
     return $form;
 }
Example #4
0
 public function actionMatchInterpret($match)
 {
     $this->sendJson($this->interpreti->match($match, 10, 0));
 }
Example #5
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;
 }