pens.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * This file is part of chamilo-pens.
  4. *
  5. * chamilo-pens is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * chamilo-pens is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with chamilo-pens. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * Provides an implementation of the PENS server, using the php-pens library.
  20. * This file must be required by a file pens.php accessible at the Chamilo root.
  21. *
  22. * @author Guillaume Viguier-Just <guillaume@viguierjust.com>
  23. * @licence http://www.gnu.org/licenses/gpl.txt
  24. */
  25. require_once __DIR__.'/../../main/inc/global.inc.php';
  26. require_once __DIR__.'/lib/pens.php';
  27. require_once __DIR__.'/chamilo_pens.php';
  28. class ChamiloPackageHandler extends PENSPackageHandler
  29. {
  30. public function processPackage($request, $path_to_package)
  31. {
  32. $server = PENSServer::singleton();
  33. // Moves the package to archive/pens
  34. $path_to_archives = api_get_path(SYS_ARCHIVE_PATH).'pens';
  35. if (!is_dir($path_to_archives)) {
  36. $mode = api_get_permissions_for_new_directories();
  37. mkdir($path_to_archives, $mode, true);
  38. }
  39. rename($path_to_package, $path_to_archives.'/'.$request->getFilename());
  40. // Insert the request in the database
  41. $chamilo_pens = new ChamiloPens($request);
  42. $chamilo_pens->save();
  43. $server->sendAlert($request, new PENSResponse(0, 'Package successfully processed'));
  44. }
  45. }
  46. $handler = new ChamiloPackageHandler();
  47. $handler->setSupportedPackageTypes(['scorm-pif']);
  48. $handler->setSupportedPackageFormats(['zip']);
  49. $server = PENSServer::singleton();
  50. $server->setPackageHandler($handler);
  51. $server->receiveCollect();