function updateDefaults($data, $accountId = '') { if (!$accountId) { $identity = Zend_Auth::getInstance()->getIdentity(); $accountId = $identity->account_id; } $model = new Model_Wep(); //Update default values $dfg = new Model_DefaultFieldValues(); //User existing default values setting. $defaultObj = $dfg->getDefaultObjByOrganisation($accountId); $fieldString = $this->prepareDefaultFieldValues($data, $defaultObj); $defaultValues['id'] = $model->getIdByField('default_field_values', 'account_id', $accountId); $defaultValues['object'] = $fieldString; $defaultValuesId = $model->updateRowsToTable('default_field_values', $defaultValues); //Update Default Fields if (!empty($data['default_fields'])) { $defaultFieldGroupObj = new Iati_WEP_AccountDisplayFieldGroup(); foreach ($data['default_fields'] as $eachField) { print $eachField; $defaultFieldGroupObj->setProperties($eachField); } $fieldString = serialize($defaultFieldGroupObj); $defaultFields['id'] = $model->getIdByField('default_field_groups', 'account_id', $accountId); $defaultFields['object'] = $fieldString; $defaultFieldId = $model->updateRowsToTable('default_field_groups', $defaultFields); } }
public function generateXml($name, $ids = array()) { $this->setChildrenIds($ids); if ($name == "Activity") { $this->xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><iati-activities><!-- Generated By AidStream --></iati-activities>'); $identity = Zend_Auth::getInstance()->getIdentity(); $model = new Model_DefaultFieldValues(); $linkedDataDefault = $model->getByOrganisationId($identity->account_id, 'linked_data_default'); if ($linkedDataDefault) { $this->xml->addAttribute('linked_data_default', $linkedDataDefault); } } else { if (strtolower($name) == 'organisation') { $this->xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><iati-organisations><!-- Generated By AidStream --></iati-organisations>'); } else { $this->xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><' . strtolower($name) . 's><!-- Generated By AidStream --></' . strtolower($name) . 's>'); } } $this->xml->addAttribute('generated-datetime', gmdate('c')); $this->xml->addAttribute('version', self::SCHEMA_VERSION); if (!empty($this->childrenIds)) { foreach ($this->childrenIds as $childId) { $childElementClass = "Iati_Aidstream_Element_" . ucfirst($name); $childElement = new $childElementClass(); $data = $childElement->fetchData($childId); $childElement->setData($data[$childElement->getClassName()]); $childElement->getXml($this->xml); } } $prettyXml = $this->formatXml($this->xml); return $prettyXml; }
public function prepareTransactionCsvData($transactionData) { if (empty($transactionData)) { return; } $csvData = array(); $identity = Zend_Auth::getInstance()->getIdentity(); $accountId = $identity->account_id; $model = new Model_DefaultFieldValues(); $defaults = $model->getByOrganisationId($accountId); $currency = $defaults['currency'] ? Iati_Core_Codelist::getCodeByAttrib('Transaction', 'currency', $defaults['currency']) : ''; $element = new Iati_Aidstream_Element_Activity_Transaction(); $element->setIsMultiple(false); $identifierText = array(); $titleText = array(); foreach ($transactionData as $transactionElementData) { $activityId = $transactionElementData['activity_id']; if (!$identifierText[$activityId]) { // fetch identifier for activity Id $identifierEle = new Iati_Aidstream_Element_Activity_IatiIdentifier(); $identifierData = $identifierEle->fetchData($activityId, true); $identifierText[$activityId] = $identifierData['text']; } if (!$titleText[$activityId]) { // fetch title for activity Id $titleEle = new Iati_Aidstream_Element_Activity_Title(); $titleData = $titleEle->fetchData($activityId, true); $titleText[$activityId] = $titleData[0]['text']; } $data = $this->prepareCsvDataForElement($element, $transactionElementData, false); $extras = array('Activity_Identifier' => $identifierText[$activityId], 'Activity_Title' => $titleText[$activityId], 'Default_currency' => $currency); $data = array_merge($extras, $data); // Add identifier and title to csv data $csvData[] = $data; } return $csvData; }