com.ibschreiber.iphp /Ingot/JQuery/JqGrid/Column/Decorator/Link.php

Language PHP Lines 83
MD5 Hash 7b5a83857c33919e0d10c239808d8bb7 Estimated Cost $824 (why?)
Repository https://github.com/ibschreiber/com.ibschreiber.iphp.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

/**
 * @see Ingot_JQuery_JqGrid_Column_Decorator_Abstract
 */
require_once 'Ingot/JQuery/JqGrid/Column/Decorator/Abstract.php';

/**
 * Decorate a column which contains HTML links
 * 
 * @package Ingot_JQuery_JqGrid
 * @copyright Copyright (c) 2005-2009 Warrant Group Ltd. (http://www.warrant-group.com)
 * @author Andy Roberts
 */

class Ingot_JQuery_JqGrid_Column_Decorator_Link extends Ingot_JQuery_JqGrid_Column_Decorator_Abstract
{
    protected $_options = array();

    /**
     * Constructor
     * 
     * @return void
     */
    public function __construct($column, $options = array())
    {
        $this->_column = $column;
        $this->_options = $options;
        
        $this->decorate();
    }

    /*
	 * Decorate column to display URL links
	 * 
	 * @return void
	 */
    public function decorate()
    {
        if (! isset($this->_options['link'])) {
            throw new Ingot_JQuery_JqGrid_Exception('A valid link must be supplied.');
        }
        if (!isset($this->_options['column']))  {
        	$this->_options['column'] = array();
        }	elseif ( (isset($this->_options['column']) && ! is_array($this->_options['column']))) {
            $this->_options['column'] = array(
                
                $this->_options['column']
            );
        }
    }

    /**
     * Build a link contain column values using a string composed of zero or more 
     * directives as per vsprintf().
     * 
     * Additional columns can be supplied, if the link needs to access different
     * column values.
     * 
     * @param array $row
     */
    public function cellValue($row)
    {
        
        // Count the number of arguments to be formatted
        $countArg = substr_count($this->_options['link'], '%');
        
        if ($countArg > 0) {
            // If no columns have been supplied, format link using current column names
            if (count($this->_options['column']) == 0) {
                $column = array_fill(1, $countArg, $row[$this->_column->getName()]);
            } else {
                // If columns have been defined, format link using user defined column names
                $column = array_intersect_key($row, array_flip($this->_options['column']));
            }
            
            $link = vsprintf($this->_options['link'], $column);
        }
        
        return "<a href=\"" . $link . "\">" . $row[$this->getName()] . "</a>";
    }

}
Back to Top