Skip to content

Commit

Permalink
Jeroens commit, think I got everything
Browse files Browse the repository at this point in the history
  • Loading branch information
yjeroen committed Jul 7, 2012
1 parent ec7189b commit c2bd29b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 13 deletions.
32 changes: 29 additions & 3 deletions protected/controllers/SongController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,35 @@ public function actionSongs() {
* Grid of all song reviews
*/
public function actionReviews() {
$this->render('grid', array(
'song' => $this->searchSong('Review'),
));
$review = new Review('search');
$review->unsetAttributes();
$song = new Song('search');
$song->unsetAttributes();
$genre = new Genre('search');
$genre->unsetAttributes();

if (isset($_GET['Review']))
$review->attributes = $_GET['Review'];
if (isset($_GET['Song']))
$song->attributes = $_GET['Song'];
if (isset($_GET['Genre']))
$genre->attributes = $_GET['Genre'];

$review->searchSong = $song;
$review->searchGenre = $genre;

if(!isset($_GET['ajax']))
$this->render('reviewsGrid', array(
'review' => $review,
'song' => $song,
'genre' => $genre,
));
else
$this->renderPartial('reviewsGrid', array(
'review' => $review,
'song' => $song,
'genre' => $genre,
));
}

public function actionAddReviews() {
Expand Down
6 changes: 4 additions & 2 deletions protected/models/Genre.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public static function model($className = __CLASS__) {
public function tableName() {
return 'genre';
}

public function rules() {
return array();
return array(
array('id, name', 'safe', 'on' => 'search'),
);
}

public function relations() {
Expand Down
33 changes: 25 additions & 8 deletions protected/models/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
* @property Song $song
*/
class Review extends CActiveRecord {
public $searchSong;
public $searchGenre;

public static function model($className = __CLASS__) {
return parent::model($className);
}

public function tableName() {
return 'review';
}

public function rules() {
return array();
return array(
array('review', 'safe', 'on' => 'search'),
);
}

public function relations() {
Expand All @@ -37,14 +42,26 @@ public function attributeLabels() {
'review' => 'Review',
);
}

public function search() {
$criteria = new CDbCriteria;

$criteria->compare('reviewer_id', $this->reviewer_id, true);
$criteria->compare('song_id', $this->song_id, true);
$criteria->compare('review', $this->review, true);


//Selecting all data from song, because its a has one relation
//Not selecting any data from genres, because its lazy loaded anyway by Song::genreNames
$criteria->with = array('song', 'song.genres'=>array('select'=>false));
$criteria->group = 't.reviewer_id, t.song_id';
$criteria->together = true;

$criteria->compare('t.reviewer_id', $this->reviewer_id, true);
$criteria->compare('t.song_id', $this->song_id, true);
$criteria->compare('t.review', $this->review, true);

$criteria->compare('song.name', $this->searchSong->name, true);
$criteria->compare('song.artist', $this->searchSong->artist, true);
$criteria->compare('song.album', $this->searchSong->album, true);
$criteria->compare('genres.id', $this->searchGenre->id, true);
$criteria->compare('genres.name', $this->searchGenre->name, true);

return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
Expand Down
48 changes: 48 additions & 0 deletions protected/views/song/reviewsGrid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* @var Review $review
* @var Controller|CController $this
*/

$columns = array(
array(
'header' => 'Num',
'value' => Help::$gridRowExp,
),
array(
'name' => 'review',
),
array(
'name' => 'song.name',
'filter' => CHtml::activeTextField($song, 'name'),
),
array(
'name' => 'song.artist',
'filter' => CHtml::activeTextField($song, 'artist'),
),
array(
'name' => 'song.album',
'filter' => CHtml::activeTextField($song, 'album'),
),
array(
'type' => 'raw',
'header' => 'Genres',
'value' => 'Help::tags($data->song->genreNames, "genres", true)',
'filter' => CHtml::activeTextField($genre, 'name'),
// 'filter' => CHtml::activedropDownList($genre, 'id', CHtml::listData(Genre::model()->findAll(array('order'=>'name')),'id','name'), array('empty'=>'Select') ),
),

);


$dp = $review->search();
$dp->pagination->pageSize = 50;
$grid = array(
'id' => 'song-grid',
'dataProvider' => $dp,
'filter' => $review,
'columns' => $columns,
);

echo CHtml::tag('h1', array(), 'Manage ' . $this->action->id);
$this->widget('zii.widgets.grid.CGridView', $grid);

0 comments on commit c2bd29b

Please sign in to comment.