public function export_csv() { $c_id = Request::get_c_id(); $session_id = Request::get_session_id(); $root = (object) array(); $root->c_id = $c_id; $root->id = 0; $root->session_id = $session_id; $links = LinkRepository::instance()->find_by_category($root); $repo = LinkCategory::repository(); $categories = $repo->find_by_course($c_id, $session_id); $temp = Chamilo::temp_file(); $writer = \CsvWriter::create(new \FileWriter($temp)); $headers = array(); $headers[] = 'url'; $headers[] = 'title'; $headers[] = 'description'; $headers[] = 'target'; $headers[] = 'category_title'; $headers[] = 'category_description'; $writer->put($headers); foreach ($links as $link) { $data = array(); $data[] = $link->url; $data[] = $link->title; $data[] = $link->description; $data[] = $link->target; $data[] = ''; $data[] = ''; $writer->put($data); } foreach ($categories as $category) { foreach ($category->links as $link) { $data = array(); $data[] = $link->url; $data[] = $link->title; $data[] = $link->description; $data[] = $link->target; $data[] = $category->category_title; $data[] = $category->description; $writer->put($data); } } \DocumentManager::file_send_for_download($temp, true, get_lang('Links') . '.csv'); }
/** * * @param string $where * @return array */ public function find($where) { $result = array(); $table = Database::get_course_table(TABLE_LINK_CATEGORY); $where = $where ? "WHERE {$where}" : ''; $sql = "SELECT * FROM {$table} {$where} ORDER BY display_order DESC"; $rs = Database::query($sql); while ($data = Database::fetch_object($rs)) { $result[] = LinkCategory::create($data); } return $result; }