Skip to content

Instantly share code, notes, and snippets.

@v9n
Created December 23, 2011 10:02
Show Gist options
  • Select an option

  • Save v9n/1513776 to your computer and use it in GitHub Desktop.

Select an option

Save v9n/1513776 to your computer and use it in GitHub Desktop.
get playlist and schedule
<?php
class Model_Schedule_Detail extends Sprig {
protected function _init() {
$this->_fields += array(
'id' => new Sprig_Field_Auto,
'schedule' => new Sprig_Field_BelongsTo(array(
'model' => 'schedule',
'column' => 'schedule_id',
)),
'playlist' => new Sprig_Field_BelongsTo(array(
'model' => 'playlist',
'column' => 'playlist_id',
)),
);
}
}
?>
<?php
//..
if (count($playlists) > 0) {
$json = array('page' => $param['page'], 'total' => $total, 'rows' => array());
foreach ($playlists as $key => $playlist) {
$json['total']++;
$schedule_name = array();
foreach (Sprig::factory('schedule_detail', array('playlist' => $playlist->id))->load(NULL, false) as $k=>$v) {
$schedule_name[] = $v->schedule->load()->name;
}
$json['rows'][] = array('id' => $playlist->id, 'cell' => array($key+1, $playlist->name, $playlist->template_id->load()->name, $schedule_name, $playlist->user_id->load()->username));
}
return $json;
}
//..
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment