本文整理汇总了PHP中DatabaseObject::BuildMultiple方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseObject::BuildMultiple方法的具体用法?PHP DatabaseObject::BuildMultiple怎么用?PHP DatabaseObject::BuildMultiple使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseObject
的用法示例。
在下文中一共展示了DatabaseObject::BuildMultiple方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetLocations
public static function GetLocations($db, $options = array())
{
$defaults = array('post_id' => array());
foreach ($defaults as $k => $v) {
$options[$k] = array_key_exists($k, $options) ? $options[$k] : $v;
}
$select = $db->select();
$select->from(array('l' => 'blog_posts_locations'), 'l.*');
if (count($options['post_id']) > 0) {
$select->where('l.post_id in (?)', $options['post_id']);
}
$data = $db->fetchAll($select);
$locations = parent::BuildMultiple($db, __CLASS__, $data);
return $locations;
}
示例2: GetUsers
public static function GetUsers($db, $options = array())
{
// initialize the options
$defaults = array('offset' => 0, 'limit' => 0, 'order' => 'u.username');
foreach ($defaults as $k => $v) {
$options[$k] = array_key_exists($k, $options) ? $options[$k] : $v;
}
$select = self::_GetBaseQuery($db, $options);
// set the fields to select
$select->from(null, 'u.*');
// set the offset, limit, and ordering of results
if ($options['limit'] > 0) {
$select->limit($options['limit'], $options['offset']);
}
$select->order($options['order']);
// fetch user data from database
$data = $db->fetchAll($select);
// turn data into array of DatabaseObject_User objects
$users = parent::BuildMultiple($db, __CLASS__, $data);
if (count($users) == 0) {
return $users;
}
$user_ids = array_keys($users);
// load the profile data for loaded posts
$profiles = Profile::BuildMultiple($db, 'Profile_User', array('user_id' => $user_ids));
foreach ($users as $user_id => $user) {
if (array_key_exists($user_id, $profiles) && $profiles[$user_id] instanceof Profile_User) {
$users[$user_id]->profile = $profiles[$user_id];
} else {
$users[$user_id]->profile->setUserId($user_id);
}
}
return $users;
}