dataform.class.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Extends FormValidator with import and export forms.
  5. *
  6. * @author Stijn Konings
  7. *
  8. * @package chamilo.gradebook
  9. */
  10. class DataForm extends FormValidator
  11. {
  12. const TYPE_IMPORT = 1;
  13. const TYPE_EXPORT = 2;
  14. const TYPE_EXPORT_PDF = 3;
  15. /**
  16. * Builds a form containing form items based on a given parameter.
  17. *
  18. * @param int form_type 1=import, 2=export
  19. * @param obj cat_obj the category object
  20. * @param obj res_obj the result object
  21. * @param string form name
  22. * @param method
  23. * @param action
  24. */
  25. public function __construct(
  26. $form_type,
  27. $form_name,
  28. $method = 'post',
  29. $action = null,
  30. $target = '',
  31. $locked_status
  32. ) {
  33. parent:: __construct($form_name, $method, $action, $target);
  34. $this->form_type = $form_type;
  35. if ($this->form_type == self::TYPE_IMPORT) {
  36. $this->build_import_form();
  37. } elseif ($this->form_type == self::TYPE_EXPORT) {
  38. if ($locked_status == 0) {
  39. $this->build_export_form_option(false);
  40. } else {
  41. $this->build_export_form();
  42. }
  43. } elseif ($this->form_type == self::TYPE_EXPORT_PDF) {
  44. $this->build_pdf_export_form();
  45. }
  46. $this->setDefaults();
  47. }
  48. public function display()
  49. {
  50. parent::display();
  51. }
  52. public function setDefaults($defaults = [], $filter = null)
  53. {
  54. parent::setDefaults($defaults, $filter);
  55. }
  56. protected function build_pdf_export_form()
  57. {
  58. $renderer = &$this->defaultRenderer();
  59. $renderer->setCustomElementTemplate('<span>{element}</span>');
  60. $this->addElement('header', get_lang('ChooseOrientation'));
  61. $this->addElement('radio', 'orientation', null, get_lang('Portrait'), 'portrait');
  62. $this->addElement('radio', 'orientation', null, get_lang('Landscape'), 'landscape');
  63. $this->addButtonExport(get_lang('Export'));
  64. $this->setDefaults([
  65. 'orientation' => 'portrait',
  66. ]);
  67. }
  68. protected function build_export_form()
  69. {
  70. $this->addElement('header', get_lang('ChooseFormat'));
  71. $this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
  72. $this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml');
  73. $this->addElement('radio', 'file_type', null, 'PDF (Portable Document Format)', 'pdf');
  74. $this->addButtonExport(get_lang('Export'));
  75. $this->setDefaults([
  76. 'file_type' => 'csv',
  77. ]);
  78. }
  79. protected function build_export_form_option($show_pdf = true)
  80. {
  81. $this->addElement('header', get_lang('ChooseFormat'));
  82. $this->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV (Comma-Separated Values)', 'csv');
  83. $this->addElement('radio', 'file_type', null, 'XML (Extensible Markup Language)', 'xml');
  84. $this->addElement(
  85. 'radio',
  86. 'file_type',
  87. Display::return_icon('info3.gif', get_lang('ToExportMustLockEvaluation')),
  88. 'PDF (Portable Document Format)',
  89. 'pdf',
  90. ['disabled']
  91. );
  92. $this->addButtonExport(get_lang('Export'));
  93. $this->setDefaults([
  94. 'file_type' => 'csv',
  95. ]);
  96. }
  97. protected function build_import_form()
  98. {
  99. $this->addElement('hidden', 'formSent');
  100. $this->addElement('header', get_lang('ImportFileLocation'));
  101. $this->addElement('file', 'import_file', get_lang('Location'));
  102. $this->addElement(
  103. 'radio',
  104. 'file_type',
  105. get_lang('FileType'),
  106. 'CSV (<a href="docs/example_csv.html" target="_blank" download>'
  107. .get_lang('ExampleCSVFile')
  108. .'</a>)',
  109. 'csv'
  110. );
  111. //$this->addElement('radio', 'file_type', null, 'XML (<a href="docs/example_xml.html" target="_blank" download>'.get_lang('ExampleXMLFile').'</a>)', 'xml');
  112. $this->addElement('checkbox', 'overwrite', null, get_lang('OverwriteScores'));
  113. $this->addElement('checkbox', 'ignoreerrors', null, get_lang('IgnoreErrors'));
  114. $this->addButtonImport(get_lang('Ok'));
  115. $this->setDefaults([
  116. 'formSent' => '1',
  117. 'file_type' => 'csv',
  118. ]);
  119. }
  120. }