http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 6 LOC: 110 Statements: 13

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
 * @version   $Id$
15
 */
16
/**
17
 * @see Xyster_Data_Symbol
18
 */
19 1
require_once 'Xyster/Data/Symbol.php';
20
/**
21
 * A struct that holds a field and a direction
22
 *
23
 * @category  Xyster
24
 * @package   Xyster_Data
25
 * @copyright Copyright (c) 2007-2008 Irrational Logic (http://irrationallogic.net)
26
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
27
 */
28
class Xyster_Data_Sort implements Xyster_Data_Symbol
29
{
30
    /**
31
     * The direction of the sort, 'ASC' or 'DESC'
32
     *
33
     * @var string
34
     */
35
    private $_direction;
36
37
    /**
38
     * @var Xyster_Data_Field
39
     */
40
    private $_field;
41
42
    /**
43
     * Creates a new Sort
44
     *
45
     * @param Xyster_Data_Field|string $field
46
     * @param string $direction
47
     */
48
    private function __construct( $field, $direction )
49
    {
50 46
        $this->_direction = $direction;
51 46
        if (! $field instanceof Xyster_Data_Field) {
52 37
            require_once 'Xyster/Data/Field.php';
53 37
            $field = Xyster_Data_Field::named($field);
54 37
        }
55 46
        $this->_field = $field;
56
    }
57
58
    /**
59
     * Gets the field
60
     *
61
     * @return Xyster_Data_Field
62
     */
63
    public function getField()
64
    {
65 33
        return $this->_field;
66
    }
67
68
    /**
69
     * Gets the sort direction
70
     *
71
     * @return string
72
     */
73
    public function getDirection()
74
    {
75 26
        return $this->_direction;
76
    }
77
78
    /**
79
     * Returns the string syntax for this Sort
80
     *
81
     * @magic
82
     * @return string
83
     */
84
    public function __toString()
85
    {
86 2
        return $this->_field->getName() . ' ' . $this->_direction;
87
    }
88
89
    /**
90
     * Create a new ascending sort for the column specified
91
     *
92
     * @param string $field
93
     * @return Xyster_Data_Sort
94
     */
95
    static public function asc( $field )
96
    {
97 42
        return new Xyster_Data_Sort($field, 'ASC');
98
    }
99
100
    /**
101
     * Create a new descending Sort for the column specified
102
     *
103
     * @param string $field
104
     * @return Xyster_Data_Sort
105
     */
106
    static public function desc( $field )
107
    {
108 22
        return new Xyster_Data_Sort($field, 'DESC');
109
    }
110
}


Report generated at 2008-03-05T18:27:43-05:00