本文整理汇总了PHP中Artist::insertMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP Artist::insertMultiple方法的具体用法?PHP Artist::insertMultiple怎么用?PHP Artist::insertMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Artist
的用法示例。
在下文中一共展示了Artist::insertMultiple方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionInject
public function actionInject()
{
header('Content-type:application/json');
$post = Yii::app()->getRequest()->getPost('chart');
$weeks = $post['weeks'];
$artists = array();
$tracks = array();
$chart_entries = array();
// traverse $week
/* weeks : [
* {
* week : 1,
* year : 2008,
* tracks : [{
* start : 0,
* mark : 1,
* position : 32,
* track : "Sexual Eruption",
* artist : "Snoop Dogg"
* }]
* }
* ]
*/
foreach ($weeks as $week) {
foreach ($week['tracks'] as $chart_entry) {
// populate artists
$artist_name = $chart_entry['artist'];
$artist_hash = md5($artist_name);
if (!isset($artists[$artist_hash])) {
$artists[$artist_hash] = $artist_name;
}
// populate tracks
$track_title = $chart_entry['track'];
$track_hash = md5("{$track_title}\\%charty\\%{$artist_name}");
if (!isset($tracks[$track_hash])) {
$tracks[$track_hash] = array('title' => $track_title, 'artist_hash' => $artist_hash);
}
// populate chart_entry_data
$chart_entries[] = array('year' => $week['year'], 'week' => $week['week'], 'position' => $chart_entry['position'], 'track_hash' => $track_hash);
}
}
$inserted_artists = Artist::insertMultiple($artists);
$inserted_tracks = Track::insertMultiple($tracks);
$inserted_chart_entries = ChartEntry::insertMultiple($chart_entries);
echo json_encode(array('inserted_artists' => $inserted_artists, 'inserted_tracks' => $inserted_tracks, 'inserted_chart_entries' => $inserted_chart_entries));
}