public static function instance() { if (!self::$instance) { self::$instance = new Helper_CSV(); } return self::$instance; }
public function action_csv() { $this->auto_render = FALSE; $id = (int) Request::current()->param('id'); $orm_form = ORM::factory('form', $id); if (!$orm_form->loaded()) { throw new HTTP_Exception_404(); } $fields = array_flip(array('id', 'email', 'text', 'created')); $labels = Arr::overwrite($fields, $orm_form->responses->labels()); $list = $orm_form->responses->find_all(); $queue = array(); Database::instance()->set_charset('cp1251'); foreach ($list as $_orm) { $_values = array_map('Helper_CSV::escape', $_orm->as_array()); $_values = array_intersect_key($_values, $fields); $_item = array_combine($labels, $_values); $queue[] = array_filter($_item); } Database::instance()->set_charset('utf8'); Helper_CSV::instance()->send($queue); }