Ejemplo n.º 1
0
 public function onGet()
 {
     $filter = Log\QueryFilter::create($this->getParameters());
     $condition = $filter->getCondition('log');
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     // build data structure
     $fromDate = $filter->getFrom();
     $toDate = $filter->getTo();
     $diff = $toDate->getTimestamp() - $fromDate->getTimestamp();
     $data = [];
     $labels = [];
     while ($fromDate <= $toDate) {
         $data[$fromDate->format('Y-m-d')] = 0;
         $labels[] = $fromDate->format($diff < 2419200 ? 'D' : 'Y-m-d');
         $fromDate->add(new \DateInterval('P1D'));
     }
     // fill values
     $sql = '  SELECT COUNT(log.id) AS count,
                      DATE(log.date) AS date
                 FROM fusio_log log
                WHERE ' . $expression . '
             GROUP BY DATE(log.date)';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     foreach ($result as $row) {
         $data[$row['date']] = (int) $row['count'];
     }
     $this->setBody(array('labels' => $labels, 'data' => [array_values($data)], 'series' => ['Requests']));
 }
Ejemplo n.º 2
0
 /**
  * Returns the GET response
  *
  * @param \PSX\Api\Version $version
  * @return array|\PSX\Data\RecordInterface
  */
 protected function doGet(Version $version)
 {
     $startIndex = $this->getParameter('startIndex', Validate::TYPE_INTEGER) ?: null;
     $filter = Log\QueryFilter::create($this->getParameters());
     $condition = $filter->getCondition();
     $table = $this->tableManager->getTable('Fusio\\Backend\\Table\\Log');
     $table->setRestrictedFields(['header', 'body']);
     return array('totalItems' => $table->getCount($condition), 'startIndex' => $startIndex, 'entry' => $table->getAll($startIndex, null, 'id', Sql::SORT_DESC, $condition));
 }
Ejemplo n.º 3
0
 public function onGet()
 {
     $filter = Log\QueryFilter::create($this->getParameters());
     $condition = $filter->getCondition('log');
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     // get the most used apps and build data structure
     $sql = '  SELECT log.appId
                 FROM fusio_log log
                WHERE ' . $expression . '
                  AND log.appId IS NOT NULL
             GROUP BY log.appId
             ORDER BY COUNT(log.appId) DESC
                LIMIT 6';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     $appIds = array();
     $data = [];
     $series = [];
     foreach ($result as $row) {
         $appIds[] = $row['appId'];
         $data[$row['appId']] = [];
         $series[$row['appId']] = null;
         $fromDate = clone $filter->getFrom();
         $toDate = clone $filter->getTo();
         while ($fromDate <= $toDate) {
             $data[$row['appId']][$fromDate->format('Y-m-d')] = 0;
             $fromDate->add(new \DateInterval('P1D'));
         }
     }
     if (!empty($appIds)) {
         $condition->in('log.appId', $appIds);
     }
     // fill data with values
     $expression = $condition->getExpression($this->connection->getDatabasePlatform());
     $sql = '    SELECT COUNT(log.id) AS count,
                        log.appId,
                        app.name,
                        DATE(log.date) AS date
                   FROM fusio_log log
             INNER JOIN fusio_app app
                     ON log.appId = app.id
                  WHERE ' . $expression . '
               GROUP BY DATE(log.date), log.appId';
     $result = $this->connection->fetchAll($sql, $condition->getValues());
     foreach ($result as $row) {
         $series[$row['appId']] = $row['name'];
         $data[$row['appId']][$row['date']] = (int) $row['count'];
     }
     // build labels
     $fromDate = clone $filter->getFrom();
     $toDate = clone $filter->getTo();
     $diff = $toDate->getTimestamp() - $fromDate->getTimestamp();
     $labels = [];
     while ($fromDate <= $toDate) {
         $labels[] = $fromDate->format($diff < 2419200 ? 'D' : 'Y-m-d');
         $fromDate->add(new \DateInterval('P1D'));
     }
     // clean data structure
     $values = [];
     foreach ($data as $row) {
         $values[] = array_values($row);
     }
     $this->setBody(array('labels' => $labels, 'data' => array_values($values), 'series' => array_values($series)));
 }