private function _getData() { if (is_string($this->dataSource)) { $db = new DataBase(); $db->Query($this->dataSource); if ($db->numRows() > 0) { while ($data = $db->fetchObject()) { array_push($this->data, $data); } } else { $this->data = NULL; } } if (is_object($this->dataSource) && !is_string($this->dataSource)) { $this->data = $this->dataSource; } if (is_array($this->dataSource)) { $this->data = $this->dataSource; } $this->getDataKeys(); }
/** * Find the related objects of the model * @param $table The name of the table of the objects * @param $conditions The relation conditions * @return array Array of objects */ public function _findRelations($table, $conditions) { if (count($conditions) == 0) { $query = "SELECT * FROM {$table}"; } else { $query = "SELECT * FROM {$table} WHERE ( {$conditions} )"; } $db2 = new DataBase(); $db2->query($query); $numResults = $db2->numRows(); $results = array(); for ($i = 0; $i < $numResults; $i++) { $result = $db2->fetchObject(); $results[] = new $table($result); } return $results; }