/** * Convert the column types between generic yentu types and native database * types on the tables * * @param array $tables * @param DatabaseManipulator $manipulator * @return array */ private function convertColumnTypes($tables, $manipulator) { foreach ($tables as $i => $table) { foreach ($table['columns'] as $j => $column) { $tables[$i]['columns'][$j]['type'] = $manipulator->convertTypes($column['type'], DatabaseManipulator::CONVERT_TO_YENTU, $column['length']); } } return $tables; }
public static function associateParent($parent, $initialise_em = true, $initialise_sm = true) { $ASDC_locations = array(EXTENSIONS . '/asdc/lib/class.asdc.php', WORKSPACE . "/api/class.asdc.php"); // Plug in in the ASDC class foreach ($ASDC_locations as $location) { if (file_exists($location)) { require_once $location; break; } } self::$ASDC = ASDCLoader::instance(); // Standard symphony init if ($initialise_sm) { self::$sm = new SectionManager($parent); } if ($initialise_em) { self::$em = new EntryManager($parent); } }
public function export($post) { $sectionManager = new SectionManager($this->_Parent); $section = $sectionManager->fetch($post['target']); /* Fetch ** ------------ ** Fetch the entries data using the DM, optionally using ** a filter. */ if ($post['linked-section'] and $post['linked-entry']) { $filter = array($post['linked-section'] => $post['linked-entry']); } else { $filter = null; } require_once EXTENSIONS . '/databasemanipulator/lib/class.databasemanipulator.php'; DatabaseManipulator::associateParent($this->_Parent); $entries = DatabaseManipulator::getEntries($section->get('id'), '*', $filter); $fields_value = $header = $data = array(); /* CSV Header ** -------------- ** Build the header from the fields */ $header_entry = array_values(current($entries)); $output = $this->_driver->str_putcsv(array_keys($header_entry[1])); /* Data ** ----------- ** Get the field scheme, then loop through our data applying the field's prepareTableValue for ** for output. If the field contains a relationship, use resolveLinks to implode the linked values */ foreach ($section->fetchFields() as $field) { $fields_value[$field->get('id')] = $field; } $fields = end($section); foreach ($entries as $k => $v) { foreach ($v['fields'] as $name => $entry) { $f_id = $fields->fetchFieldIDFromElementName($name, $section->get('id')); if (isset($entry)) { if (array_key_exists("linked_entry_id", $entry) or array_key_exists("relation_id", $entry)) { $data[$k][] = $this->resolveLinks(current($entry)); } else { $value = $fields_value[$f_id]->prepareTableValue($entry); ## Dirty hack way to show HREF's in the CSV while stripping away the rest if (strpos($value, "href") === FALSE) { $data[$k][] = preg_replace('/(<[^>]+>)/', '', $value); } else { $pieces = explode('"', $value); $data[$k][] = $pieces[1]; } } } else { ## No value, so null it otherwise our columns won't match up $data[$k][] = null; } } } $output .= $this->_driver->str_putcsv($data); ## We got our CSV, so lets output it, but we'll exit, because we don't want any Symphony output header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename= ' . $this->getFileName($post['target'])); echo $output; exit; }
public function rollbackTransaction() { // Don't delete if there are no errors if (!$this->rollback) { return; } DatabaseManipulator::deleteEntries($this->created_entries); }