/** * Save a chartconfig entity to the database * * @param ChartConfig $config * @return boolean */ public function save(ChartConfig $config) { $id = $config->getId(); if (!empty($id)) { $query = $this->db->prepareQuery('UPDATE *PREFIX*uc_chartconfig SET created = ?, username = ?, charttype = ?, chartprovider = ?, metadata = ? WHERE id = ?'); $query->execute(array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider(), $config->getMetaData(), $config->getId())); } else { $query = $this->db->prepareQuery('INSERT INTO *PREFIX*uc_chartconfig(created, username, charttype, chartprovider, metadata) VALUES (?,?,?,?,?)'); $query->execute(array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider(), $config->getMetaData())); } return true; }
/** * Save a chartconfig entity to the database * * @param ChartConfig $config */ public function save(ChartConfig $config) { $query = $this->db->prepareQuery('INSERT INTO oc_uc_chartconfig(created, username, charttype, chartprovider) VALUES (?,?,?,?)'); $query->execute(Array($config->getDate()->format('Y-m-d H:i:s'), $config->getUsername(), $config->getChartType(), $config->getChartProvider())); }
public function testGetChartProvider() { $this->assertEquals('c3js', $this->chartConfig->getChartProvider()); }
/** * @param ChartConfig $config * @return mixed * @throws \OCA\ocUsageCharts\Exception\ChartServiceException */ public function getChartByConfig(ChartConfig $config) { $adapter = '\OCA\ocUsageCharts\ChartType\\' . $config->getChartProvider() . '\Adapters\\' . $config->getChartType() . 'Adapter'; if ( !class_exists($adapter) ) { throw new ChartServiceException("Adapter for " . $config->getChartType() . ' does not exist.'); } $chartAdapter = new $adapter($config); if ( !in_array($config->getChartProvider(), $this->isLoaded) ) { $chartAdapter->loadFrontend(); $this->isLoaded[] = $config->getChartProvider(); } return $chartAdapter; }
/** * @TODO refactor to proper code * * @param ChartConfig $config * @return ChartTypeAdapterInterface * * @throws \OCA\ocUsageCharts\Exception\StorageUsageRepositoryException */ public function getUsage(ChartConfig $config) { switch($config->getChartType()) { default: case 'StorageUsageLastMonth': $created = new \DateTime("-1 month"); if ( $this->isAdminUser() ) { $data = $this->findAllAfterCreated($created); } else { $data = $this->findAfterCreated($config->getUsername(), $created); $data = array($config->getUsername() => $data); } break; case 'StorageUsagePerMonth': //@TODO don't need to get everything for one user... // Performance and such $data = $this->findAllPerMonth(); if ( !$this->isAdminUser() ) { $data = array($config->getUsername() => $data[$config->getUsername()]); } break; case 'StorageUsageCurrent': $new = array(); $storageInfo = \OC_Helper::getStorageInfo('/'); $free = ceil($storageInfo['free'] / 1024 / 1024); if ( $this->isAdminUser() ) { $data = $this->findAll(1); foreach($data as $username => $items) { foreach($items as $item) { $new[$username] = ceil($item->getUsage() / 1024 / 1024); } } $new['free'] = $free; $data = $new; } else { $free = ceil($storageInfo['free'] / 1024 / 1024); $used = ceil($storageInfo['used'] / 1024 / 1024); $data = array( 'used' => $used, 'free' => $free ); } break; } // If an adapter has been defined, format the data, else just return data parsed by the system $adapter = '\OCA\ocUsageCharts\ChartType\\' . $config->getChartProvider() . '\Adapters\\' . $config->getChartType() . 'Adapter'; if ( class_exists($adapter) ) { $chartAdapter = new $adapter($config); return $chartAdapter->formatData($data); } return $data; }