本文整理匯總了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;
}
}
}
}