本文整理汇总了PHP中Gdn_DataSet::Join方法的典型用法代码示例。如果您正苦于以下问题:PHP Gdn_DataSet::Join方法的具体用法?PHP Gdn_DataSet::Join怎么用?PHP Gdn_DataSet::Join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Gdn_DataSet
的用法示例。
在下文中一共展示了Gdn_DataSet::Join方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Search
public function Search($Search, $Offset = 0, $Limit = 20)
{
$BaseUrl = C('Plugins.Solr.SearchUrl', 'http://localhost:8983/solr/select/?');
if (!$BaseUrl) {
throw new Gdn_UserException("The search url has not been configured.");
}
if (!$Search) {
return array();
}
// Escepe the search.
$Search = preg_replace('`([][+&|!(){}^"~*?:\\\\-])`', "\\\\\$1", $Search);
// Add the category watch.
$Categories = CategoryModel::CategoryWatch();
if ($Categories === FALSE) {
return array();
} elseif ($Categories !== TRUE) {
$Search = 'CategoryID:(' . implode(' ', $Categories) . ') AND ' . $Search;
}
// Build the search url.
$BaseUrl .= strpos($BaseUrl, '?') === FALSE ? '?' : '&';
$Query = array('q' => $Search, 'start' => $Offset, 'rows' => $Limit);
$Url = $BaseUrl . http_build_query($Query);
// Grab the data.
$Curl = curl_init($Url);
curl_setopt($Curl, CURLOPT_RETURNTRANSFER, 1);
$CurlResult = curl_exec($Curl);
curl_close($Curl);
// Parse the result into the form that the search controller expects.
$Xml = new SimpleXMLElement($CurlResult);
$Result = array();
if (!isset($Xml->result)) {
return array();
}
foreach ($Xml->result->children() as $Doc) {
$Row = array();
foreach ($Doc->children() as $Field) {
$Name = (string) $Field['name'];
$Row[$Name] = (string) $Field;
}
// Add the url.
switch ($Row['DocType']) {
case 'Discussion':
$Row['Url'] = '/discussion/' . $Row['PrimaryID'] . '/' . Gdn_Format::Url($Row['Title']);
break;
case 'Comment':
$Row['Url'] = "/discussion/comment/{$Row['PrimaryID']}/#Comment_{$Row['PrimaryID']}";
break;
}
// Fix the time.
$Row['DateInserted'] = strtotime($Row['DateInserted']);
$Result[] = $Row;
}
// Join the users into the result.
Gdn_DataSet::Join($Result, array('table' => 'User', 'parent' => 'UserID', 'prefix' => '', 'Name', 'Photo'));
return $Result;
}
示例2: JoinParticipants
public function JoinParticipants(&$Data)
{
$this->SQL->From('UserConversation uc')->Join('User u', 'u.UserID = uc.UserID');
Gdn_DataSet::Join($Data, array('alias' => 'uc', 'parent' => 'ConversationID', 'column' => 'Participants', 'UserID', 'u.Name', 'u.Photo'), array('sql' => $this->SQL));
}
示例3: Get2
/**
* Get a list of conversaitons for a user's inbox. This is an optimized version of ConversationModel::Get().
*
* @param int $UserID
* @param int $Offset Number to skip.
* @param int $Limit Maximum to return.
*/
public function Get2($UserID, $Offset = 0, $Limit = FALSE)
{
if (!$Limit) {
$Limit = C('Conversations.Conversations.PerPage', 30);
}
// The self join is intentional in order to force the query to us an index-scan instead of a table-scan.
$Data = $this->SQL->Select('c.*')->Select('uc2.DateLastViewed')->Select('uc2.CountReadMessages')->Select('uc2.LastMessageID', '', 'UserLastMessageID')->From('UserConversation uc')->Join('UserConversation uc2', 'uc.ConversationID = uc2.ConversationID and uc.UserID = uc2.UserID')->Join('Conversation c', 'c.ConversationID = uc2.ConversationID')->Where('uc.UserID', $UserID)->Where('uc.Deleted', 0)->OrderBy('uc.DateConversationUpdated', 'desc')->Limit($Limit, $Offset)->Get();
$Data->DatasetType(DATASET_TYPE_ARRAY);
$Result =& $Data->Result();
// Add some calculated fields.
foreach ($Result as &$Row) {
if ($Row['UserLastMessageID']) {
$Row['LastMessageID'] = $Row['UserLastMessageID'];
}
$Row['CountNewMessages'] = $Row['CountMessages'] - $Row['CountReadMessages'];
unset($Row['UserLastMessageID']);
}
// Join the participants.
$this->JoinParticipants($Result);
// Join in the last message.
Gdn_DataSet::Join($Result, array('table' => 'ConversationMessage', 'prefix' => 'Last', 'parent' => 'LastMessageID', 'child' => 'MessageID', 'InsertUserID', 'DateInserted', 'Body', 'Format'));
return $Data;
}