Marcel
Active member
Im on my way with this plugin
At the moment I have the following
A ControllerPublic with the following code
and a model which extends XenForo_Model_Thread
Now this works. It returns an array $threads filled with the relevant (unread) thread ID's and all the fields from the xf_thread table corresponding to each row selected.
Now, I want to parse this into a viewable list of results.
I've passed it to my template (which is a copy of thread_list with some bumpf taken out )
This shows some of the data needed. However, it doesn't for example, pull out the thread starter avatar, the node title etc.
How would I add these? I understand theyre from a different table, and my controller and model don't retrieve this data....
I tried with very limited knowledge of SQL to add it to the query in the model, but got stuck.
I know the whole structure is very primitive, but it's something I plan on building on. Naturally there will be permissions checks, pagination of results etc.
I also tried extending both the ControllerPublic class and the Model class via the XFCP method, but it didn't work, so I hope this is the correct way to do it!
This is executed by a route prefix /newposts
I hope to build on this with newposts/discussion ..... newposts/images etc etc. Hence doing it via a route controller
At the moment I have the following
A ControllerPublic with the following code
PHP:
<?php
class MaB_NewPosts_ControllerPublic_NewPosts extends XenForo_ControllerPublic_FindNew {
public function actionIndex()
{
$threadIds = $this->getModelFromCache('MaB_NewPosts_Model_NewPosts')->getUnreadThreads();
If (!$threadIds){
return $this->responseMessage(new XenForo_Phrase('mab_np_noresults'));
}
// If we're at this point then there must be results.
$viewParams = array('threads' => $threadIds);
return $this->responseView('MaB_NewPosts_ViewPublic_NewPosts', 'mab_np_main',$viewParams);
}
}
and a model which extends XenForo_Model_Thread
PHP:
<?php
class MaB_NewPosts_Model_NewPosts extends XenForo_Model_Thread
{
/**
* Gets the IDs of threads
*
* @param integer $userId
* @return array List of thread IDs
*/
public function getUnreadThreads()
{
return $this->_getDb()->fetchAll('
SELECT thread.*
FROM xf_thread AS thread
LEFT JOIN xf_node AS node ON
(node.node_id = thread.node_id)
LEFT JOIN xf_thread_read AS thread_read ON
(thread_read.thread_id = thread.thread_id AND thread_read.user_id = 1
AND thread_read.thread_read_date >= thread.last_post_date)
LEFT JOIN xf_forum_read AS forum_read ON
(forum_read.node_id = thread.node_id AND forum_read.user_id = 1
AND forum_read.forum_read_date >= thread.last_post_date)
WHERE thread_read.thread_read_date IS NULL
ORDER BY thread.last_post_date DESC
LIMIT 50');
}
}
Now this works. It returns an array $threads filled with the relevant (unread) thread ID's and all the fields from the xf_thread table corresponding to each row selected.
Now, I want to parse this into a viewable list of results.
I've passed it to my template (which is a copy of thread_list with some bumpf taken out )
This shows some of the data needed. However, it doesn't for example, pull out the thread starter avatar, the node title etc.
How would I add these? I understand theyre from a different table, and my controller and model don't retrieve this data....
I tried with very limited knowledge of SQL to add it to the query in the model, but got stuck.
I know the whole structure is very primitive, but it's something I plan on building on. Naturally there will be permissions checks, pagination of results etc.
I also tried extending both the ControllerPublic class and the Model class via the XFCP method, but it didn't work, so I hope this is the correct way to do it!
This is executed by a route prefix /newposts
I hope to build on this with newposts/discussion ..... newposts/images etc etc. Hence doing it via a route controller
Last edited: