Beispiel #1
0
 /**
  * Finds the Items model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Items the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Items::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #2
0
 public function loadModel($id)
 {
     $model = Items::findOne($id);
     if ($model === null) {
         throw new \yii\web\HttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Beispiel #3
0
 /**
  * Выборка для случайного концерта
  * @return string
  */
 function actionConcert()
 {
     if ($user = Yii::$app->getRequest()->getQueryParam('user')) {
         if (!$user) {
             return 'Доступ запрещн!';
         }
         // $user = Yii::$app->getRequest()->getQueryParam('user');
         if (Items::find()->where(['is_next' => 1])->one()) {
             $item = Items::find()->where(['is_next' => 1])->one();
             $song_id = $item->id;
         } else {
             $song_id = 100;
         }
         $songs = [];
         //return $song_id;
         $songs1 = Items::find()->where("(source_id = 6 or source_id = 40) and id < {$song_id} and published = 1")->limit(5)->orderBy('id DESC')->all();
         $songs2 = Items::find()->where("(source_id = 19 or source_id = 41) and id < {$song_id} and published = 1")->limit(5)->orderBy('id DESC')->all();
         $songs3 = Items::find()->where("source_id = 38 and id < {$song_id} and published = 1")->limit(5)->orderBy('id DESC')->all();
         $songs4 = Items::find()->where("(source_id = 29 or source_id = 326 or source_id = 526) and id < {$song_id} and published = 1")->limit(1)->orderBy('id DESC')->all();
         $songs = array_merge($songs1, $songs2, $songs3, $songs4);
         shuffle($songs);
         //return var_dump($songs);
         //$choosen_songs = [];
         foreach ($songs as $song) {
             try {
                 $items_records = [];
                 $tags = explode(',', $song->tags);
                 $rand_tag = $tags[mt_rand(0, count($tags) - 1)];
                 $this->rand_tag[] = $rand_tag;
                 $query = new Query();
                 // $search_result = $query_search->from('siteSearch')->match($q)->all();  // поиск осуществляется по средством метода match с переданной поисковой фразой.
                 $query_items_ids = $query->from('items')->match($rand_tag)->all();
                 //return var_dump($query_items_ids);
                 foreach ($query_items_ids as $arr_item_rec) {
                     foreach ($arr_item_rec as $id) {
                         $item = Items::findOne((int) $id);
                         if ($item->cat_id == 93 || $item->cat_id == 104 || $item->cat_id == 105 || $item->cat_id == 143 || $item->cat_id == 136) {
                             $items_records[] = Items::findOne((int) $id);
                         }
                     }
                 }
                 //return var_dump($items_records[mt_rand(0,count($items_records)-1)]->text);
                 if (empty($items_records)) {
                     continue;
                 }
                 $rand_index = mt_rand(0, count($items_records) - 1);
                 $song->phrase = $items_records[$rand_index]->text;
                 if (isset($items_records[$rand_index + 1]) && $song->phrase != $song->phrase2) {
                     $song->phrase2 = $items_records[$rand_index + 1]->text;
                 } else {
                     $song->phrase2 = $items_records[0]->text;
                 }
                 //return $song->phrase.'<br>'.$song->phrase2;
                 //return var_dump($song);
                 $this->choosen_songs[] = $song;
             } catch (\ErrorException $e) {
                 return $e->getMessage();
             }
         }
         //exit;
         //return var_dump($this->choosen_songs);
         return $this->renderPartial('concert', ['songs' => $this->choosen_songs, 'tags' => $this->rand_tag]);
     }
 }
Beispiel #4
0
 public function actionItemprice()
 {
     if (\filter_input(INPUT_POST, 'item')) {
         $item_id = filter_input(INPUT_POST, 'item');
         $model = Items::findOne($item_id);
         if (!empty($model)) {
             return json_encode($model->price);
         }
     }
 }
Beispiel #5
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);
 }