/library/Nid/Grid/Column/Decorator/Action.php
PHP | 137 lines | 119 code | 18 blank | 0 comment | 34 complexity | 947504c06475b28a145273a122aedf9a MD5 | raw file
Possible License(s): AGPL-3.0
- <?php
- class Nid_Grid_Column_Decorator_Action extends Nid_Grid_Column_Decorator_Abstract
- {
- protected $_links = array();
- protected $_separator = " / ";
- protected $_row;
-
- public function render($column)
- {
- $output = array();
- if ($this->getOption('seperator'))
- $this->_seperator = $this->getOption('seperator');
-
- $grid = $this->getOption('grid');
- $url = $this->getOption('url');
- if (empty($url))
- $url = array();
- if (empty($url['module']))
- $url['module'] = $grid->getModule();
-
- if (empty($url['module']))
- $url['module'] = "default";
-
-
- if (empty($url['controller']))
- $url['controller'] = $grid->getController();
-
- $links = $this->getOption('links');
- foreach ($links as $key=>$value)
- {
- if (is_array($value))
- {
- $link = $key;
- $options = $value;
- } elseif (is_string($value)) {
- $link = $value;
- $options = array();
- }
-
- $curUrl = $url;
- if (!empty($options['params']) && is_array($options['params']))
- $curUrl = array_merge($curUrl, $options['params']);
-
-
- if (empty($options['linkParams']))
- $options['linkParams'] = array();
-
- if ($link == "edit") {
- $curUrl['action'] = "edit";
- $curUrl['id'] = $column->getRow()->id;
- $options['label'] = __("Edit");
- } elseif ($link == "duplicate") {
- $curUrl['action'] = "create";
- $curUrl['id'] = $column->getRow()->id;
- $options['label'] = __("Duplicate");
- } elseif ($link == "ajaxedit") {
- $curUrl['action'] = "edit";
- $curUrl['id'] = $column->getRow()->id;
- $options['label'] = __("Edit");
- $options['linkParams'] = array_merge(array("mask" => true, "ajax" => true, "type" => "get"), $options['linkParams']);
- } elseif ($link == "simpleshow") {
- $curUrl['action'] = "show";
- $curUrl['id'] = $column->getRow()->id;
- $options['label'] = __("Show");
- } elseif ($link == "show") {
- $curUrl['action'] = "show";
- $curUrl['id'] = $column->getRow()->id;
- $options['label'] = __("Show");
- $options['linkParams'] = array_merge(array("mask" => true, "ajax" => true, "type" => "get"), $options['linkParams']);
- } elseif ($link == "active") {
- $curUrl['id'] = $column->getRow()->id;
- if ($column->getRow()->{$column->getGrid()->getTable()->getPrefix() . "is_active"} == "1")
- {
- $curUrl['action'] = "active";
- $curUrl['value'] = "0";
- $options['label'] = __("Deactive");
- } else {
- $curUrl['action'] = "active";
- $curUrl['value'] = "1";
- $options['label'] = __("Active");
- }
- $options['linkParams'] = array("loading" => "...", "ajax" => true, "target" => "action-active-" . $column->getRow()->id, "scroll" => false);
- } elseif ($link == "publish") {
- $curUrl['id'] = $column->getRow()->id;
- if ($column->getRow()->{$column->getGrid()->getTable()->getPrefix() . "is_published"} == "1")
- {
- $curUrl['action'] = "publish";
- $curUrl['value'] = "0";
- $options['label'] = __("Unpublish");
- } else {
- $curUrl['action'] = "publish";
- $curUrl['value'] = "1";
- $options['label'] = __("Publish");
- }
- $options['linkParams'] = array("loading" => "...", "ajax" => true, "target" => "action-publish-" . $column->getRow()->id, "scroll" => false);
- } elseif ($link == "delete") {
- $curUrl['action'] = "delete";
- $curUrl['id'] = $column->getRow()->id;
- $options['label'] = __("Delete");
- $options['linkParams'] = array_merge(array("mask" => true, "ajax" => true), $options['linkParams']);
- $options['linkParams']['confirmMessage'] = __("Are you sure you want to delete this item?");
- } elseif (!empty($options)) {
- if (empty($options['label']))
- $options['label'] = __("Unnamed");
-
- if (!array_key_exists("action", $curUrl))
- throw new Nid_Exception(540, __("You must specify an action for custom link actions in your grid column"));
- }
-
- foreach ($curUrl as $key=>$param)
- {
- preg_match('/{([^}]*)}/',$param,$matches);
- if ($matches)
- {
- $curUrl[$key] = $column->getRow()->{$matches[1]};
- }
- }
-
- if (empty($options['linkParams']))
- $options['linkParams'] = array("ajax" => false);
-
- if (empty($options["type"]))
- $options["type"] = "link";
-
- if ($options['type'] == "dialog")
- $linkUrl = $this->_view->dialogLink($curUrl, $options['label'], $options['linkParams']);
- else
- $linkUrl = $this->_view->link($curUrl, $options['label'], $options['linkParams']);
- if ($linkUrl != "")
- $output[] = "<span id=\"action-" . $link . "-" . $column->getRow()->id . "\">" . $linkUrl . "</span>";
-
- }
-
- return "<div class=\"grid-actions\">" . implode($this->_separator, $output) . "</div>";
- }
- }