/** * Returns an array with a list of values and information about where they were obtained from * * @param array $billing_category_ids */ function getBillingAmounts($billing_categories = null) { if (!$billing_categories) { $billing_categories = BillingCategories::findAll(); } if ($billing_categories && count($billing_categories) > 0) { $result = array(); $billing_category_ids = array(); foreach ($billing_categories as $category) { $billing_category_ids[] = $category->getId(); } $wsBillingCategories = WorkspaceBillings::findAll(array('conditions' => 'project_id = ' . $this->getId() . ' and billing_id in (' . implode(',', $billing_category_ids) . ')')); if ($wsBillingCategories) { foreach ($wsBillingCategories as $wsCategory) { for ($i = 0; $i < count($billing_categories); $i++) { if ($billing_categories[$i]->getId() == $wsCategory->getBillingId()) { $result[] = array('category' => $billing_categories[$i], 'value' => $wsCategory->getValue(), 'origin' => $this->getId()); array_splice($billing_categories, $i, 1); array_splice($billing_category_ids, $i, 1); break; } } } } if (count($billing_categories) > 0) { if ($this->getParentWorkspace() instanceof Project) { $resultToConcat = $this->getParentWorkspace()->getBillingAmounts($billing_categories); foreach ($resultToConcat as $resultValue) { $result[] = array('category' => $resultValue['category'], 'value' => $resultValue['value'], 'origin' => $resultValue['origin'] == 'default' ? 'default' : 'inherited'); } } else { foreach ($billing_categories as $category) { $result[] = array('category' => $category, 'value' => $category->getDefaultValue(), 'origin' => 'default'); } } } return $result; } else { return null; } }