/** * Return a CURRENT storage usage for a user * * @return StorageUsage */ public function getChartUsageForUpdate() { $userName = $this->chartConfig->getUsername(); $created = new \DateTime(); $created->setTime(0, 0, 0); $results = $this->repository->findAfterCreated($userName, $created); // The cron has already ran today, therefor ignoring a current update, only update once a day. if (count($results) == 0) { return new StorageUsage(new \Datetime(), $this->getStorageUsageFromCacheByUserName($userName), $userName); } }
/** * 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; }
/** * Return the chart data you want to return based on the ChartConfig * * @return array */ public function getChartUsage() { $return = array(); if ($this->user->isAdminUser($this->user->getSignedInUsername())) { $users = $this->users->getSystemUsers(); foreach ($users as $username) { $return[$username] = $this->getCollectionByUsername($username); } } else { $username = $this->chartConfig->getUsername(); $return[$username] = $this->getCollectionByUsername($username); } return $return; }
/** * Return a CURRENT storage usage for a user * * @return StorageUsage */ public function getChartUsageForUpdate() { $userName = $this->chartConfig->getUsername(); $usage = $this->storage->getStorageUsage($userName); $maximumUsage = $this->storage->getMaximumStorageUsage($userName); return new StorageUsage(new \Datetime(), $usage, $userName, $maximumUsage); }
/** * Return the chart data you want to return based on the ChartConfig * * @param User $user * @param ActivityUsageRepository|StorageUsageRepository $repository * @param ChartConfig $chartConfig * @return mixed */ public function getChartUsage(User $user, $repository, ChartConfig $chartConfig) { if ($user->isAdminUser($user->getSignedInUsername())) { $data = $repository->findAllPerMonth(); } else { $data = $repository->findAllPerMonth($chartConfig->getUsername()); } return $data; }
/** * 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 testGetUsername() { $this->assertEquals('test1', $this->chartConfig->getUsername()); }
/** * @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; }