/Ip/Internal/Grid/Model/Status.php

https://gitlab.com/x33n/ImpressPages · PHP · 110 lines · 56 code · 13 blank · 41 comment · 12 complexity · b94f8ccfb0a3701d0a1c150706573a2d MD5 · raw file

  1. <?php
  2. /**
  3. * @package ImpressPages
  4. */
  5. namespace Ip\Internal\Grid\Model;
  6. class Status
  7. {
  8. public static function parse($statusVariable)
  9. {
  10. if (!empty($statusVariable[0]) && $statusVariable[0] == '#') {
  11. $statusVariable = substr($statusVariable, 1);
  12. }
  13. $variables = array();
  14. $parts = explode('&', $statusVariable);
  15. foreach ($parts as $part) {
  16. $tmp = explode('=', $part);
  17. if (isset($tmp[1])) {
  18. $key = $tmp[0];
  19. $val = urldecode($tmp[1]);
  20. if (substr($key, -5) == '_json') {
  21. $key = substr($key, 0, -5);
  22. $val = json_decode($val);
  23. }
  24. $variables[urldecode($key)] = $val;
  25. } else {
  26. $variables[urldecode($tmp[0])] = null;
  27. }
  28. }
  29. return $variables;
  30. }
  31. public static function build($variables)
  32. {
  33. return 'grid&' . http_build_query($variables);
  34. }
  35. /**
  36. * Get the depth of nesting
  37. * @param $statusVariables
  38. * @return int
  39. */
  40. public static function depth($statusVariables)
  41. {
  42. $depth = 1;
  43. while (isset($statusVariables['gridId' . $depth]) && isset($statusVariables['gridParentId' . $depth])) {
  44. $depth++;
  45. }
  46. return $depth;
  47. }
  48. public static function genSubgridVariables($curStatusVariables, $gridId, $gridParentId)
  49. {
  50. $newStatusVariables = array();
  51. $depth = Status::depth($curStatusVariables);
  52. for($i=1; $i<$depth; $i++) {
  53. $newStatusVariables['gridId' . $i] = $curStatusVariables['gridId' . $i];
  54. $newStatusVariables['gridParentId' . $i] = $curStatusVariables['gridParentId' . $i];
  55. }
  56. if ($gridId !== null) {
  57. $newStatusVariables['gridId' . $depth] = $gridId;
  58. }
  59. if ($gridParentId !== null) {
  60. $newStatusVariables['gridParentId' . $depth] = $gridParentId;
  61. }
  62. return $newStatusVariables;
  63. }
  64. // protected $config = null;
  65. //
  66. // public function __construct($hash)
  67. // {
  68. // $this->config = fixMagicQuotes(parse_str($hash));
  69. // }
  70. //
  71. //
  72. // public function hash()
  73. // {
  74. //
  75. // }
  76. //
  77. // protected function fixMagicQuotes($data)
  78. // {
  79. // if (!get_magic_quotes_gpc()) {
  80. // return;
  81. // }
  82. //
  83. // $process = array(&$data);
  84. // while (list($key, $val) = each($process)) {
  85. // foreach ($val as $k => $v) {
  86. // unset($process[$key][$k]);
  87. // if (is_array($v)) {
  88. // $process[$key][stripslashes($k)] = $v;
  89. // $process[] = & $process[$key][stripslashes($k)];
  90. // } else {
  91. // $process[$key][stripslashes($k)] = stripslashes($v);
  92. // }
  93. // }
  94. // }
  95. // unset($process);
  96. // }
  97. }