private function beforeInsert() { $this->log_content = Callback::searchMovie($this->query); foreach ($this->getContent() as $movie_info) { if (!Movie::model()->with('attributes')->find('tmdb_id=:id', array(':id' => $movie_info['imdb_id']))) { $movie = new Movie(); $movie->setUrlKey($movie_info); $movie->tmdb_id = $movie_info['id']; $movie->imdb_id = $movie_info['imdb_id']; $movie->save(); } } }
<?php $this->pageTitle = Yii::app()->name . ' - Dashboard'; ?> <?php $this->widget('zii.widgets.jui.CJuiAccordion', array('panels' => array('Recent Comments' => $this->renderPartial('_list', array('items' => Comment::model()->recent()->findAll()), true), 'LMDB Popular Movies' => $this->renderPartial('_list', array('items' => Movie::model()->popular()->findAll()), true), 'Top Public Movies' => $this->renderPartial('_list', array('items' => MovieAttributes::model()->top()->findAll()), true), 'Recent Added Movies' => $this->renderPartial('_list', array('items' => Movie::model()->recent()->findAll()), true), 'Recent Searches' => $this->renderPartial('_list', array('items' => SearchLog::model()->recent()->findAll()), true)), 'options' => array('animated' => 'bounceslide')));
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. */ public function loadModel($query = '') { if ($this->_model === null) { if (isset($_GET['id'])) { // switch($query) // { // case 'tmdb': $this->_model = Movie::model()->with(array('attributes', 'images'))->find('tmdb_id=:id', array(':id' => $_GET['id'])); } // break; // default: // $this->_model=Movie::model()->with(array('attributes', 'images'))->findbyPk($_GET['id']); // } if (isset($_GET['url_key'])) { $this->_model = Movie::model()->with(array('attributes', 'images'))->find('url_key LIKE :url_key', array(':url_key' => $_GET['url_key'])); } if ($this->_model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } } return $this->_model; }
public function setUrlKey($attributes) { $url_key = strtolower(preg_replace('/\\W+/', '-', $attributes['name'])); // if name is already given, add the release date if (Movie::model()->find('url_key LIKE :url_key', array(':url_key' => $url_key))) { $url_key .= "-" . substr($attributes['released'], 0, 4); } // if url_key is still not unique add a number $tmp_key = $url_key; for ($num = 1; Movie::model()->find('url_key LIKE :url_key', array(':url_key' => $url_key)); $num++) { $url_key = $tmp_key . "-{$num}"; } $this->url_key = $url_key; }