mmm, I used to have generic functions to get status and comments, unfortunately, I introduced the paginaiton and the load more button so the those functions became more and more specific towards a single use.
I will include a generic method for both status and comments, in the meantime you can use this method:
/**
* BreezeQuery::getStatus()
*
* Get all status made by X users. no pagination, no other special code.
* @param int|array $id the ID(s) of the user(s) to get the status from. If left empty the functon will load all available status.
* @param boolean $getComments Whether or not to include comments made on each status.
* @param int $limit How many status do you want to retrieve.
* @param string $sort Sorting for retrieving the data, by default is set to DESC (most recent)
* @return array An array containing all the status made by those users, two keys, data and users
*/
public function getStatus($id = false, $getComments = false, $limit = 5, $sort = 'status_id DESC')
{
// Declare some generic vars, mainly to avoid errors
$return = array(
'data' => array(),
'users' => array(),
);
$statusIDs = array();
$id = !empty($id) ? (array) $id : false;
// Fetch the status.
$result = $this->_smcFunc['db_query']('', '
SELECT '. implode(', ', $this->_tables['status']['columns']) .'
FROM {db_prefix}'. ($this->_tables['status']['table']) .'
'. (!empty($id) ? 'WHERE status_owner_id IN({array_int:owner})' : '') .'
ORDER BY {raw:sort}
LIMIT {int:limit}',
array(
'owner' => $id,
'sort' => $sort,
'limit' => $limit,
)
);
// Populate the array like a big heavy boss!
while ($row = $this->_smcFunc['db_fetch_assoc']($result))
{
// Are we also fetching comments?
if ($getComments)
$statusIDs[] = $row['status_id'];
$return['data'][$row['status_id']] = array(
'id' => $row['status_id'],
'owner_id' => $row['status_owner_id'],
'poster_id' => $row['status_poster_id'],
'time' => $this->tools->timeElapsed($row['status_time']),
'time_raw' => $row['status_time'],
'body' => $this->parser->display($row['status_body']),
'comments' => array(),
);
// Get the users IDs
$return['users'][] = $row['status_owner_id'];
$return['users'][] = $row['status_poster_id'];
}
$this->_smcFunc['db_free_result']($result);
// Now get the comments for each status.
if ($getComments && !empty($statusIDs))
{
$result = $this->_smcFunc['db_query']('', '
SELECT '. implode(', ', $this->_tables['comments']['columns']) .'
FROM {db_prefix}'. ($this->_tables['comments']['table']) .'
WHERE comments_status_id IN({array_int:status})
ORDER BY comments_id ASC
',
array(
'status' => $statusIDs,
)
);
// Append the data to our main return array
while ($row = $this->_smcFunc['db_fetch_assoc']($result))
{
$return['data'][$row['comments_status_id']]['comments'][$row['comments_id']] = array(
'id' => $row['comments_id'],
'status_id' => $row['comments_status_id'],
'status_owner_id' => $row['comments_status_owner_id'],
'poster_id' => $row['comments_poster_id'],
'profile_id' => $row['comments_profile_id'],
'time' => $this->tools->timeElapsed($row['comments_time']),
'time_raw' => $row['comments_time'],
'body' => $this->parser->display($row['comments_body']),
);
// Append the users IDs.
$return['users'][] = $row['comments_poster_id'];
}
$this->_smcFunc['db_free_result']($result);
}
// Clean it a bit
if (!empty($return['users']))
$return['users'] = array_values(array_filter(array_unique($return['users'])));
return $return;
}
put it inside Sources/Breeze/BreezeQuery.php
before this line of comments:
/**
* BreezeQuery::getStatusByProfile()
*
* Get all status made in X profile page. Uses a custom query and store the results on separate cache entries per profile.
* @param int $id the ID of the user that owns the profile page, it does not matter who made that status as long as the status was made in X profile page.
* @return array An array containing all the status made in X profile page
*/
and to use it you can use this on a php block:
global $breezeController;
if (empty($breezeController))
$breezeController = new BreezeController();
$status = $breezeController->get('query')->getStatus();
By default the function will show status made by everyone, will show the latest 5 and will not show comments associated with each status, however, you can change those parameters if you want.
You can modify the following params:
$id = false, $getComments = false, $limit = 5, $sort = 'DESC'
$id is the single ID or an array of IDs from users you want to show the latest status.
$getComments is a boolean value to tell the function if you also want to load all the comments for each status.
$limit is the amount of status to retrieve, by default is 5
$sort is the SQL sort, DESC means get the latest status made but you can add any valid SQL ORDER statement.
If the query fetched something, $status will be an array with 2 keys, users and data, $status['data'] holds all the status as an array, to get the body you can use something like this:
if (!empty($status['data']))
foreach ($status['data'] as $data)
echo $data['body'];