Subversion Repositories PHPX

Rev

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

Rev 54 Rev 55
Line 25... Line 25...
25
   * used for comparing against the primary key column(s) of
25
   * used for comparing against the primary key column(s) of
26
   * the <code>Table</code>.
26
   * the <code>Table</code>.
27
   *
27
   *
28
   * @type string|array[string]
28
   * @type string|array[string]
29
   */
29
   */
30
        protected $_persistentId = 'id';
30
        protected static $_persistentId = 'id';
31
31
32
  /**
32
  /**
33
   * The names of the properties that should be used in database
33
   * The names of the properties that should be used in database
34
   * queries, and their mapping to the columns of
34
   * queries, and their mapping to the columns of
35
   * the <code>Table</code>, if specified (keys are property names,
35
   * the <code>Table</code>, if specified (keys are property names,
Line 41... Line 41...
41
   * automatically when saved; if it is in the database,
41
   * automatically when saved; if it is in the database,
42
   * you already have its ID as you searched by it.
42
   * you already have its ID as you searched by it.
43
   *
43
   *
44
   * @type array
44
   * @type array
45
   */
45
   */
46
  protected $_persistentProperties = array();
46
  protected static $_persistentProperties = array();
47
47
48
        /**
48
        /**
49
   * Creates a new model object
49
   * Creates a new model object
50
   *
50
   *
51
   * @see AbstractModel::__construct()
51
   * @see AbstractModel::__construct()
Line 103... Line 103...
103
  {
103
  {
104
        $a = array();
104
        $a = array();
105
105
106
        if ($propertyNames === null)
106
        if ($propertyNames === null)
107
        {
107
        {
-
 
108
                $class = \get_class($this);
108
                $propertyNames = $this->_persistentProperties;
109
                $propertyNames = $class::$_persistentProperties;
109
        }
110
        }
110
111
111
        foreach ($propertyNames as $propertyName => $columnName)
112
        foreach ($propertyNames as $propertyName => $columnName)
112
        {
113
        {
113
                if (is_numeric($propertyName))
114
                if (is_numeric($propertyName))
Line 131... Line 132...
131
   *   if there is no data for this object
132
   *   if there is no data for this object
132
   */
133
   */
133
  public function find ()
134
  public function find ()
134
  {
135
  {
135
        $class = \get_class($this);
136
        $class = \get_class($this);
136
    $result = $this->persistentTable->find($this->{$this->_persistentId});
137
    $result = $this->persistentTable->find($this->{$class::$_persistentId});
137
    if ($result)
138
    if ($result)
138
    {
139
    {
139
        return $this->map($result);
140
        return $this->map($result);
140
    }
141
    }
141
142
Line 154... Line 155...
154
   * @see Table::updateOrInsert()
155
   * @see Table::updateOrInsert()
155
   */
156
   */
156
  public function save (array $propertyNames = null)
157
  public function save (array $propertyNames = null)
157
  {
158
  {
158
        $table = $this->persistentTable;
159
        $table = $this->persistentTable;
-
 
160
        $class = \get_class($this);
159
        $idPropertyName = $this->_persistentId;
161
        $idPropertyName = $class::$_persistentId;
160
162
161
        $result = $table->updateOrInsert(
163
        $result = $table->updateOrInsert(
162
                $this->getPropertyArray($propertyNames),
164
                $this->getPropertyArray($propertyNames),
163
                array(
165
                array(
164
                        $table->id => $this->$idPropertyName
166
                        $table->id => $this->$idPropertyName
Line 185... Line 187...
185
   * @see Table::insert()
187
   * @see Table::insert()
186
   */
188
   */
187
  public function insert (array $propertyNames = null)
189
  public function insert (array $propertyNames = null)
188
  {
190
  {
189
        $table = $this->persistentTable;
191
        $table = $this->persistentTable;
-
 
192
        $class = \get_class($this);
190
        $idPropertyName = $this->_persistentId;
193
        $idPropertyName = $class::$_persistentId;
191
194
192
        $result = $table->insert($this->getPropertyArray($propertyNames));
195
        $result = $table->insert($this->getPropertyArray($propertyNames));
193
196
194
        if ($result && ($lastInsertId = $table->lastInsertId))
197
        if ($result && ($lastInsertId = $table->lastInsertId))
195
        {
198
        {
Line 205... Line 208...
205
   * @return bool
208
   * @return bool
206
   * @see Table::delete()
209
   * @see Table::delete()
207
   */
210
   */
208
  public function delete ()
211
  public function delete ()
209
  {
212
  {
-
 
213
        $class = \get_class($this);
210
        return $this->persistentTable->delete($this->{$this->_persistentId});
214
        return $this->persistentTable->delete($this->{$class::$_persistentId});
211
  }
215
  }
212
}
216
}