/** * @param array $torrent * @param string $fieldName * @param string $transmissionHost * @param int $lastDays * @return int */ public function getTorrentSum(array $torrent, $fieldName, $transmissionHost = '', $lastDays = 0) { $where = []; if (isset($torrent[Torrent\Get::NAME])) { $where[] = "torrent_name = '" . $torrent[Torrent\Get::NAME] . "'"; } if ($transmissionHost) { $where[] = "host = '" . $transmissionHost . "'"; } if ($lastDays) { $fromTimestamp = strtotime('-' . $lastDays . ' days'); $fromDate = date('c', $fromTimestamp); $where[] = "time >= '{$fromDate}'"; } $results = $this->getDatabase()->getQueryBuilder()->from('uploaded')->select("sum({$fieldName}) as {$fieldName}")->where($where)->getResultSet()->getPoints(); $this->log('debug', $this->influxDb->getLastQuery()); if (!empty($results)) { return $results[0][$fieldName]; } return 0; }