当前位置: 首页>>代码示例>>PHP>>正文


PHP Gdn_DataSet::result方法代码示例

本文整理汇总了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);
                 }
             }
         }
     }
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:57,代码来源:class.usermodel.php

示例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;
             }
         }
     }
 }
开发者ID:vanilla,项目名称:vanilla,代码行数:27,代码来源:class.discussionmodel.php


注:本文中的Gdn_DataSet::result方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。