コード例 #1
0
ファイル: Budgets.php プロジェクト: scalr/scalr
 /**
  * Gets budget data for specified CC and period
  *
  * @param   CostCentreEntity $cc
  * @param   QuarterPeriod    $period
  * @return  array Returns budget data
  */
 private function getCostCenterData(CostCentreEntity $cc, QuarterPeriod $period)
 {
     $ret = array('ccId' => $cc->ccId, 'name' => $cc->name, 'billingCode' => $cc->getProperty(CostCentrePropertyEntity::NAME_BILLING_CODE), 'description' => $cc->getProperty(CostCentrePropertyEntity::NAME_DESCRIPTION));
     $budget = $this->getBudgetUsedPercentage(['ccId' => $cc->ccId, 'period' => $period, 'getRelationDependentBudget' => true]);
     foreach (['budget', 'budgetRemain', 'budgetRemainPct', 'budgetSpent', 'budgetSpentPct', 'budgetOverspend', 'budgetOverspendPct', 'relationDependentBudget'] as $field) {
         $ret[$field] = $budget[$field];
     }
     return $ret;
 }
コード例 #2
0
ファイル: Costcenters.php プロジェクト: mheydt/scalr
 /**
  * Gets cost centre properties and parameters
  *
  * @param   CostCentreEntity $cc          Cost centre entity
  * @param   string           $calculate   optional Whether response should be adjusted with cost usage data
  * @return  array Returns cost centre properties and parameters
  */
 private function getCostCenterData(CostCentreEntity $cc, $calculate = false)
 {
     $ret = array('ccId' => $cc->ccId, 'name' => $cc->name, 'billingCode' => $cc->getProperty(CostCentrePropertyEntity::NAME_BILLING_CODE), 'description' => $cc->getProperty(CostCentrePropertyEntity::NAME_DESCRIPTION), 'leadEmail' => $cc->getProperty(CostCentrePropertyEntity::NAME_LEAD_EMAIL), 'locked' => $cc->getProperty(CostCentrePropertyEntity::NAME_LOCKED) ? 1 : 0, 'created' => $cc->created->format('Y-m-d'), 'createdByEmail' => $cc->createdByEmail, 'archived' => $cc->archived, 'envCount' => count($cc->getEnvironmentsList()), 'projectsCount' => count($cc->getProjects()));
     if ($calculate) {
         $iterator = ChartPeriodIterator::create('month', gmdate('Y-m-01'), null, 'UTC');
         $usage = $this->getContainer()->analytics->usage->get(['ccId' => $cc->ccId], $iterator->getStart(), $iterator->getEnd());
         //It calculates usage for previous period same days
         $prevusage = $this->getContainer()->analytics->usage->get(['ccId' => $cc->ccId], $iterator->getPreviousStart(), $iterator->getPreviousEnd());
         $ret = $this->getWrappedUsageData(['ccId' => $cc->ccId, 'iterator' => $iterator, 'usage' => $usage['cost'], 'prevusage' => $prevusage['cost']]) + $ret;
     }
     return $ret;
 }