本文整理汇总了PHP中Gdn_DataSet::index方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_DataSet::index方法的具体用法?PHP Gdn_DataSet::index怎么用?PHP Gdn_DataSet::index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_DataSet
的用法示例。
在下文中一共展示了Gdn_DataSet::index方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: array
/**
* Get and store list of current bans.
*
* @since 2.0.18
* @access public
*/
public static function &allBans()
{
if (!self::$_AllBans) {
self::$_AllBans = Gdn::sql()->get('Ban')->resultArray();
self::$_AllBans = Gdn_DataSet::index(self::$_AllBans, array('BanID'));
}
// $AllBans =& self::$_AllBans;
return self::$_AllBans;
}
示例2: getProviders
/**
*
*
* @return array|null|type
*/
public function getProviders()
{
$this->SQL->select('uap.*')->from('UserAuthenticationProvider uap');
if (Gdn::session()->isValid()) {
$UserID = Gdn::session()->UserID;
$this->SQL->select('ua.ForeignUserKey', '', 'UniqueID')->join('UserAuthentication ua', "uap.AuthenticationKey = ua.ProviderKey and ua.UserID = {$UserID}", 'left');
}
$Data = $this->SQL->get()->resultArray();
$Data = Gdn_DataSet::index($Data, array('AuthenticationKey'));
foreach ($Data as &$Row) {
self::calculate($Row);
}
return $Data;
}
示例3: messages
/**
* Get all messages or one message.
*
* @param int|bool $ID ID of message to get.
* @return array|null
*/
public static function messages($ID = false)
{
if ($ID === null) {
Gdn::cache()->remove('Messages');
return;
}
$Messages = Gdn::cache()->get('Messages');
if ($Messages === Gdn_Cache::CACHEOP_FAILURE) {
$Messages = Gdn::sql()->get('Message', 'Sort')->resultArray();
$Messages = Gdn_DataSet::index($Messages, array('MessageID'));
Gdn::cache()->store('Messages', $Messages);
}
if ($ID === false) {
return $Messages;
} else {
return val($ID, $Messages);
}
}
示例4: getIDs
/**
*
*
* @param array $IDs
* @param bool $SkipCacheQuery
* @return array
* @throws Exception
*/
public function getIDs($IDs, $SkipCacheQuery = false)
{
$DatabaseIDs = $IDs;
$Data = [];
if (!$SkipCacheQuery) {
$Keys = [];
// Make keys for cache query
foreach ($IDs as $UserID) {
if (!$UserID) {
continue;
}
$Keys[] = formatString(self::USERID_KEY, ['UserID' => $UserID]);
}
// Query cache layer
$CacheData = Gdn::cache()->get($Keys);
if (!is_array($CacheData)) {
$CacheData = [];
}
foreach ($CacheData as $RealKey => $User) {
if ($User === null) {
$ResultUserID = trim(strrchr($RealKey, '.'), '.');
} else {
$ResultUserID = val('UserID', $User);
}
$this->setCalculatedFields($User);
$Data[$ResultUserID] = $User;
}
//echo "from cache:\n";
//print_r($Data);
$DatabaseIDs = array_diff($DatabaseIDs, array_keys($Data));
unset($CacheData);
}
// Clean out bogus blank entries
$DatabaseIDs = array_diff($DatabaseIDs, [null, '']);
// If we are missing any users from cache query, fill em up here
if (sizeof($DatabaseIDs)) {
$DatabaseData = $this->SQL->whereIn('UserID', $DatabaseIDs)->getWhere('User')->result(DATASET_TYPE_ARRAY);
$DatabaseData = Gdn_DataSet::index($DatabaseData, 'UserID');
//echo "from DB:\n";
//print_r($DatabaseData);
foreach ($DatabaseIDs as $ID) {
if (isset($DatabaseData[$ID])) {
$User = $DatabaseData[$ID];
$this->userCache($User, $ID);
// Apply calculated fields
$this->setCalculatedFields($User);
$Data[$ID] = $User;
} else {
$User = null;
$this->userCache($User, $ID);
}
}
}
$this->EventArguments['RequestedIDs'] = $IDs;
$this->EventArguments['LoadedUsers'] =& $Data;
$this->fireEvent('AfterGetIDs');
return $Data;
}
示例5: check
/**
* Do code checks on an uploaded addon.
*
* @param int $AddonID Addon to check.
* @param bool|false $SaveVersionID Whether to save the version id.
* @throws Exception Addon not found.
*/
public function check($AddonID, $SaveVersionID = false)
{
$this->permission('Addons.Addon.Manage');
if ($SaveVersionID !== false) {
// Get the version data.
$Version = $this->AddonModel->SQL->getWhere('AddonVersion', array('AddonVersionID' => $SaveVersionID))->firstRow(DATASET_TYPE_ARRAY);
$this->AddonModel->save($Version);
$this->Form->setValidationResults($this->AddonModel->validationResults());
}
$Addon = $this->AddonModel->getID($AddonID, false, ['GetVersions' => true]);
$AddonTypes = Gdn::sql()->get('AddonType')->resultArray();
$AddonTypes = Gdn_DataSet::index($AddonTypes, 'AddonTypeID');
if (!$Addon) {
throw notFoundException('Addon');
}
// Get the data for the most recent version of the addon.
$upload = new Gdn_Upload();
// Also used per version below.
$Path = $upload->copyLocal($Addon['File']);
$AddonData = arrayTranslate((array) $Addon, array('AddonID', 'AddonKey', 'Name', 'Type', 'Description', 'Requirements', 'Checked'));
try {
$FileAddonData = UpdateModel::analyzeAddon($Path);
if ($FileAddonData) {
$AddonData = array_merge($AddonData, arrayTranslate($FileAddonData, array('AddonKey' => 'File_AddonKey', 'Name' => 'File_Name', 'File_Type', 'Description' => 'File_Description', 'Requirements' => 'File_Requirements', 'Checked' => 'File_Checked')));
$AddonData['File_Type'] = valr($FileAddonData['AddonTypeID'] . '.Label', $AddonTypes, 'Unknown');
}
$upload->delete($Path);
} catch (Exception $Ex) {
$AddonData['File_Error'] = $Ex->getMessage();
}
$this->setData('Addon', $AddonData);
// Go through the versions and make sure we get the versions to check out.
$Versions = array();
foreach ($Addon['Versions'] as $Version) {
$Version = $Version;
$Path = $upload->copyLocal($Version['File']);
try {
$VersionData = arrayTranslate((array) $Version, array('AddonVersionID', 'Version', 'AddonKey', 'Name', 'MD5', 'FileSize', 'Checked'));
$FileVersionData = UpdateModel::analyzeAddon($Path);
$FileVersionData = arrayTranslate($FileVersionData, array('Version' => 'File_Version', 'AddonKey' => 'File_AddonKey', 'Name' => 'File_Name', 'MD5' => 'File_MD5', 'FileSize' => 'File_FileSize', 'Checked' => 'File_Checked'));
$upload->delete($Path);
} catch (Exception $Ex) {
$FileVersionData = array('File_Error' => $Ex->getMessage());
}
$Versions[] = array_merge($VersionData, $FileVersionData);
}
$this->setData('Versions', $Versions);
$this->addModule('AddonHelpModule');
$this->render();
}
示例6: joinAttachments
/**
* Joins attachments to data
*
* <code>
* <?php
* $AttachmentModel->JoinAttachments($Discussion, $Comments);
* ?>
* </code>
*
* @param $Data - Data to which to attach comments
* @param $Data2 - Optional set of Data to which to attach comments
*
*/
public function joinAttachments(&$Data, &$Data2 = null)
{
if ($Data == null) {
return;
}
// Gather the Ids.
$ForeignIDs = array();
self::gatherIDs($Data, $ForeignIDs);
if ($Data2) {
self::gatherIDs($Data2, $ForeignIDs);
}
// Get the attachments.
$Attachments = $this->getWhere(array('ForeignID' => array_keys($ForeignIDs)), 'DateInserted', 'desc')->resultArray();
$Attachments = Gdn_DataSet::index($Attachments, 'ForeignID', array('Unique' => false));
// Join the attachments.
$this->joinAttachmentsTo($Data, $Attachments);
if ($Data2) {
$this->joinAttachmentsTo($Data2, $Attachments);
}
}
示例7: postController_afterDiscussionFormOptions_handler
/**
* Add the tag input to the discussion form.
*
* @param Gdn_Controller $Sender
*/
public function postController_afterDiscussionFormOptions_handler($Sender)
{
if (in_array($Sender->RequestMethod, array('discussion', 'editdiscussion', 'question'))) {
// Setup, get most popular tags
$TagModel = TagModel::instance();
$Tags = $TagModel->getWhere(array('Type' => array_keys($TagModel->defaultTypes())), 'CountDiscussions', 'desc', c('Plugins.Tagging.ShowLimit', 50))->Result(DATASET_TYPE_ARRAY);
$TagsHtml = count($Tags) ? '' : t('No tags have been created yet.');
$Tags = Gdn_DataSet::index($Tags, 'FullName');
ksort($Tags);
// The tags must be fetched.
if ($Sender->Request->isPostBack()) {
$tag_ids = TagModel::SplitTags($Sender->Form->getFormValue('Tags'));
$tags = TagModel::instance()->getWhere(array('TagID' => $tag_ids))->resultArray();
$tags = array_column($tags, 'TagID', 'FullName');
} else {
// The tags should be set on the data.
$tags = array_column($Sender->data('Tags', array()), 'FullName', 'TagID');
$xtags = $Sender->data('XTags', array());
foreach (TagModel::instance()->defaultTypes() as $key => $row) {
if (isset($xtags[$key])) {
$xtags2 = array_column($xtags[$key], 'FullName', 'TagID');
foreach ($xtags2 as $id => $name) {
$tags[$id] = $name;
}
}
}
}
echo '<div class="Form-Tags P">';
// Tag text box
echo $Sender->Form->label('Tags', 'Tags');
echo $Sender->Form->textBox('Tags', array('data-tags' => json_encode($tags)));
// Available tags
echo wrap(Anchor(t('Show popular tags'), '#'), 'span', array('class' => 'ShowTags'));
foreach ($Tags as $Tag) {
$TagsHtml .= anchor(htmlspecialchars($Tag['FullName']), '#', 'AvailableTag', array('data-name' => $Tag['Name'], 'data-id' => $Tag['TagID'])) . ' ';
}
echo wrap($TagsHtml, 'div', array('class' => 'Hidden AvailableTags'));
echo '</div>';
}
}
示例8: addUserToConversation
/**
* Add another user to the conversation.
*
* @since 2.0.0
* @access public
*
* @param int $ConversationID Unique ID of conversation effected.
* @param int $UserID Unique ID of current user.
*/
public function addUserToConversation($ConversationID, $UserID)
{
if (!is_array($UserID)) {
$UserID = array($UserID);
}
// First define the current users in the conversation
$OldContributorData = $this->getRecipients($ConversationID);
$OldContributorData = Gdn_DataSet::index($OldContributorData, 'UserID');
$AddedUserIDs = array();
// Get some information about this conversation
$ConversationData = $this->SQL->select('LastMessageID')->select('DateUpdated')->select('CountMessages')->from('Conversation')->where('ConversationID', $ConversationID)->get()->firstRow();
// Add the user(s) if they are not already in the conversation
foreach ($UserID as $NewUserID) {
if (!array_key_exists($NewUserID, $OldContributorData)) {
$AddedUserIDs[] = $NewUserID;
$this->SQL->insert('UserConversation', array('UserID' => $NewUserID, 'ConversationID' => $ConversationID, 'LastMessageID' => $ConversationData->LastMessageID, 'CountReadMessages' => 0, 'DateConversationUpdated' => $ConversationData->DateUpdated));
} elseif ($OldContributorData[$NewUserID]->Deleted) {
$AddedUserIDs[] = $NewUserID;
$this->SQL->put('UserConversation', array('Deleted' => 0), array('ConversationID' => $ConversationID, 'UserID' => $NewUserID));
}
}
if (count($AddedUserIDs) > 0) {
$ActivityModel = new ActivityModel();
foreach ($AddedUserIDs as $AddedUserID) {
$ActivityModel->queue(array('ActivityType' => 'AddedToConversation', 'NotifyUserID' => $AddedUserID, 'HeadlineFormat' => t('You were added to a conversation.', '{ActivityUserID,User} added you to a <a href="{Url,htmlencode}">conversation</a>.'), 'Route' => '/messages/' . $ConversationID), 'ConversationMessage');
}
$ActivityModel->saveQueue();
$this->updateUserUnreadCount($AddedUserIDs);
$this->updateParticipantCount($ConversationID);
}
}
示例9: joinTags
/**
* Join the tags to a set of discussions.
*
* @param $data
*/
public function joinTags(&$data)
{
$ids = array();
foreach ($data as $row) {
$discussionId = val('DiscussionID', $row);
if ($discussionId) {
$ids[] = $discussionId;
}
}
// Select the tags.
$all_tags = $this->SQL->select('td.DiscussionID, t.TagID, t.Name, t.FullName')->from('TagDiscussion td')->join('Tag t', 't.TagID = td.TagID')->whereIn('td.DiscussionID', $ids)->get()->resultArray();
$all_tags = Gdn_DataSet::index($all_tags, 'DiscussionID', array('Unique' => false));
foreach ($data as &$row) {
$discussionId = val('DiscussionID', $row);
if (isset($all_tags[$discussionId])) {
$tags = $all_tags[$discussionId];
if ($this->StringTags) {
$tags = consolidateArrayValuesByKey($tags, 'Name');
setValue('Tags', $row, implode(',', $tags));
} else {
foreach ($tags as &$trow) {
unset($trow['DiscussionID']);
}
setValue('Tags', $row, $tags);
}
} else {
if ($this->StringTags) {
setValue('Tags', $row, '');
} else {
setValue('Tags', $row, array());
}
}
}
}
示例10: joinComments
/**
*
*
* @param type $Activities
* @since 2.1
*/
public function joinComments(&$Activities)
{
// Grab all of the activity IDs.
$ActivityIDs = array();
foreach ($Activities as $Activity) {
if ($ID = val('CommentActivityID', $Activity['Data'])) {
// This activity shares its comments with another activity.
$ActivityIDs[] = $ID;
} else {
$ActivityIDs[] = $Activity['ActivityID'];
}
}
$ActivityIDs = array_unique($ActivityIDs);
$Comments = $this->getComments($ActivityIDs);
$Comments = Gdn_DataSet::index($Comments, array('ActivityID'), array('Unique' => false));
foreach ($Activities as &$Activity) {
$ID = val('CommentActivityID', $Activity['Data']);
if (!$ID) {
$ID = $Activity['ActivityID'];
}
if (isset($Comments[$ID])) {
$Activity['Comments'] = $Comments[$ID];
} else {
$Activity['Comments'] = array();
}
}
}