main.itop-portal.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. // Copyright (C) 2016 Combodo SARL
  3. //
  4. // This file is part of iTop.
  5. //
  6. // iTop is free software; you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // iTop is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with iTop. If not, see <http://www.gnu.org/licenses/>
  18. /**
  19. * main.itop-portal.php
  20. *
  21. * @author Guillaume Lajarige <guillaume.lajarige@combodo.com>
  22. */
  23. class iTopPortalUrlMaker implements iDBObjectURLMaker
  24. {
  25. public static function MakeObjectURL($sClass, $iId)
  26. {
  27. require_once APPROOT . '/lib/silex/vendor/autoload.php';
  28. require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/providers/urlgeneratorserviceprovider.class.inc.php';
  29. require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/helpers/urlgeneratorhelper.class.inc.php';
  30. require_once APPROOT . '/env-' . utils::GetCurrentEnvironment() . '/itop-portal-base/portal/src/helpers/applicationhelper.class.inc.php';
  31. // Using a static var allows to preserve the object through function calls
  32. static $oApp = null;
  33. static $sPortalId = null;
  34. // Initializing Silex app
  35. if ($oApp === null)
  36. {
  37. // Initializing Silex framework
  38. $oApp = new Silex\Application();
  39. // Registering optional silex components
  40. $oApp->register(new Combodo\iTop\Portal\Provider\UrlGeneratorServiceProvider());
  41. // Registering routes
  42. Combodo\iTop\Portal\Helper\ApplicationHelper::LoadRouters();
  43. Combodo\iTop\Portal\Helper\ApplicationHelper::RegisterRoutes($oApp);
  44. // Retrieving portal id
  45. $sPortalId = basename(__DIR__);
  46. }
  47. $sObjectQueryString = $oApp['url_generator']->generate('p_object_edit', array('sObjectClass' => $sClass, 'sObjectId' => $iId));
  48. $sPortalAbsoluteUrl = utils::GetAbsoluteUrlModulePage($sPortalId, 'index.php');
  49. $sUrl = str_replace('?', $sObjectQueryString . '?', $sPortalAbsoluteUrl);
  50. return $sUrl;
  51. }
  52. }
  53. DBObject::RegisterURLMakerClass('portal', 'iTopPortalUrlMaker');