本文整理汇总了PHP中app\Board::threads方法的典型用法代码示例。如果您正苦于以下问题:PHP Board::threads方法的具体用法?PHP Board::threads怎么用?PHP Board::threads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Board
的用法示例。
在下文中一共展示了Board::threads方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleThreadEphemeral
/**
* Manage threads that have expired.
*
* @param App\Board $board
* @param Carbon\Carbon $time Optional Carbon that will be the xed_at timestamps. Defaults to now.
* @return void
*/
protected function handleThreadEphemeral(Board $board, Carbon $time = null)
{
if (is_null($time)) {
$time = Carbon::now();
}
// Get important settings.
$threadsPerPage = (int) $board->getConfig('postsPerPage', 10);
// Collect a list of threads which have been modified.
$threadsToSave = [];
// There are two groups of autoprune settings.
// x on day since last reply
$sageOnDay = (int) $board->getConfig('epheSageThreadDays', false);
$lockOnDay = (int) $board->getConfig('epheLockThreadDays', false);
$deleteOnDay = (int) $board->getConfig('epheDeleteThreadDays', false);
// x on page (meaning the thread has fallen to this page)
$sageOnPage = (int) $board->getConfig('epheSageThreadPage', false);
$lockOnPage = (int) $board->getConfig('epheLockThreadPage', false);
$deleteOnPage = (int) $board->getConfig('epheDeleteThreadPage', false);
// Don't do anything unless we have to.
if ($sageOnDay || $lockOnDay || $deleteOnDay || $sageOnPage || $lockOnPage || $deleteOnPage) {
$this->comment(" Pruning /{$board->board_uri}/...");
// Modify threads based on these settings.
foreach ($board->threads as $threadIndex => $thread) {
$threadPage = (int) (floor($threadIndex / $threadsPerPage) + 1);
$modified = false;
$replyLast = clone $thread->reply_last;
// x on day since last reply
// This is asking if:
// 1) The setting is set ($x > 0)
// 2) the last reply date + the number of days permitted by each setting is < now.
if (!$thread->isBumplocked() && ($sageOnDay > 0 && $replyLast->addDays($sageOnDay)->isPast() || $sageOnPage > 0 && $sageOnPage <= $threadPage)) {
$this->comment(" Bumplocking #{$thread->board_id}");
$modified = true;
$thread->bumplocked_at = $time;
}
if (!$thread->isLocked() && ($lockOnDay > 0 && $replyLast->addDays($lockOnDay)->isPast() || $lockOnPage > 0 && $lockOnPage <= $threadPage)) {
$this->comment(" Locking #{$thread->board_id}");
$modified = true;
$thread->locked_at = $time;
}
if (!$thread->isDeleted() && ($deleteOnDay > 0 && $replyLast->addDays($sageOnDay)->isPast() || $deleteOnPage > 0 && $deleteOnPage <= $threadPage)) {
$this->comment(" Deleting #{$thread->board_id}");
$modified = true;
$thread->deleted_at = $time;
}
if ($modified) {
$threadsToSave[] = $thread;
}
}
if (count($threadsToSave)) {
// Save all at once.
$board->threads()->saveMany($threadsToSave);
} else {
$this->comment(" Nothing to do.");
}
}
}