Skip to content

Commit

Permalink
Making history
Browse files Browse the repository at this point in the history
  • Loading branch information
irvingleonard committed Jun 4, 2014
1 parent 1a761c5 commit 342de96
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGES.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
February 13, 2011
- Released ObjectDB.mysql-v3.2
- Bug retrieving and storing data in Ubuntu 10 Linux was corrected
- getPublicProperties method added to ODBObject class
6 changes: 3 additions & 3 deletions ODBConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class ODBConnection {

/* start - configure */
static public $host = "localhost";
static public $host = "salvipascualdb";
static public $port = "3306";
static public $dbname = "test";
static public $dbname = "objectdb";
static public $user = "root";
static public $pass = "root";
static public $pass = "UncleSalviAdventures";
/* end - configure */

public $connect = null;
Expand Down
30 changes: 23 additions & 7 deletions ODBObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function setSaveStatus(){
public function setDataFromArray($data){
if($this->getState() == OBJECT_DELETED) throw new ODBEObjectNotExist();

foreach($this as $key=>$value) {
foreach($this->getPublicProperties() as $key=>$value) {
$element = each($data); // for make it work with ASSOCIATIVE arrays
$this->$key = $element['value'];
}
Expand All @@ -70,7 +70,7 @@ public function setDataFromArray($data){
name: setDataFromParamsList
overview: fill this object with a list of parameters
params:
Array; object values, order as in database
Params; object values, order as in database
returns:
none
exceptions:
Expand All @@ -80,7 +80,7 @@ public function setDataFromParamsList(){
if($this->getState() == OBJECT_DELETED) throw new ODBEObjectNotExist();

$i=0; $args = func_get_args();
foreach($this as $key=>$value){
foreach($this->getPublicProperties() as $key=>$value){
$this->$key = $args[$i++];
}
}
Expand Down Expand Up @@ -144,6 +144,21 @@ public function getTableKeyName(){
// return $db->getTableKey($this->getTableName());
}

/*
name: getPublicProperties
overview: get the user entries properties for this clase
params:
none
returns:
Array; name of properties entry by user
exceptions:
none
*/
public function getPublicProperties(){
$getFields = create_function('$obj', 'return get_object_vars($obj);');
return $getFields($this);
}

/*
name: isSaved
overview: specify if object is in database
Expand Down Expand Up @@ -173,11 +188,11 @@ public function save(){

if($this->isSaved()) { // update object
$sql = "UPDATE ".$this->getTableName()." SET ";
foreach($this as $key=>$value) $sql .= "$key='$value', ";
foreach($this->getPublicProperties() as $key=>$value) $sql .= "$key='$value', ";
$where = " WHERE ".$this->getTableKeyName()."='".$this->id."'";
}else{ // create a new object
$sql = "INSERT INTO ".$this->getTableName()." SET ";
foreach($this as $key=>$value) $sql .= "$key='$value', ";
foreach($this->getPublicProperties() as $key=>$value) $sql .= "$key='$value', ";
}
$sql = substr_replace($sql,$where,strrpos($sql,","));

Expand Down Expand Up @@ -323,8 +338,9 @@ public function __toString(){
if($this->getState() == OBJECT_DELETED) throw new ODBEObjectNotExist();

$header='<th>'.$this->getTableKeyName().'</th>';
$body='<td>'.$this->getId().'</td>';
foreach($this as $key=>$value) {
$body='<td>'.$this->getId().'</td>';

foreach($this->getPublicProperties() as $key=>$value) {
$header .= "<th>$key</th>";
$body .= "<td>$value</td>";
}
Expand Down
5 changes: 5 additions & 0 deletions README.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Created for Salvi Pascual
Find official documentation in http://objectdb.salvipascual.com
Please report any bug or suggestion to [email protected]

Thank you! Enjoy ObjectDB

0 comments on commit 342de96

Please sign in to comment.