Scalr\Stats\CostAnalytics\Entity\ProjectEntity::getCostCenter PHP Method

getCostCenter() public method

Gets parent Cost Center
public getCostCenter ( ) : Scalr\Stats\CostAnalytics\Entity\CostCentreEntity
return Scalr\Stats\CostAnalytics\Entity\CostCentreEntity Returns cost centre entity
    public function getCostCenter()
    {
        if ($this->_cc === null || $this->_cc->ccId != $this->ccId) {
            $this->_cc = CostCentreEntity::findPk($this->ccId);
        }
        return $this->_cc;
    }

Usage Example

Example #1
0
 /**
  * Gets project properties and parameters
  *
  * @param   ProjectEntity    $projectEntity          Project entity
  * @param   string           $calculate   optional Whether response should be adjusted with cost usage data
  * @return  array Returns cost centre properties and parameters
  */
 private function getProjectData(ProjectEntity $projectEntity, $calculate = false)
 {
     $ret = array('ccId' => $projectEntity->ccId, 'ccName' => $projectEntity->getCostCenter() !== null ? $projectEntity->getCostCenter()->name : null, 'projectId' => $projectEntity->projectId, 'name' => $projectEntity->name, 'billingCode' => $projectEntity->getProperty(ProjectPropertyEntity::NAME_BILLING_CODE), 'description' => $projectEntity->getProperty(ProjectPropertyEntity::NAME_DESCRIPTION), 'leadEmail' => $projectEntity->getProperty(ProjectPropertyEntity::NAME_LEAD_EMAIL), 'created' => $projectEntity->created->format('Y-m-d'), 'createdByEmail' => $projectEntity->createdByEmail, 'archived' => $projectEntity->archived, 'farmsCount' => count($projectEntity->getFarmsList()));
     if ($calculate) {
         $iterator = new ChartPeriodIterator('month', gmdate('Y-m-01'), null, 'UTC');
         $usage = $this->getContainer()->analytics->usage->get(['projectId' => $ret['projectId']], $iterator->getStart(), $iterator->getEnd());
         //It calculates usage for previous period same days
         $prevusage = $this->getContainer()->analytics->usage->get(['projectId' => $ret['projectId']], $iterator->getPreviousStart(), $iterator->getPreviousEnd());
         //Calclulates usage for previous whole period
         if ($iterator->getPreviousEnd() != $iterator->getWholePreviousPeriodEnd()) {
             $prevWholePeriodUsage = $this->getContainer()->analytics->usage->get(['projectId' => $ret['projectId']], $iterator->getPreviousStart(), $iterator->getWholePreviousPeriodEnd());
         } else {
             $prevWholePeriodUsage = $prevusage;
         }
         $ret = $this->getWrappedUsageData(['ccId' => $ret['ccId'], 'projectId' => $ret['projectId'], 'iterator' => $iterator, 'usage' => $usage['cost'], 'prevusage' => $prevusage['cost'], 'prevusagewhole' => $prevWholePeriodUsage['cost']]) + $ret;
     }
     return $ret;
 }
All Usage Examples Of Scalr\Stats\CostAnalytics\Entity\ProjectEntity::getCostCenter