SurveyExportTxtPlugin.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Class SurveyExportTxtPlugin.
  5. */
  6. class SurveyExportTxtPlugin extends Plugin
  7. {
  8. /**
  9. * SurveyExportTxtPlugin constructor.
  10. */
  11. protected function __construct()
  12. {
  13. $settings = [
  14. 'enabled' => 'boolean',
  15. 'export_incomplete' => 'boolean',
  16. ];
  17. parent::__construct('0.1', 'Angel Fernando Quiroz Campos', $settings);
  18. }
  19. /**
  20. * @return SurveyExportTxtPlugin|null
  21. */
  22. public static function create()
  23. {
  24. static $result = null;
  25. return $result ? $result : $result = new self();
  26. }
  27. /**
  28. * Installation process.
  29. */
  30. public function install()
  31. {
  32. }
  33. /**
  34. * Uninstallation process.
  35. */
  36. public function uninstall()
  37. {
  38. }
  39. /**
  40. * @param array $params
  41. *
  42. * @return string
  43. */
  44. public static function filterModify($params)
  45. {
  46. $enabled = api_get_plugin_setting('surveyexporttxt', 'enabled');
  47. if ($enabled !== 'true') {
  48. return '';
  49. }
  50. $surveyId = isset($params['survey_id']) ? (int) $params['survey_id'] : 0;
  51. $iconSize = isset($params['icon_size']) ? $params['icon_size'] : ICON_SIZE_SMALL;
  52. if (empty($surveyId)) {
  53. return '';
  54. }
  55. return Display::url(
  56. Display::return_icon('export_evaluation.png', get_lang('Export'), [], $iconSize),
  57. api_get_path(WEB_PLUGIN_PATH).'surveyexporttxt/export.php?survey='.$surveyId.'&'.api_get_cidreq()
  58. );
  59. }
  60. /**
  61. * Create tools for all courses.
  62. */
  63. private function createLinkToCourseTools()
  64. {
  65. $result = Database::getManager()
  66. ->createQuery('SELECT c.id FROM ChamiloCoreBundle:Course c')
  67. ->getResult();
  68. foreach ($result as $item) {
  69. $this->createLinkToCourseTool($this->get_name().':teacher', $item['id'], 'survey.png');
  70. }
  71. }
  72. /**
  73. * Remove all course tools created by plugin.
  74. */
  75. private function removeLinkToCourseTools()
  76. {
  77. Database::getManager()
  78. ->createQuery('DELETE FROM ChamiloCourseBundle:CTool t WHERE t.link LIKE :link AND t.category = :category')
  79. ->execute(['link' => 'surveyexporttxt/start.php%', 'category' => 'plugin']);
  80. }
  81. }