pivotGet moved into Managed_DataObject

This commit is contained in:
Mikael Nordfeldth 2013-08-29 10:13:07 +02:00
parent cb94a29e84
commit fac7371179
8 changed files with 26 additions and 22 deletions

View File

@ -22,11 +22,6 @@ class Avatar extends Managed_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
static function pivotGet($keyCol, $keyVals, $otherCols)
{
return Memcached_DataObject::pivotGet('Avatar', $keyCol, $keyVals, $otherCols);
}
public static function schemaDef()
{

View File

@ -61,6 +61,20 @@ abstract class Managed_DataObject extends Memcached_DataObject
return parent::pkeyGetClass(get_called_class(), $kv);
}
/**
* Get multiple items from the database by key
*
* @param string $keyCol name of column for key
* @param array $keyVals key values to fetch
* @param array $otherCols Other columns to hold fixed
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
static function pivotGet($keyCol, array $keyVals, array $otherCols=array())
{
return parent::pivotGetClass(get_called_class(), $keyCol, $keyVals, $otherCols);
}
/**
* Get a multi-instance object
*

View File

@ -76,7 +76,7 @@ class Memcached_DataObject extends Safe_DataObject
*/
function multiGet($cls, $keyCol, $keyVals, $skipNulls=true)
{
$result = self::pivotGet($cls, $keyCol, $keyVals);
$result = self::pivotGetClass($cls, $keyCol, $keyVals);
$values = array_values($result);
@ -103,7 +103,7 @@ class Memcached_DataObject extends Safe_DataObject
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
static function pivotGet($cls, $keyCol, $keyVals, $otherCols = array())
static function pivotGetClass($cls, $keyCol, array $keyVals, array $otherCols = array())
{
if (!is_a($cls, __CLASS__, true)) {
throw new Exception('Trying to fetch ' . __CLASS__ . ' into a non-related class');
@ -292,7 +292,7 @@ class Memcached_DataObject extends Safe_DataObject
}
if (count($allPkeys) > 0) {
$keyResults = self::pivotGet($cls, $pkeyCols, $allPkeys);
$keyResults = self::pivotGetClass($cls, $pkeyCols, $allPkeys);
foreach ($pkeyMap as $keyVal => $pkeyList) {
foreach ($pkeyList as $pkeyVal) {

View File

@ -2600,7 +2600,7 @@ class Notice extends Managed_DataObject
$ids = array_unique($ids);
return Memcached_DataObject::pivotGet('Profile', 'id', $ids);
return Profile::pivotGet('id', $ids);
}
static function fillGroups(&$notices)
@ -2621,7 +2621,7 @@ class Notice extends Managed_DataObject
$gids = array_unique($gids);
$group = Memcached_DataObject::pivotGet('User_group', 'id', $gids);
$group = User_group::pivotGet('id', $gids);
foreach ($notices as $notice)
{
@ -2660,7 +2660,7 @@ class Notice extends Managed_DataObject
$fileIds = array_unique($fileIds);
$fileMap = Memcached_DataObject::pivotGet('File', 'id', $fileIds);
$fileMap = File::pivotGet('id', $fileIds);
foreach ($notices as $notice)
{

View File

@ -1494,8 +1494,4 @@ class Profile extends Managed_DataObject
{
return $this;
}
static function pivotGet($key, $values, $otherCols=array()) {
return Memcached_DataObject::pivotGet('Profile', $key, $values, $otherCols);
}
}

View File

@ -144,7 +144,7 @@ class RawInboxNoticeStream extends NoticeStream
$ids = $this->getNoticeIds($offset, $limit, $sinceId, $maxId);
$notices = Memcached_DataObject::pivotGet('Notice', 'id', $ids);
$notices = Notice::pivotGet('id', $ids);
// By default, takes out false values

View File

@ -147,8 +147,8 @@ class NoticeList extends Widget
$ids[] = $notice->id;
}
Memcached_DataObject::pivotGet('Fave', 'notice_id', $ids, array('user_id' => $p->id));
Memcached_DataObject::pivotGet('Notice', 'repeat_of', $ids, array('profile_id' => $p->id));
Fave::pivotGet('notice_id', $ids, array('user_id' => $p->id));
Notice::pivotGet('repeat_of', $ids, array('profile_id' => $p->id));
}
Event::handle('EndNoticeListPrefill', array(&$notices, &$profiles, $avatarSize));

View File

@ -89,10 +89,9 @@ class ScopingNoticeStream extends FilteringNoticeStream
$pids[] = $profile->id;
}
Memcached_DataObject::pivotGet('Profile_role',
'profile_id',
$pids,
array('role' => Profile_role::SILENCED));
Profile_role::pivotGet('profile_id',
$pids,
array('role' => Profile_role::SILENCED));
}
}
}