GetSelectedFeatures.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. Lib::loadClass('FeatureAttrSelected');
  3. Lib::loadClass('FeatureAttrContextSelected');
  4. Lib::loadClass('Route_UrlAction');
  5. Lib::loadClass('Api_WfsNs');
  6. class Api_Process_P5_GetSelectedFeatures { // TODO: extends Api_ProcessBase
  7. static function run($args, $responseForm) {
  8. DBG::log($args, 'array', "Run WPS Process 'p5:getSelectedFeatures'");
  9. $typeName = (!empty($args['typeName'][0])) ? $args['typeName'][0] : '';
  10. if (!$typeName) throw new Api_OwsException("Missing value for 'typeName'", 501, null, 'MissingParameterValue', 'request');
  11. $listPrimaryKeys = (!empty($args['primaryKey'])) ? $args['primaryKey'] : [];
  12. if (empty($listPrimaryKeys)) throw new Api_OwsException("Missing value for 'primaryKey'", 501, null, 'MissingParameterValue', 'request');
  13. $context = (!empty($args['context'])) ? $args['context'][0] : '';
  14. if (!empty($context)) {
  15. $idContext = (is_numeric($context)) ? $context : FeatureAttrContextSelected::getIdContext($context);
  16. DBG::log($args, 'array', "Run WPS Process 'p5:getSelectedFeatures' with context '{$context}' (ID: {$idContext})");
  17. $listSelectedState = FeatureAttrContextSelected::getSelectState($idContext, $typeName, $listPrimaryKeys);
  18. $totalSelected = FeatureAttrContextSelected::getTotalSelected($idContext, $typeName);
  19. } else {
  20. $listSelectedState = FeatureAttrSelected::getSelectState($typeName, $listPrimaryKeys);
  21. $totalSelected = FeatureAttrSelected::getTotalSelected($typeName);
  22. }
  23. $idAcl = DB::getPDO()->fetchValue("
  24. select t.idZasob
  25. from `CRM_#CACHE_ACL_OBJECT` t
  26. where t.namespace = :namespace
  27. and t.idZasob IS NOT NULL
  28. ", [
  29. ':namespace' => Api_WfsNs::toNamespace($typeName),
  30. ]);
  31. header('Content-Type: application/json');
  32. echo json_encode([
  33. 'type' => "success",
  34. 'msg' => "done",
  35. 'body' => [
  36. 'selected' => $listSelectedState,
  37. 'totalSelected' => $totalSelected,
  38. 'tools' => $idAcl ? Route_UrlAction::getSelectedFeatureTools($idAcl, User::getLogin()) : [],
  39. ]
  40. ]);
  41. exit;
  42. }
  43. }