PageRenderTime 30ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/library/Nid/Grid/Column/Decorator/Action.php

https://bitbucket.org/rmarefaty/joogle
PHP | 137 lines | 119 code | 18 blank | 0 comment | 34 complexity | 947504c06475b28a145273a122aedf9a MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. class Nid_Grid_Column_Decorator_Action extends Nid_Grid_Column_Decorator_Abstract
  3. {
  4. protected $_links = array();
  5. protected $_separator = " / ";
  6. protected $_row;
  7. public function render($column)
  8. {
  9. $output = array();
  10. if ($this->getOption('seperator'))
  11. $this->_seperator = $this->getOption('seperator');
  12. $grid = $this->getOption('grid');
  13. $url = $this->getOption('url');
  14. if (empty($url))
  15. $url = array();
  16. if (empty($url['module']))
  17. $url['module'] = $grid->getModule();
  18. if (empty($url['module']))
  19. $url['module'] = "default";
  20. if (empty($url['controller']))
  21. $url['controller'] = $grid->getController();
  22. $links = $this->getOption('links');
  23. foreach ($links as $key=>$value)
  24. {
  25. if (is_array($value))
  26. {
  27. $link = $key;
  28. $options = $value;
  29. } elseif (is_string($value)) {
  30. $link = $value;
  31. $options = array();
  32. }
  33. $curUrl = $url;
  34. if (!empty($options['params']) && is_array($options['params']))
  35. $curUrl = array_merge($curUrl, $options['params']);
  36. if (empty($options['linkParams']))
  37. $options['linkParams'] = array();
  38. if ($link == "edit") {
  39. $curUrl['action'] = "edit";
  40. $curUrl['id'] = $column->getRow()->id;
  41. $options['label'] = __("Edit");
  42. } elseif ($link == "duplicate") {
  43. $curUrl['action'] = "create";
  44. $curUrl['id'] = $column->getRow()->id;
  45. $options['label'] = __("Duplicate");
  46. } elseif ($link == "ajaxedit") {
  47. $curUrl['action'] = "edit";
  48. $curUrl['id'] = $column->getRow()->id;
  49. $options['label'] = __("Edit");
  50. $options['linkParams'] = array_merge(array("mask" => true, "ajax" => true, "type" => "get"), $options['linkParams']);
  51. } elseif ($link == "simpleshow") {
  52. $curUrl['action'] = "show";
  53. $curUrl['id'] = $column->getRow()->id;
  54. $options['label'] = __("Show");
  55. } elseif ($link == "show") {
  56. $curUrl['action'] = "show";
  57. $curUrl['id'] = $column->getRow()->id;
  58. $options['label'] = __("Show");
  59. $options['linkParams'] = array_merge(array("mask" => true, "ajax" => true, "type" => "get"), $options['linkParams']);
  60. } elseif ($link == "active") {
  61. $curUrl['id'] = $column->getRow()->id;
  62. if ($column->getRow()->{$column->getGrid()->getTable()->getPrefix() . "is_active"} == "1")
  63. {
  64. $curUrl['action'] = "active";
  65. $curUrl['value'] = "0";
  66. $options['label'] = __("Deactive");
  67. } else {
  68. $curUrl['action'] = "active";
  69. $curUrl['value'] = "1";
  70. $options['label'] = __("Active");
  71. }
  72. $options['linkParams'] = array("loading" => "...", "ajax" => true, "target" => "action-active-" . $column->getRow()->id, "scroll" => false);
  73. } elseif ($link == "publish") {
  74. $curUrl['id'] = $column->getRow()->id;
  75. if ($column->getRow()->{$column->getGrid()->getTable()->getPrefix() . "is_published"} == "1")
  76. {
  77. $curUrl['action'] = "publish";
  78. $curUrl['value'] = "0";
  79. $options['label'] = __("Unpublish");
  80. } else {
  81. $curUrl['action'] = "publish";
  82. $curUrl['value'] = "1";
  83. $options['label'] = __("Publish");
  84. }
  85. $options['linkParams'] = array("loading" => "...", "ajax" => true, "target" => "action-publish-" . $column->getRow()->id, "scroll" => false);
  86. } elseif ($link == "delete") {
  87. $curUrl['action'] = "delete";
  88. $curUrl['id'] = $column->getRow()->id;
  89. $options['label'] = __("Delete");
  90. $options['linkParams'] = array_merge(array("mask" => true, "ajax" => true), $options['linkParams']);
  91. $options['linkParams']['confirmMessage'] = __("Are you sure you want to delete this item?");
  92. } elseif (!empty($options)) {
  93. if (empty($options['label']))
  94. $options['label'] = __("Unnamed");
  95. if (!array_key_exists("action", $curUrl))
  96. throw new Nid_Exception(540, __("You must specify an action for custom link actions in your grid column"));
  97. }
  98. foreach ($curUrl as $key=>$param)
  99. {
  100. preg_match('/{([^}]*)}/',$param,$matches);
  101. if ($matches)
  102. {
  103. $curUrl[$key] = $column->getRow()->{$matches[1]};
  104. }
  105. }
  106. if (empty($options['linkParams']))
  107. $options['linkParams'] = array("ajax" => false);
  108. if (empty($options["type"]))
  109. $options["type"] = "link";
  110. if ($options['type'] == "dialog")
  111. $linkUrl = $this->_view->dialogLink($curUrl, $options['label'], $options['linkParams']);
  112. else
  113. $linkUrl = $this->_view->link($curUrl, $options['label'], $options['linkParams']);
  114. if ($linkUrl != "")
  115. $output[] = "<span id=\"action-" . $link . "-" . $column->getRow()->id . "\">" . $linkUrl . "</span>";
  116. }
  117. return "<div class=\"grid-actions\">" . implode($this->_separator, $output) . "</div>";
  118. }
  119. }