本文整理汇总了PHP中Gdn_DataSet::result方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_DataSet::result方法的具体用法?PHP Gdn_DataSet::result怎么用?PHP Gdn_DataSet::result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_DataSet
的用法示例。
在下文中一共展示了Gdn_DataSet::result方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: joinUsers
/**
* Add user data to a result set.
*
* @param array|Gdn_DataSet $Data Results we need to associate user data with.
* @param array $Columns Database columns containing UserIDs to get data for.
* @param array $Options Optionally pass list of user data to collect with key 'Join'.
*/
public function joinUsers(&$Data, $Columns, $Options = [])
{
if ($Data instanceof Gdn_DataSet) {
$Data2 = $Data->result();
} else {
$Data2 =& $Data;
}
// Grab all of the user fields that need to be joined.
$UserIDs = [];
foreach ($Data as $Row) {
foreach ($Columns as $ColumnName) {
$ID = val($ColumnName, $Row);
if (is_numeric($ID)) {
$UserIDs[$ID] = 1;
}
}
}
// Get the users.
$Users = $this->getIDs(array_keys($UserIDs));
// Get column name prefix (ex: 'Insert' from 'InsertUserID')
$Prefixes = [];
foreach ($Columns as $ColumnName) {
$Prefixes[] = StringEndsWith($ColumnName, 'UserID', true, true);
}
// Join the user data using prefixes (ex: 'Name' for 'InsertUserID' becomes 'InsertName')
$Join = val('Join', $Options, ['Name', 'Email', 'Photo']);
foreach ($Data2 as &$Row) {
foreach ($Prefixes as $Px) {
$ID = val($Px . 'UserID', $Row);
if (is_numeric($ID)) {
$User = val($ID, $Users, false);
foreach ($Join as $Column) {
$Value = $User[$Column];
if ($Column == 'Photo') {
if ($Value && !isUrl($Value)) {
$Value = Gdn_Upload::url(changeBasename($Value, 'n%s'));
} elseif (!$Value) {
$Value = UserModel::getDefaultAvatarUrl($User);
}
}
setValue($Px . $Column, $Row, $Value);
}
} else {
foreach ($Join as $Column) {
setValue($Px . $Column, $Row, null);
}
}
}
}
}
示例2: addDenormalizedViews
/**
* Add denormalized views to discussions.
*
* @param Gdn_DataSet|stdClass $Discussions
*/
public function addDenormalizedViews(&$Discussions)
{
if ($Discussions instanceof Gdn_DataSet) {
$Result = $Discussions->result();
foreach ($Result as &$Discussion) {
$CacheKey = sprintf(DiscussionModel::CACHE_DISCUSSIONVIEWS, $Discussion->DiscussionID);
$CacheViews = Gdn::cache()->get($CacheKey);
if ($CacheViews !== Gdn_Cache::CACHEOP_FAILURE) {
$Discussion->CountViews += $CacheViews;
}
}
} else {
if (isset($Discussions->DiscussionID)) {
$Discussion = $Discussions;
$CacheKey = sprintf(DiscussionModel::CACHE_DISCUSSIONVIEWS, $Discussion->DiscussionID);
$CacheViews = Gdn::cache()->get($CacheKey);
if ($CacheViews !== Gdn_Cache::CACHEOP_FAILURE) {
$Discussion->CountViews += $CacheViews;
}
}
}
}