/** *Loads in the requeted data from the relationship * @returns boolean True on success */ protected function loadData($as_iterator = true) { $fields = $this->getFields(); $ordering = $this->getOrdering(); I2CE::longExecution(array("max_execution_time" => 1800)); if (!$as_iterator) { $this->data = $this->formRelationship->getFormData($this->primObj->getName(), $this->primObj->getId(), $fields, $ordering, false); if (!is_array($data)) { I2CE::raiseError("No Data"); return false; } } else { $data = $this->formRelationship->getFormData($this->primObj->getName(), $this->primObj->getId(), $fields, $ordering, true); $this->data = $this->sortIterator($data); } return true; }
protected function setHeaderVars($segment) { $rel_base = '/modules/CustomReports/relationships'; if (array_key_exists('relationship_base', $this->args) && is_scalar($this->args['relationship_base'])) { $rel_base = $this->args['relationship_base']; } $use_cache = I2CE_ModuleFactory::instance()->isEnabled('CachedForms'); if (array_key_exists('use_cache', $this->args)) { $use_cache = $this->args['use_cache']; } if ($use_cache) { $cache_callback = array('I2CE_CachedForm', 'getCachedTableName'); } else { $cache_callback = null; } try { if (!array_key_exists('header_relationship', $this->args) || !is_string($this->args['header_relationship']) || strlen($this->args['header_relationship']) == 0 || !($formRelationship = new I2CE_FormRelationship($this->args['header_relationship'], $rel_base, $cache_callback)) instanceof I2CE_FormRelationship || $formRelationship->getPrimaryForm() != $this->primObj->getName()) { return; } $fields = $this->getFields(); $data = $formRelationship->getFormData($this->primObj->getName(), $this->primObj->getId(), $fields, array(), true); $row = 0; foreach ($data as $formfields) { if (!$this->setData($segment, $row, $formfields, $formRelationship)) { I2CE::raiseError("Error setting data for row: {$row}"); return false; } break; //only do one row } } catch (Exception $e) { } }
public function streamRaw($ids = false, $last_modified = -1, $headers = false, $pre = '', $post = '', $wrap = true) { $ff = I2CE_FormFactory::instance(); $form_name = $this->relObj->getPrimaryForm(); I2CE::raiseError("Primary form = {$form_name}"); if (!is_array($ids)) { $ids = $ff->getRecords($form_name, $last_modified); } else { $t_ids = $ids; $ids = array(); foreach ($t_ids as $id) { list($form, $fid) = array_pad(explode("|", $id, 2), 2, ''); if ($fid != '' and $fid != '0') { $ids[] = $fid; } } } try { $formRelationship = new I2CE_FormRelationship($this->relationship); } catch (Exception $e) { I2CE::raiseError("Could not create form relationship : " . $this->args['relationship']); return false; } $formRelationship->useRawFields(); $formfields = array(); foreach ($formRelationship->getFormNames() as $formName) { if (!($form = $formRelationship->getForm($formName)) || !($formObj = $ff->createContainer(array($form, 0))) instanceof I2CE_Form) { continue; } $formfields[$formName] = array(); foreach ($formObj->getFieldNames() as $fieldName) { if (!($fieldObj = $formObj->getField($fieldName)) instanceof I2CE_FormField || !$fieldObj->isInDB()) { continue; } $formfields[$formName][] = $fieldName; } $cachefields = array("created", "last_modified", "parent"); foreach ($cachefields as $cachedfieldName) { $formfields[$formName][] = $cachedfieldName; } } I2CE::longExecution(array("max_execution_time" => 1800)); $results = $this->getCache($ids, $last_modified); if ($errors = I2CE_Dumper::cleanlyEndOutputBuffers()) { I2CE::raiseError("Got errors:\n{$errors}"); } if (array_key_exists('HTTP_HOST', $_SERVER)) { if (!is_array($headers)) { $headers = array('Content-Type: text/xml'); } foreach ($headers as $header) { header($header); } } echo "<?xml version='1.0'?>\n"; flush(); if ($pre) { echo $pre; flush(); } echo "<!-- Contains " . count($ids) . " records -->\n"; flush(); if ($wrap) { echo "<relationshipCollection name='" . $formRelationship->getPrimaryFormName() . "'>\n"; flush(); } $rec = 0; foreach ($ids as $id) { I2CE::longExecution(array("max_execution_time" => 1800)); $doc = new DOMDocument(); $doc->loadXML("<relationship/>"); $node = $doc->documentElement; $formRelationship->getFormData($form_name, $id, $formfields, array(), $node); echo "<!-- Record #: " . $rec . "-->"; echo $doc->saveXML($doc->documentElement) . "\n"; flush(); $rec++; } if ($wrap) { echo "</relationshipCollection>"; flush(); } if ($post) { echo $post; flush(); } flush(); }