Subversion Repositories PHPX

Rev

Rev 65 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 65 Rev 67
Line 90... Line 90...
90
                $class::$_persistentTable = $table;
90
                $class::$_persistentTable = $table;
91
        }
91
        }
92
  }
92
  }
93
93
94
  /**
94
  /**
-
 
95
   * Returns an array containing the property-column mapping.
-
 
96
   *
-
 
97
   * @param array $propertyNames = null
-
 
98
   *   Names of the properties that should be included.
-
 
99
   *   The default is to include all persistent properties.
-
 
100
   * @return array
-
 
101
   */
-
 
102
  public static function getPersistentMapping (array $propertyNames = null)
-
 
103
  {
-
 
104
    $a = array();
-
 
105
-
 
106
        $persistent_properties = static::$_persistentProperties;
-
 
107
-
 
108
        if ($propertyNames === null)
-
 
109
        {
-
 
110
                $propertyNames = $persistent_properties;
-
 
111
        }
-
 
112
-
 
113
        foreach ($propertyNames as $property_name)
-
 
114
        {
-
 
115
          if (!array_key_exists($property_name, $persistent_properties))
-
 
116
          {
-
 
117
                        $column_name = $property_name;
-
 
118
          }
-
 
119
          else
-
 
120
          {
-
 
121
            $column_name = $persistent_properties[$property_name];
-
 
122
          }
-
 
123
-
 
124
                $a[$property_name] = $column_name;
-
 
125
        }
-
 
126
-
 
127
        return $a;
-
 
128
  }
-
 
129
-
 
130
  /**
95
   * Returns an array for database queries containing the
131
   * Returns an array for database queries containing the
96
   * property values of this object, using the specified
132
   * property values of this object, using the specified
97
   * property-to-column mapping.
133
   * property-to-column mapping.
98
   *
134
   *
99
   * @param array $propertyNames = null
135
   * @param array $propertyNames = null
Line 128... Line 164...
128
   * Finds the record for the model object in the table, fills
164
   * Finds the record for the model object in the table, fills
129
   * the object with missing data, and returns the result.
165
   * the object with missing data, and returns the result.
130
   *
166
   *
131
   * @param mixed $id = null
167
   * @param mixed $id = null
132
   *   The ID of the object to find.  If <code>null</code> (default),
168
   *   The ID of the object to find.  If <code>null</code> (default),
133
   *   the object is search for by its current ID.
169
   *   the object is searched for by its current ID.
134
   * @see Table::find(Model)
-
 
135
   * @return Model|null
170
   * @return Model|null
136
   *   This object filled with missing data, or <code>null</code>
171
   *   This object filled with missing data, or <code>null</code>
137
   *   if there is no data for this object
172
   *   if there is no data for this object
138
   * @see Table::find(Model)
173
   * @see Table::find(int)
139
   */
174
   */
140
  public function find ($id = null)
175
  public function find ($id = null)
141
  {
176
  {
142
        $class = \get_class($this);
177
        $class = \get_class($this);
143
        if ($id === null)
178
        if ($id === null)
Line 158... Line 193...
158
    }
193
    }
159
194
160
    return null;
195
    return null;
161
  }
196
  }
162
197
-
 
198
  /**
-
 
199
   * Finds the records for model objects in the table by value,
-
 
200
   * and returns the result.
-
 
201
   *
-
 
202
   * @param string $name
-
 
203
   *   Name of the property to search for.
-
 
204
   * @param mixed $value = null
-
 
205
   *   The property value to find.  If <code>null</code>,
-
 
206
   *   the current value of the specified property is used.
-
 
207
   *   (To search for null, you need to make sure that the
-
 
208
   *   current property value is <code>null</code>, which is
-
 
209
   *   the PHP default.)
-
 
210
   * @return array[Model]|null
-
 
211
   *   Model objects, or <code>null</code> if there is no data
-
 
212
   *   for this property and value
-
 
213
   * @see Table::select(Model)
-
 
214
   */
-
 
215
  public function findByProperty ($name, $value = null)
-
 
216
  {
-
 
217
    $class = \get_class($this);
-
 
218
        $mapping = $class::getPersistentMapping(array($name));
-
 
219
-
 
220
        if ($value === null)
-
 
221
        {
-
 
222
          $value = $this->$name;
-
 
223
        }
-
 
224
-
 
225
    $results = $this->persistentTable->select(null,
-
 
226
      array($mapping[$name] => $value));
-
 
227
-
 
228
    if ($results)
-
 
229
    {
-
 
230
        return array_map(array($this, 'map'), $results);
-
 
231
    }
-
 
232
-
 
233
    return null;
-
 
234
  }
-
 
235
163
  /**
236
  /**
164
   * Saves the model object in the table
237
   * Saves the model object in the table
165
   *
238
   *
166
   * @param array $propertyNames = null
239
   * @param array $propertyNames = null
167
   *   Names of the properties whose values should be saved
240
   *   Names of the properties whose values should be saved