importDataset() public method

Allows you to fill this object's result set with a foreign data set in the form of an array of associative arrays (or objects).
public importDataset ( array $Resultset )
$Resultset array The array of arrays or objects that represent the data to be traversed.
Ejemplo n.º 1
0
 /**
  * Called to prepare data grab, and then cache the results on the software level for the request.
  *
  * This will call PreloadDiscussionMedia, which will either query the db, or query memcached.
  *
  * @param mixed $Sender
  */
 protected function cacheAttachedMedia($Sender)
 {
     if ($Sender->data('Conversation')) {
         $ConversationMessageIDList = $this->getConversationMessageIDList(val('ConversationID', $Sender->data('Conversation')));
         if (count($ConversationMessageIDList)) {
             $MediaData = $this->preloadDiscussionMedia(val('ConversationID', $Sender->data('Conversation')), $ConversationMessageIDList, 'conversation');
         }
         $this->mediaCache = $MediaData;
         return;
     }
     if ($Sender->data('Messages')) {
         $Message = $Sender->data('Messages')->result();
         $MessageID = val(0, $Message)->MessageID;
         $MessageIDList = array($MessageID);
         if (count($MessageIDList)) {
             $MediaData = $this->preloadDiscussionMedia(val('ConversationID', $Sender->data('Messages')), $MessageIDList, 'conversation');
         }
         $this->mediaCache = $MediaData;
         return;
     }
     $DiscussionID = null;
     $Comments = $Sender->data('Comments');
     if ($answers = $Sender->data('Answers')) {
         $commentsArray = $Comments->resultObject();
         $commentsArray = array_merge($answers, $commentsArray);
         $commentsData = new Gdn_DataSet();
         $commentsData->importDataset($commentsArray);
         $Comments = $commentsData;
     }
     $CommentIDList = array();
     $MediaData = array();
     if ($Sender->data('Discussion.DiscussionID')) {
         $DiscussionID = $Sender->data('Discussion.DiscussionID');
     }
     if (is_null($DiscussionID) && !empty($Comments)) {
         $DiscussionID = $Comments->firstRow()->DiscussionID;
     }
     if ($DiscussionID) {
         if ($Comments instanceof Gdn_DataSet && $Comments->numRows()) {
             $Comments->dataSeek(-1);
             while ($Comment = $Comments->nextRow()) {
                 $CommentIDList[] = $Comment->CommentID;
             }
         } elseif (!empty($Sender->Discussion)) {
             $CommentIDList[] = $Sender->DiscussionID = $Sender->Discussion->DiscussionID;
         }
         if (isset($Sender->Comment) && isset($Sender->Comment->CommentID)) {
             $CommentIDList[] = $Sender->Comment->CommentID;
         }
         // TODO
         // Added note for caching here because it was the CommentIDList that is the main problem.
         // Note about memcaching:
         // Main problem with this is when a new comment is posted. It will only
         // have that current comment in the list, which, after calling
         // PreloadDiscussionMedia, means it will be the only piece of data added
         // to the cache, which prevents all the rest of the comments from loading
         // their own attachments. Consider either adding to the cache when a new
         // file is uploaded, or just getting a list of all comments for a discussion.
         // This is why memcaching has been disabled for now. There are a couple
         // ways to prevent this, but they all seem unnecessary.
         if (count($CommentIDList)) {
             $MediaData = $this->preloadDiscussionMedia($DiscussionID, $CommentIDList);
         }
         $this->mediaCache = $MediaData;
     }
 }