pens.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. public function processPackage($request, $path_to_package) {
  30. $server = PENSServer::singleton();
  31. // Moves the package to archive/pens
  32. $path_to_archives = api_get_path(SYS_ARCHIVE_PATH).'pens';
  33. if (!is_dir($path_to_archives)) {
  34. mkdir($path_to_archives, 0777, true);
  35. }
  36. rename($path_to_package, $path_to_archives.'/'.$request->getFilename());
  37. // Insert the request in the database
  38. $chamilo_pens = new ChamiloPens($request);
  39. $chamilo_pens->save();
  40. $server->sendAlert($request, new PENSResponse(0, 'Package successfully processed'));
  41. }
  42. }
  43. $handler = new ChamiloPackageHandler();
  44. $handler->setSupportedPackageTypes(array('scorm-pif'));
  45. $handler->setSupportedPackageFormats(array('zip'));
  46. $server = PENSServer::singleton();
  47. $server->setPackageHandler($handler);
  48. $server->receiveCollect();