Exemplo n.º 1
0
 function stats()
 {
     $this->validateRights([USER_ADMIN]);
     if (isset($_REQUEST['top_articles'])) {
         if ($t = $this->db->fetch('SELECT views FROM articles ORDER BY views DESC LIMIT 5')) {
             $v = [0];
             foreach ($t as $a) {
                 $v[] = $a['views'];
             }
             unset($v[0]);
             $this->data['image'] = new GDImage(NULL, new Size(800, 500));
             $g = new BarChart(new Boundary(0, 0, $this->data['image']->size()->width, $this->data['image']->size()->height));
             $g->depth(15);
             $g->background(new Color(255, 144, 130, 127));
             $g->values(['bgcolors' => [new Color(255, 102, 91), new Color(50, 255, 0), new Color(63, 168, 255), new Color(255, 220, 22), new Color(255, 112, 238)], 'labels' => TRUE, 'thickness' => 3]);
             $g->data($v);
             $g->title(['text' => 'Топ 5 публикаций', 'color' => new Color(255, 255, 255), 'font' => new Font(PATH_ROOT . '/css/fonts/OpenSans-Bold.ttf', 14), 'margin' => ['top' => 0, 'bottom' => 15]]);
             $g->axis(['font_x' => new Font(PATH_ROOT . '/css/fonts/OpenSans-Regular.ttf', 8), 'font_y' => new Font(PATH_ROOT . '/css/fonts/OpenSans-Regular.ttf', 8), 'bgcolor' => new Color(255, 255, 255, 100), 'fgcolor' => new Color(255, 255, 255), 'y_lines' => TRUE]);
             $g->max(50);
             $g->min(0);
             $g->draw($this->data['image']->getHandle());
         }
         $this->data['subaction'] = 'image';
     } else {
         if (isset($_REQUEST['storage_usage'])) {
             $this->validateArgs($_REQUEST, [['start_date', 'string'], ['end_date', 'string'], ['resolution', 'numeric']]);
             $s = $_REQUEST['start_date'];
             $e = $_REQUEST['end_date'];
             $r = $_REQUEST['resolution'];
             $v = [];
             if ($t = $this->db->call('show_storage_usage', [$s, $e, $r])) {
                 $b = $t[0]['balance'];
                 for ($i = 1; $i < count($t); $i++) {
                     if ($r == 1) {
                         $v[sprintf('%02d.%02d.%04d', $t[$i]['day'], $t[$i]['month'], $t[$i]['year'])] = round(($b += $t[$i]['balance']) / 1024 / 1024, 2);
                     } else {
                         if ($r == 2) {
                             $v[sprintf('%02d.%04d', $t[$i]['month'], $t[$i]['year'])] = round(($b += $t[$i]['balance']) / 1024 / 1024, 2);
                         }
                     }
                 }
                 $this->data['image'] = new GDImage(NULL, new Size(800, 500));
                 $g = new LineChart(new Boundary(0, 0, $this->data['image']->size()->width, $this->data['image']->size()->height));
                 $g->depth(15);
                 $g->background(new Color(255, 144, 130, 127));
                 $g->values(['bgcolors' => [new Color(0, 255, 0)], 'fgcolors' => [new Color(255, 255, 255)], 'font' => new Font(PATH_ROOT . '/css/fonts/OpenSans-Regular.ttf', 10), 'labels' => TRUE, 'thickness' => 2]);
                 $g->data($v);
                 $g->title(['text' => 'Использование хранилища', 'color' => new Color(255, 255, 255), 'font' => new Font(PATH_ROOT . '/css/fonts/OpenSans-Bold.ttf', 14), 'margin' => ['top' => 0, 'bottom' => 15]]);
                 $g->axis(['font_x' => new Font(PATH_ROOT . '/css/fonts/OpenSans-Regular.ttf', 8, 90), 'font_y' => new Font(PATH_ROOT . '/css/fonts/OpenSans-Regular.ttf', 8), 'bgcolor' => new Color(255, 255, 255, 100), 'fgcolor' => new Color(255, 255, 255), 'y_lines' => TRUE]);
                 $g->draw($this->data['image']->getHandle());
             }
             $this->data['subaction'] = 'image';
         } else {
             if ($t = $this->db->fetch('SELECT COUNT(*) AS total_users FROM users')) {
                 $this->data['stats']['total_users'] = $t[0]['total_users'];
             }
             if ($t = $this->db->fetch('SELECT COUNT(*) AS total_admins FROM users WHERE is_admin=1')) {
                 $this->data['stats']['total_admins'] = $t[0]['total_admins'];
             }
             if ($t = $this->db->fetch('SELECT id, login, DATE_FORMAT(reg_date, \'%e.%m.%Y %H:%i\') AS reg_date FROM users WHERE reg_date=(SELECT MAX(reg_date) FROM users)')) {
                 $this->data['stats']['last_user'] = $t[0];
             }
             if ($t = $this->db->fetch('SELECT SUM(file_size) AS total_size FROM storage')) {
                 $this->data['stats']['storage_usage'] = round($t[0]['total_size'] / 1024 / 1024, 1) . ($this->app->config['storage']['max_size'] != -1 ? ' из ' . $this->app->config['storage']['max_size'] : '') . ' МБ';
             }
             if ($t = $this->db->fetch('SELECT COUNT(*) AS total_sections FROM sections')) {
                 $this->data['stats']['total_sections'] = $t[0]['total_sections'];
             }
             if ($t = $this->db->fetch('SELECT COUNT(*) AS total_articles FROM articles')) {
                 $this->data['stats']['total_articles'] = $t[0]['total_articles'];
             }
             if ($t = $this->db->fetch('SELECT COUNT(*) AS total_unverified_articles FROM articles WHERE verifier_id IS NULL')) {
                 $this->data['stats']['total_unverified_articles'] = $t[0]['total_unverified_articles'];
             }
             if ($t = $this->db->fetch('SELECT COUNT(*) AS total_comments FROM comments')) {
                 $this->data['stats']['total_comments'] = $t[0]['total_comments'];
             }
             if ($t = $this->db->fetch('SELECT articles.id AS id, articles.title AS title, data_folder, users.id AS user_id, login FROM articles INNER JOIN sections ON articles.section_id=sections.id INNER JOIN users ON author_id=users.id ORDER BY views DESC LIMIT 5')) {
                 foreach ($t as &$a) {
                     $a['href'] = $this->app->config['path']['section'] . $a['data_folder'] . '/' . $a['id'] . '/';
                 }
                 unset($a);
                 $this->data['stats']['top_articles'] = $t;
             }
         }
     }
 }