Gdn_DataSet::result PHP Method

result() public method

Returns an array of data as the specified result type: object or array.
public result ( string $DatasetType = false )
$DatasetType string The format in which to return a row: object or array. The following values are supported. - DATASET_TYPE_ARRAY: An array of associative arrays. - DATASET_TYPE_OBJECT: An array of standard objects. - FALSE: The current value of the DatasetType property will be used.
    public function &result($DatasetType = false)
    {
        $this->datasetType($DatasetType);
        if (is_null($this->_Result)) {
            $this->_fetchAllRows();
        }
        return $this->_Result;
    }

Usage Example

Beispiel #1
0
 /**
  * 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);
                 }
             }
         }
     }
 }
All Usage Examples Of Gdn_DataSet::result