123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- namespace ForkBB\Models\Stats;
- use ForkBB\Models\Model as ParentModel;
- use PDO;
- use RuntimeException;
- class Model extends ParentModel
- {
- /**
- * Загружает статистику из кеша/БД
- */
- public function init(): Model
- {
- $list = $this->c->Cache->get('stats');
- if (! \is_array($list)) {
- $list = $this->c->users->stats();
- if (true !== $this->c->Cache->set('stats', $list)) {
- throw new RuntimeException('Unable to write value to cache - stats');
- }
- }
- $this->userTotal = $list['total'];
- $this->userLast = $list['last'];
- $query = 'SELECT SUM(f.num_topics), SUM(f.num_posts)
- FROM ::forums AS f';
- list($this->topicTotal, $this->postTotal) = $this->c->DB->query($query)->fetch(PDO::FETCH_NUM);
- return $this;
- }
- /**
- * Сбрасывает кеш статистики
- */
- public function reset(): Model
- {
- if (true !== $this->c->Cache->delete('stats')) {
- throw new RuntimeException('Unable to remove key from cache - stats');
- }
- return $this;
- }
- }
|