/** * Finds the Movie model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Movie the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Movie::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Movie::find(); $query->andFilterWhere(['state' => AppActiveRecord::STATUS_DELETE]); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['defaultOrder' => ['updatedOn' => SORT_DESC]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['Id' => $this->Id, 'launguageId' => $this->launguageId, 'starRating' => $this->starRating, 'oldStarRating' => $this->oldStarRating, 'avgerageUserRate' => $this->avgerageUserRate, 'reviewCount' => $this->reviewCount, 'releaseDate' => $this->releaseDate, 'createdOn' => $this->createdOn, 'status' => $this->status, 'length' => $this->length, 'toiMovieId' => $this->toiMovieId, 'topLevelCount' => $this->topLevelCount, 'recommendedCount' => $this->recommendedCount, 'agreeCount' => $this->agreeCount, 'disagreeCount' => $this->disagreeCount, 'updatedOn' => $this->updatedOn, 'createdBy' => $this->createdBy, 'updatedBy' => $this->updatedBy, 'entityType' => $this->entityType, 'state' => $this->state]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'cast', $this->cast])->andFilterWhere(['like', 'synopsis', $this->synopsis])->andFilterWhere(['like', 'parentalGuidance', $this->parentalGuidance])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'tagline', $this->tagline])->andFilterWhere(['like', 'review', $this->review])->andFilterWhere(['like', 'movieDirector', $this->movieDirector])->andFilterWhere(['like', 'musicDirector', $this->musicDirector])->andFilterWhere(['like', 'oldGuid', $this->oldGuid])->andFilterWhere(['like', 'guid', $this->guid])->andFilterWhere(['like', 'shortCode', $this->shortCode])->andFilterWhere(['like', 'canonicalUrl', $this->canonicalUrl])->andFilterWhere(['like', 'ip', $this->ip]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Movie::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getMovie() { return $this->hasOne(Movie::className(), ['id' => 'movie_id']); }
public static function createNewMovie($id) { $token = new ApiToken(self::API_KEY); $client = new Client($token, ['secure' => false]); $configRepository = new ConfigurationRepository($client); $config = $configRepository->load(); $repository = new MovieRepository($client); $newMovie = $repository->load($id); $movie = new Movie(); $movie->tmdb_id = $newMovie->getId(); $movie->imdb_id = $newMovie->getImdbId(); $movie->title = $newMovie->getTitle(); $movie->overview = $newMovie->getOverview(); $movie->homepage = $newMovie->getHomepage(); $movie->poster = $newMovie->getPosterPath(); $movie->runtime = $newMovie->getRuntime(); foreach ($newMovie->getReleases() as $release) { if (in_array($release->getIso31661(), ['US', 'TH'])) { $movie->rate = $release->getCertification(); $movie->release = $release->getReleaseDate()->getTimestamp(); break; } } $arrayTemp = []; foreach ($newMovie->getGenres() as $genre) { $arrayTemp[$genre->getId()] = $genre->getName(); } $movie->genre = $arrayTemp; $arrayTemp = []; foreach ($newMovie->getImages() as $image) { $arrayTemp[] = $image->getFilePath(); } $movie->image = $arrayTemp; $arrayTemp = []; foreach ($newMovie->getVideos() as $trailer) { $arrayTemp[] = $trailer->getUrl(); } $movie->trailer = $arrayTemp; $arrayTemp = []; foreach ($newMovie->getCredits()->getCast() as $key => $person) { $arrayTemp[$key]['tmdb_id'] = $person->getId(); $arrayTemp[$key]['full_name'] = $person->getName(); $arrayTemp[$key]['image_path'] = $person->getProfilePath(); $arrayTemp[$key]['character'] = $person->getCharacter(); $arrayTemp[$key]['job'] = ''; $arrayTemp[$key]['type'] = 1; } foreach ($newMovie->getCredits()->getCrew() as $key => $person) { $arrayTemp[$key]['tmdb_id'] = $person->getId(); $arrayTemp[$key]['full_name'] = $person->getName(); $arrayTemp[$key]['image_path'] = $person->getProfilePath(); $arrayTemp[$key]['character'] = ''; $arrayTemp[$key]['job'] = $person->getJob(); $arrayTemp[$key]['type'] = 2; } $movie->people = $arrayTemp; if ($movie->save()) { return $movie; } throw new HttpException(500, 'Something went wrong!!'); }
<?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'hall_id')->dropDownList(\yii\helpers\ArrayHelper::map(\common\models\Hall::find()->all(), 'id', 'hall_name'), ['prompt' => 'Select Hall']); ?> <?php echo $form->field($model, 'start_time')->dropDownList(\yii\helpers\ArrayHelper::map(\common\models\Time::find()->where(['6' => '0'])->all(), 'time_id', 'time_list'), ['prompt' => 'Select time', "disabled" => "disabled"]); ?> <?php echo $form->field($model, 'movie_id')->dropDownList(\yii\helpers\ArrayHelper::map(\common\models\Movie::find()->all(), 'id', 'name'), ['prompt' => 'Select Movie', "disabled" => "disabled"]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div> <script>
public function actionIndex($id, $name) { $movie = Movie::findOne(['tmdb_id' => $id]); if (!isset($movie) || empty($movie)) { echo 'create new<br>'; $movie = TmdbHelper::createNewMovie($id); } if (empty($movie->imdb->id)) { $imdbService = new \common\components\Imdb(); $imdb = new \common\models\Imdb(); $mArr = $imdbService->getMovieInfoById($movie->imdb_id); $imdb->id = $movie->imdb_id; $imdb->rating = $mArr['rating_value']; $imdb->max_rating = 10; $imdb->num_review = intval(str_replace(',', '', $mArr['rating_count'])); $imdb->save(); $movie = Movie::findOne(['tmdb_id' => $id]); } else { if (time() - $movie->imdb->updated_at > 3600 * 8) { $imdbService = new \common\components\Imdb(); $mArr = $imdbService->getMovieInfoById($movie->imdb_id); $imdb = \common\models\Imdb::findOne($movie->imdb_id); $imdb->rating = $mArr['rating_value']; $imdb->num_review = intval(str_replace(',', '', $mArr['rating_count'])); $imdb->save(); $movie = Movie::findOne(['tmdb_id' => $id]); } } if (empty($movie->rt->id)) { $rtService = new \common\components\Rt(); $mArr = $rtService->getMovieInfo($movie->title); $rt = new \common\models\Rt(); $rt->id = $movie->imdb_id; $rt->url = $mArr['url']; $rt->critic_meter_tomato = $mArr['critic_meter_tomato']; $rt->critic_score = $mArr['critic_score']; $rt->average_rating = $mArr['average_rating']; $rt->reviews_counted = $mArr['reviews_counted']; $rt->fresh = $mArr['fresh']; $rt->rotten = $mArr['rotten']; $rt->user_meter_tomato = $mArr['user_meter_tomato']; $rt->user_score = $mArr['user_score']; $rt->user_average_rating = $mArr['user_average_rating']; $rt->user_reviews_counted = intval(str_replace(',', '', $mArr['user_reviews_counted'])); $rt->save(); $movie = Movie::findOne(['tmdb_id' => $id]); } else { if (time() - $movie->rt->updated_at > 3600 * 12) { $rtService = new \common\components\Rt(); $mArr = $rtService->getMovieInfo($movie->title); $rt = \common\models\Rt::findOne($movie->imdb_id); $rt->critic_meter_tomato = $mArr['critic_meter_tomato']; $rt->critic_score = $mArr['critic_score']; $rt->average_rating = $mArr['average_rating']; $rt->reviews_counted = $mArr['reviews_counted']; $rt->fresh = $mArr['fresh']; $rt->rotten = $mArr['rotten']; $rt->user_meter_tomato = $mArr['user_meter_tomato']; $rt->user_score = $mArr['user_score']; $rt->user_average_rating = $mArr['user_average_rating']; $rt->user_reviews_counted = intval(str_replace(',', '', $mArr['user_reviews_counted'])); $rt->save(); $movie = Movie::findOne(['tmdb_id' => $id]); } } // echo '<pre>', print_r($rt->getErrors()); // die; return $this->render('index', ['movie' => $movie]); }
public function getMovie() { return $this->hasMany(Movie::className(), ['id' => 'movie_id'])->via('moviePeople'); }
use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel common\models\SessionSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Sessions'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="session-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['label' => 'Hall', 'format' => 'raw', 'value' => function ($row) { return \common\models\Hall::findOne(['id' => $row->hall_id])->hall_name; }], ['label' => 'Movie', 'format' => 'raw', 'value' => function ($row) { return \common\models\Movie::findOne(['id' => $row->movie_id])->name; }], 'start_time', ['class' => 'yii\\grid\\ActionColumn', 'template' => ' {link}', 'buttons' => ['update' => function ($url, $model) { return Html::a('<span class="glyphicon glyphicon-screenshot"></span>', $url); }, 'link' => function ($url, $model, $key) { return Html::a('Order tikcet', ['order', 'id' => $model->id, 'hallid' => $model->hall_id]); }]]]]); ?> </div>
public function getMovieMap() { return $this->hasMany(Movie::className(), ['launguageId' => 'Id']); }
public function actionMovieautosuggest($search = null) { Yii::$app->response->format = Response::FORMAT_JSON; $query = \common\models\Movie::find(); if ($search) { $query->andFilterWhere(['like', 'name', $search . '%', false]); } //*/ $query->andFilterWhere(['status' => \common\component\AppActiveRecord::STATUS_PUBLISH]); //*/ $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query]); $data = []; foreach ($dataProvider->getModels() as $model) { $NameString = $model->name . ' (' . $model->languagename . ')'; //$NameString = (string)$model->Id; $data[] = ['id' => $model->Id, 'text' => $NameString]; } return $data; }