GetSelectedFeatures.php 1.9 KB

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