Subversion Repositories PHPX

Rev

Rev 29 | Rev 51 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 29 Rev 49
Line 1... Line 1...
1
<?php
1
<?php
2
2
-
 
3
require_once __DIR__ . '/../AbstractModel.php';
3
require_once __DIR__ . '/Table.php';
4
require_once __DIR__ . '/Table.php';
4
5
5
/**
6
/**
6
 * Generic abstract database mapper class
7
 * Generic abstract database mapper class
7
 *
8
 *
8
 * @author Thomas Lahn
9
 * @author Thomas Lahn
9
 */
10
 */
10
abstract class Mapper
11
abstract class Mapper extends AbstractModel
11
{
12
{
12
  /**
13
  /**
13
   * Class name of the associated table model
14
   * Class name of the associated table model
14
   *
15
   *
15
   * @var string
16
   * @var string
16
   */
17
   */
17
  protected $_table = 'Table';
18
  protected $_table = 'Table';
18
 
19
19
  protected $_dbTable;
20
  protected $_dbTable;
20
 
21
21
  /**
22
  /**
22
   * Sets the {@link Table} for this mapper
23
   * Sets the {@link Table} for this mapper
23
   * @param string|Table $dbTable
24
   * @param string|Table $dbTable
24
   *   Class name of the new instance, or an existing instance
25
   *   Class name of the new instance, or an existing instance
25
   * @throws Exception if <var>$dbTable</var> is not a <code>Table</code>
26
   * @throws Exception if <var>$dbTable</var> is not a <code>Table</code>
Line 28... Line 29...
28
  {
29
  {
29
    if (is_string($table))
30
    if (is_string($table))
30
    {
31
    {
31
      $table = new $table();
32
      $table = new $table();
32
    }
33
    }
33
 
34
34
    if (!($table instanceof Table)) {
35
    if (!($table instanceof Table)) {
35
      throw new Exception('Invalid table data gateway provided');
36
      throw new Exception('Invalid table data gateway provided');
36
    }
37
    }
37
 
38
38
    $this->_dbTable = $table;
39
    $this->_dbTable = $table;
39
  }
40
  }
40
41
41
  /**
42
  /**
42
   * Gets the {@link Table} for this mapper
43
   * Gets the {@link Table} for this mapper
Line 54... Line 55...
54
    {
55
    {
55
      if (is_null($table))
56
      if (is_null($table))
56
      {
57
      {
57
        $table = $this->_table;
58
        $table = $this->_table;
58
      }
59
      }
59
     
60
60
      $this->setDbTable($table);
61
      $this->setDbTable($table);
61
    }
62
    }
62
   
63
63
    return $this->_dbTable;
64
    return $this->_dbTable;
64
  }
65
  }
65
 
66
-
 
67
  /**
-
 
68
   * Returns the <code>Table</code> for this object.
-
 
69
   *
-
 
70
   * @return Table
-
 
71
   */
-
 
72
  public function getTable ()
-
 
73
  {
-
 
74
        return $this->getDbTable();
-
 
75
  }
-
 
76
66
  /**
77
  /**
67
   * Sorts an array of objects by the property of the nested object.
78
   * Sorts an array of objects by the property of the nested object.
68
   * To be used with the u*sort() functions.
79
   * To be used with the u*sort() functions.
69
   *
80
   *
70
   * @param object $a First operand of the comparison
81
   * @param object $a First operand of the comparison
Line 80... Line 91...
80
  {
91
  {
81
    if ($a->$property === $b->$property)
92
    if ($a->$property === $b->$property)
82
    {
93
    {
83
      return 0;
94
      return 0;
84
    }
95
    }
85
 
96
86
    return ($a->$property < $b->$property) ? -1 : 1;
97
    return ($a->$property < $b->$property) ? -1 : 1;
87
  }
98
  }
88
}
99
}
89
100