/**
  * Удаление автора.
  *
  * @param int $id
  * @return \yii\web\Response
  */
 public function actionDelete($id)
 {
     /** @var Author $modelAuthor */
     $modelAuthor = Author::findOne($id);
     if ($modelAuthor->delete()) {
         return $this->redirect(['back-author/index']);
     }
     return $this->refresh();
 }
 /**
  * Сохраняет модель и связанные данные
  *
  * @param Book $modelBook
  * @return \yii\web\Response
  */
 private function _saveBook(Book $modelBook)
 {
     $authorIds = Yii::$app->request->post('authors');
     $tagIds = Yii::$app->request->post('tags');
     if ($modelBook->load(Yii::$app->request->post()) && $modelBook->save()) {
         array_map(function ($model) use($modelBook) {
             $modelBook->unlink('authors', $model, true);
         }, $modelBook->authors);
         foreach ($authorIds ?: [] as $authorId) {
             /** @var Author $modelAuthor */
             $modelAuthor = Author::findOne($authorId);
             $modelBook->link('authors', $modelAuthor);
         }
         array_map(function ($model) use($modelBook) {
             $modelBook->unlink('tags', $model, true);
         }, $modelBook->tags);
         foreach ($tagIds ?: [] as $tagId) {
             /** @var Tag $modelTag */
             $modelTag = Tag::findOne($tagId);
             $modelBook->link('tags', $modelTag);
         }
         return $this->redirect(['back-book/view', 'id' => $modelBook->id]);
     }
 }
 public function runPKSearch($i)
 {
     $author = $this->authors[array_rand($this->authors)];
     $author = Author::findOne($author->id);
     //        $this->em->clear();
 }
Beispiel #4
0
 /**
  * Finds the Author model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Author the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Author::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #5
0
 /**
  * Displays a single Book model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     return $this->render('view', ['model' => $model, 'author' => (new AuthorEntity())->createEntity(Author::findOne($model->author_id))]);
 }
Beispiel #6
0
 /**
  * Генератор тэговых страниц
  */
 public function actionGetTags()
 {
     $list = scandir('/home/romanych/www/vrs/pages/');
     $list = array_diff($list, ['.', '..']);
     //var_dump($list); exit;
     $alphabet = fopen("/home/romanych/www/vrs/alphabet.html", "w");
     fwrite($alphabet, self::$header);
     foreach ($list as $letter) {
         fwrite($alphabet, "<div class='letters'><a href='pages/" . $letter . "/tags.html'>" . $letter . "</a></div>");
         $alfa_tags = fopen("/home/romanych/www/vrs/pages/" . $letter . "/tags.html", "w");
         fwrite($alfa_tags, self::$header);
         fwrite($alfa_tags, self::$footer);
         fclose($alfa_tags);
     }
     fwrite($alphabet, self::$footer);
     fclose($alphabet);
     $tags = Tag::find()->orderBy('name')->all();
     //var_dump($tags); exit;
     //$file =  fopen("/home/romanych/www/vrs/tags.html", "w");
     //fwrite($file, self::$header);
     foreach ($tags as $tag) {
         $first_letter = mb_substr($tag->name, 0, 1, 'UTF-8');
         //var_dump($first_letter); exit;
         $big_first_letter = mb_strtoupper($first_letter, 'UTF-8');
         $alfa_tags = fopen("/home/romanych/www/vrs/pages/" . $big_first_letter . "/tags.html", "a");
         fwrite($alfa_tags, "<a href='" . TranslateHelper::translit($tag->name) . ".html'><button type='button' class='btn btn-default btn-lg'>{$tag->name}</button></a>");
         fwrite($alfa_tags, self::$footer);
         fclose($alfa_tags);
         //fwrite($file, "<p><a href='pages/".$big_first_letter."/". TranslateHelper::translit($tag->name) .".html'>$tag->name</a></p>");
         $page = fopen("/home/romanych/www/vrs/pages/" . $big_first_letter . "/" . TranslateHelper::translit($tag->name) . ".html", "w");
         fwrite($page, '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                         <link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css">
                         <meta name="viewport" content="width=device-width, initial-scale=1.0">
                         <style>.item_head{font-weight: bold;} body{padding-left: 20px; padding-top: 20px;} </style>');
         $items = explode(",", $tag->items);
         $r = 1;
         foreach ($items as $item) {
             try {
                 $item = Items::findOne(['id' => (int) $item]);
                 $source = Source::findOne(['id' => $item->source_id]);
                 $author = Author::findOne(['id' => $source->author_id]);
                 fwrite($page, "<p class='item_head'>{$r} {$item->title} ({$author->name} - {$source->title})</p>\n                    " . $this->renderPlayer($item->audio_link) . "\n                    " . nl2br("<p>{$item->text}</p>") . "\n\n                    ");
             } catch (\ErrorException $e) {
                 echo $e->getMessage() . PHP_EOL;
                 var_dump(Items::findOne(['id' => (int) $item]));
             }
             $r++;
         }
         fwrite($page, self::$footer);
         fclose($page);
     }
     //fwrite($file, self::$footer);
     //fclose($file);
 }