Last active
December 17, 2015 11:39
-
-
Save daohoangson/5603960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function getFeaturedItems($nodeIds, $groupIds, $limitOption) | |
{ | |
return $this->fetchAllKeyed($this->limitQueryResults( | |
' | |
SELECT thread.*, attachment.*, attachment_data.* | |
FROM xf_thread AS thread | |
LEFT JOIN xf_attachment AS attachment ON | |
(attachment.content_id = thread.first_post_id AND attachment.content_type = \'post\') | |
LEFT JOIN xf_attachment_data AS attachment_data ON | |
(attachment_data.data_id = attachment.data_id AND attachment_data.thumbnail_width > 0) | |
LEFT JOIN xf_user AS user ON | |
(user.user_id = thread.user_id) | |
WHERE thread.node_id IN (?) | |
AND thread.discussion_state = \'visible\' | |
AND user.secondary_group_ids IN (?) | |
GROUP BY thread.thread_id | |
', $limitOption, 0 | |
),'thread_id', array($nodeIds, $groupIds)); | |
} | |
public function rebuildFeaturedItems() | |
{ | |
$options = XenForo_Application::get('options'); | |
$nodeIds = implode(',', $options->FeaturedItems_specialForums); | |
$groupIds = implode(',', $options->FeaturedItems_userGroups); | |
$limitOption = $options->FeaturedItems_limitDisplay; | |
$featuredItems = $this->getFeaturedItems($nodeIds, $groupIds, $limitOption); | |
var_dump($featuredItems);die(); | |
$featuredItem = $this->_getAttachmentModel()->prepareAttachments($featuredItems); | |
#var_dump($featuredItem);die(); | |
return $featuredItem; | |
} | |
// SImilar thread | |
public function getSimilarThreads($threadTitle, $threadId, $limitThread, &$forumIds, $excludeForums) | |
{ | |
/* Fixed with full thread title. I feel freely ... ^^ */ | |
if(strlen($threadTitle) > 80) | |
{ | |
$threadTitle = utf8_substr($threadTitle, 0, 60); /* Fixed with non-english posts */ | |
} | |
$excludeForums = implode(', ', $excludeForums); | |
$db = XenForo_Application::get('db'); | |
return $this->fetchAllKeyed($this->limitQueryResults( | |
' | |
SELECT thread.*, search_index.title, search_index.content_id,user.gender, user.avatar_date, user.gravatar, | |
MATCH(search_index.title) AGAINST (? IN BOOLEAN MODE) AS score | |
FROM xf_thread AS thread | |
LEFT JOIN xf_search_index AS search_index ON | |
(search_index.content_id = thread.thread_id) | |
LEFT JOIN xf_user AS user ON | |
(user.user_id = thread.user_id) | |
WHERE MATCH(search_index.title) AGAINST (? IN BOOLEAN MODE) | |
AND search_index.content_type = \'thread\' | |
AND thread.thread_id != ? | |
AND thread.node_id = ? | |
AND thread.node_id NOT IN (?) | |
HAVING score >= 1 | |
ORDER BY search_index.content_id DESC | |
', $limitThread, 0 | |
),'thread_id', array($threadTitle, $threadTitle, $threadId, $forumIds, $excludeForums)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const FETCH_JOIN_ATTACHMENT = 'FETCH_JOIN_ATTACHMENT'; | |
const FETCH_JOIN_USER = 'FETCH_JOIN_USER'; | |
public function prepareThreadFetchOptions(array $fetchOptions) | |
{ | |
$result = parent::prepareThreadFetchOptions($fetchOptions); | |
$selectFields =& $result['selectFields']; | |
$joinTables =& $result['joinTables']; | |
if(!empty($fetchOptions['FI_join'])){ | |
if($fetchOptions['FI_join'] & self::FETCH_JOIN_ATTACHMENT) { | |
$selectFields .= ', | |
attachment.*, attachment_data.*'; | |
$joinTables .= ' | |
LEFT JOIN xf_attachment AS attachment ON | |
(attachment.content_id = thread.first_post_id AND attachment.content_type = \'post\') | |
LEFT JOIN xf_attachment_data AS attachment_data ON | |
(attachment_data.data_id = attachment.data_id AND attachment_data.thumbnail_width > 0)'; | |
} | |
if ($fetchOptions['FI_join'] & self::FETCH_JOIN_USER){ | |
$selectFields .= ', | |
user.*, IF(user.username IS NULL, thread.username, user.username) AS username'; | |
$joinTables .= ' | |
LEFT JOIN xf_user AS user ON | |
(user.user_id = thread.user_id)'; | |
} | |
} | |
return $result; | |
} | |
public function prepareThreadConditions(array $conditions, array &$fetchOptions) | |
{ | |
$result = parent::prepareThreadConditions($conditions, $fetchOptions); | |
$sqlConditions = array($result); | |
$db = $this->_getDb(); | |
if(!empty($conditions['discussion_state'])){ | |
$sqlConditions[] = 'thread.discussion_state = '. $db->quote($conditions['discussion_state']); | |
} | |
if(!empty($conditions['secondary_group_ids'])){ | |
if (is_array($conditions['secondary_group_ids'])) { | |
$sqlConditions[] = 'user.secondary_group_ids IN (' . $db->quote($conditions['secondary_group_ids']) . ')'; | |
}else { | |
$sqlConditions[] = 'user.secondary_group_ids = ' . $db->quote($conditions['secondary_group_ids']); | |
} | |
} | |
if(count($sqlConditions) > 1){ | |
return $this->getConditionsForClause($sqlConditions); | |
}else{ | |
return $result; | |
} | |
} | |
public function getFeaturedItems() | |
{ | |
$options = XenForo_Application::get('options'); | |
$nodeIds = $options->FeaturedItems_specialForums; | |
$groupIds = $options->FeaturedItems_userGroups; | |
$limit = $options->FeaturedItems_limitDisplay; | |
$conditions = array( | |
'discussion_state' => 'visible', | |
'secondary_group_ids' => $groupIds, | |
'node_id' => $nodeIds | |
); | |
$fetchOptions = array( | |
'FI_join' => self::FETCH_JOIN_ATTACHMENT + self::FETCH_JOIN_USER, | |
); | |
$threads = $this->getThreads($conditions, $fetchOptions); | |
#var_dump($threads);die(); | |
return $threads; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment