http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 6 LOC: 105 Statements: 12

Source file Statements Methods Total coverage
Sort.php 100.0% 100.0% 100.0%
 
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * This source file is subject to the new BSD license that is bundled
6
 * with this package in the file LICENSE.txt.
7
 * It is also available through the world-wide-web at this URL:
8
 * http://www.opensource.org/licenses/bsd-license.php
9
 *
10
 * @category  Xyster
11
 * @package   Xyster_Data
12
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
13
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
14
 */
15
/**
16
 * A struct that holds a field and a direction
17
 *
18
 * @category  Xyster
19
 * @package   Xyster_Data
20
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
21
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
22
 */
23
class Xyster_Data_Sort
24
{
25
    /**
26
     * The direction of the sort, 'ASC' or 'DESC'
27
     *
28
     * @var string
29
     */
30
    private $_direction;
31
32
    /**
33
     * @var Xyster_Data_Field
34
     */
35
    private $_field;
36
37
    /**
38
     * Creates a new Sort
39
     *
40
     * @param Xyster_Data_Field|string $field
41
     * @param string $direction
42
     */
43
    private function __construct( $field, $direction )
44
    {
45 27
        $this->_direction = $direction;
46 27
        if (! $field instanceof Xyster_Data_Field) {
47 19
            require_once 'Xyster/Data/Field.php';
48 19
            $field = Xyster_Data_Field::named($field);
49 19
        }
50 27
        $this->_field = $field;
51
    }
52
53
    /**
54
     * Gets the field
55
     *
56
     * @return Xyster_Data_Field
57
     */
58
    public function getField()
59
    {
60 23
        return $this->_field;
61
    }
62
63
    /**
64
     * Gets the sort direction
65
     *
66
     * @return string
67
     */
68
    public function getDirection()
69
    {
70 16
        return $this->_direction;
71
    }
72
73
    /**
74
     * Returns the string syntax for this Sort
75
     *
76
     * @magic
77
     * @return string
78
     */
79
    public function __toString()
80
    {
81 1
        return $this->_field->getName() . ' ' . $this->_direction;
82
    }
83
84
    /**
85
     * Create a new ascending sort for the column specified
86
     *
87
     * @param string $field
88
     * @return Xyster_Data_Sort
89
     */
90
    static public function asc( $field )
91
    {
92 23
        return new Xyster_Data_Sort($field, 'ASC');
93
    }
94
95
    /**
96
     * Create a new descending Sort for the column specified
97
     *
98
     * @param string $field
99
     * @return Xyster_Data_Sort
100
     */
101
    static public function desc( $field )
102
    {
103 11
        return new Xyster_Data_Sort($field, 'DESC');
104
    }
105
}


Report generated at 2008-01-20T12:13:39-05:00