Get a dataset for the model with a where filter.
public getWhere ( array | boolean $Where = false, string $OrderFields = '', string $OrderDirection = 'asc', integer | false $Limit = false, integer | false $Offset = false ) : Gdn_DataSet | ||
$Where | array | boolean | A filter suitable for passing to Gdn_SQLDriver::Where(). |
$OrderFields | string | A comma delimited string to order the data. |
$OrderDirection | string | One of **asc** or **desc**. |
$Limit | integer | false | The database limit. |
$Offset | integer | false | The database offset. |
return | Gdn_DataSet |
/** * Start merging user accounts. * * @param int $OldUserID The ID of the old user. * @param int $NewUserID The ID of the new user. * @return int|null Returns the merge table ID of the merge. * @throws Gdn_UserException Throws an exception of there is a data validation error. */ private function mergeStart($OldUserID, $NewUserID) { $Model = new Gdn_Model('UserMerge'); // Grab the users. $OldUser = $this->getID($OldUserID, DATASET_TYPE_ARRAY); $NewUser = $this->getID($NewUserID, DATASET_TYPE_ARRAY); // First see if there is a record with the same merge. $Row = $Model->getWhere(['OldUserID' => $OldUserID, 'NewUserID' => $NewUserID])->firstRow(DATASET_TYPE_ARRAY); if ($Row) { $MergeID = $Row['MergeID']; // Save this merge in the log. if ($Row['Attributes']) { $Attributes = dbdecode($Row['Attributes']); } else { $Attributes = []; } $Attributes['Log'][] = ['UserID' => Gdn::session()->UserID, 'Date' => Gdn_Format::toDateTime()]; $Row = ['MergeID' => $MergeID, 'Attributes' => $Attributes]; } else { $Row = ['OldUserID' => $OldUserID, 'NewUserID' => $NewUserID]; } $UserSet = []; $OldUserSet = []; if (dateCompare($OldUser['DateFirstVisit'], $NewUser['DateFirstVisit']) < 0) { $UserSet['DateFirstVisit'] = $OldUser['DateFirstVisit']; } if (!isset($Row['Attributes']['User']['CountVisits'])) { $UserSet['CountVisits'] = $OldUser['CountVisits'] + $NewUser['CountVisits']; $OldUserSet['CountVisits'] = 0; } if (!empty($UserSet)) { // Save the user information on the merge record. foreach ($UserSet as $Key => $Value) { // Only save changed values that aren't already there from a previous merge. if ($NewUser[$Key] != $Value && !isset($Row['Attributes']['User'][$Key])) { $Row['Attributes']['User'][$Key] = $NewUser[$Key]; } } } $MergeID = $Model->save($Row); if (val('MergeID', $Row)) { $MergeID = $Row['MergeID']; } if (!$MergeID) { throw new Gdn_UserException($Model->Validation->resultsText()); } // Update the user with the new user-level data. $this->setField($NewUserID, $UserSet); if (!empty($OldUserSet)) { $this->setField($OldUserID, $OldUserSet); } return $MergeID; }
/** * Query the Media table for any media related to the current discussion, * including all the comments. This will be cached per discussion. * * @param int $discussionID * @param array $commentIDList * @return array */ public function preloadDiscussionMedia($discussionID, $commentIDList, $type = 'discussion') { $mediaData = array(); $mediaDataDiscussion = array(); $mediaDataComment = array(); $mediaModel = new Gdn_Model('Media'); // Query the Media table for discussion media. if ($type === 'discussion') { if (is_numeric($discussionID)) { $sqlWhere = array('ForeignTable' => 'discussion', 'ForeignID' => $discussionID); $mediaDataDiscussion = $mediaModel->getWhere($sqlWhere)->resultArray(); } } // Query the Media table for comment media. if (is_numeric($commentIDList)) { $commentIDList[] = $commentIDList; } if (is_array($commentIDList) && count($commentIDList)) { $commentIDList = array_filter($commentIDList); $sqlWhere = array('ForeignTable' => $type == 'discussion' ? 'comment' : 'message', 'ForeignID' => $commentIDList); $mediaDataComment = $mediaModel->getWhere($sqlWhere)->resultArray(); } $mediaData = array_merge($mediaDataDiscussion, $mediaDataComment); return $mediaData; }
/** * Query the Media table for any media related to the current discussion, * including all the comments. This will be cached per discussion. * * @param int $discussionID * @param array $commentIDList * @return array */ public function preloadDiscussionMedia($discussionID, $commentIDList, $type = 'discussion') { $mediaData = array(); $mediaDataDiscussion = array(); $mediaDataComment = array(); /*$cacheKey = sprintf(self::DISCUSSION_MEDIA_CACHE_KEY, $discussionID); $cacheResponse = Gdn::cache()->get($cacheKey); if ($cacheResponse === Gdn_Cache::CACHEOP_FAILURE) {*/ $mediaModel = new Gdn_Model('Media'); // Query the Media table for discussion media. if ($type === 'discussion') { if (is_numeric($discussionID)) { $sqlWhere = array('ForeignTable' => 'discussion', 'ForeignID' => $discussionID); $mediaDataDiscussion = $mediaModel->getWhere($sqlWhere)->resultArray(); } } // Query the Media table for comment media. if (is_numeric($commentIDList)) { $commentIDList[] = $commentIDList; } if (is_array($commentIDList) && count($commentIDList)) { $commentIDList = array_filter($commentIDList); $sqlWhere = array('ForeignTable' => $type == 'discussion' ? 'comment' : 'message', 'ForeignID' => $commentIDList); $mediaDataComment = $mediaModel->getWhere($sqlWhere)->resultArray(); } $mediaData = array_merge($mediaDataDiscussion, $mediaDataComment); /* Gdn::cache()->store($cacheKey, $mediaData, array( Gdn_Cache::FEATURE_EXPIRY => $this->mediaCacheExpire )); } else { $mediaData = $cacheResponse; }*/ return $mediaData; }
/** * Delete a screenshot from an addon. * * @param string $AddonPictureID Picture id to remove. * @throws Gdn_UserException No permission to delete this picture. */ public function deletePicture($AddonPictureID = '') { $AddonPictureModel = new Gdn_Model('AddonPicture'); $Picture = $AddonPictureModel->getWhere(array('AddonPictureID' => $AddonPictureID))->firstRow(); $AddonModel = new AddonModel(); $Addon = $AddonModel->getID($Picture->AddonID); $Session = Gdn::session(); if ($Session->UserID != $Addon['InsertUserID'] && !$Session->checkPermission('Addons.Addon.Manage')) { throw permissionException(); } if ($this->Form->authenticatedPostBack() && $this->Form->getFormValue('Yes')) { if ($Picture) { $Upload = new Gdn_Upload(); $Upload->delete(changeBasename($Picture->File, 'ao%s')); $Upload->delete(changeBasename($Picture->File, 'at%s')); $AddonPictureModel->delete(array('AddonPictureID' => $AddonPictureID)); } $this->RedirectUrl = url('/addon/' . $Picture->AddonID); } $this->render('deletepicture'); }
/** * {@inheritDoc} * in addition; We CalculateRow for each record found (Add Attachments) * @see Gdn_Model::GetWhere */ public function getWhere($Where = false, $OrderFields = '', $OrderDirection = 'asc', $Limit = false, $Offset = false) { $Data = parent::getWhere($Where, $OrderFields, $OrderDirection, $Limit, $Offset); $Rows =& $Data->resultArray(); foreach ($Rows as &$Row) { $this->calculateRow($Row); } return $Data; }
/** * Get all the members of a conversation from the $ConversationID. * * @param int $ConversationID The conversation ID. * * @return array Array of user IDs. */ public function getConversationMembers($ConversationID) { $ConversationMembers = array(); $UserConversation = new Gdn_Model('UserConversation'); $UserMembers = $UserConversation->getWhere(array('ConversationID' => $ConversationID))->resultArray(); if (is_array($UserMembers) && count($UserMembers)) { $ConversationMembers = array_column($UserMembers, 'UserID'); } return $ConversationMembers; }
/** * * * @param $Name * @param $Value */ public static function touch($Name, $Value) { $Model = new Gdn_Model('Pocket'); $Pockets = $Model->getWhere(array('Name' => $Name))->resultArray(); if (empty($Pockets)) { $Pocket = array('Name' => $Name, 'Location' => 'Content', 'Sort' => 0, 'Repeat' => Pocket::REPEAT_BEFORE, 'Body' => $Value, 'Format' => 'Raw', 'Disabled' => Pocket::DISABLED, 'MobileOnly' => 0, 'MobileNever' => 0, 'EmbeddedNever' => 0, 'ShowInDashboard' => 0, 'Type' => 'default'); $Model->save($Pocket); } }