csv_writer.class.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Glossay csv writer class definition
  5. * @package chamilo.glossary
  6. */
  7. /**
  8. * Init
  9. */
  10. namespace Glossary;
  11. use Chamilo;
  12. /**
  13. * Write glossary entries to a file in CSV format.
  14. *
  15. * @license /licence.txt
  16. * @author Laurent Opprecht <laurent@opprecht.info>
  17. */
  18. class CsvWriter extends \CsvObjectWriter
  19. {
  20. /**
  21. *
  22. * @return \Glossary\CsvWriter
  23. */
  24. public static function create($path = '', $delimiter = ';', $enclosure = '"')
  25. {
  26. return new self($path, $delimiter, $enclosure);
  27. }
  28. protected $path = '';
  29. function __construct($path = '', $delimiter = ';', $enclosure = '"')
  30. {
  31. $path = $path ? $path : Chamilo::temp_file();
  32. $this->path = $path;
  33. $stream = new \FileWriter($path);
  34. $map = array(
  35. 'name' => 'name',
  36. 'description' => 'description'
  37. );
  38. parent::__construct($stream, $map, $delimiter, $enclosure);
  39. }
  40. function get_path()
  41. {
  42. return $this->path;
  43. }
  44. }