Permalink
Browse files

Modified internal database references to static

Changed the internal variables that Zoph uses to figure out which
database table belongs to which object (as well as the primary keys and
fields that cannot be null) from object variables into static variables.

Also modified the getRecords(), getRecordsFromQuery() and
getTopNfromSQL() and  method to no longer need the class name as a
parameter.

All of the above became possible because Zoph no longer supports PHP
5.2, as "Late Static Binding", which was needed for this change, was
introduced in PHP 5.3.
  • Loading branch information...
jeroenrnl committed Feb 3, 2013
1 parent 1b6b601 commit 9c88955f36286cf19e2ed58f95f428c934167386
View
@@ -32,6 +32,17 @@
*/
class album extends zophTreeTable implements Organizer {
+ /** @var string The name of the database table */
+ protected static $table_name="albums";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("album_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("album");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="albums.php?parent_album_id=";
+
/** @var Cache the count of photos */
private $photoCount;
@@ -42,7 +53,6 @@ class album extends zophTreeTable implements Organizer {
*/
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("album_id must be numeric"); }
- parent::__construct("albums", array("album_id"), array("album"));
$this->set("album_id", $id);
}
@@ -112,7 +122,7 @@ public function removePhoto(photo $photo) {
*/
public function delete() {
parent::delete(array("photo_albums", "group_permissions"));
- $users = user::getRecords("user", "user_id", array("lightbox_id" => $this->get("album_id")));
+ $users = user::getRecords("user_id", array("lightbox_id" => $this->get("album_id")));
if ($users) {
foreach ($users as $user) {
$user->setFields(array("lightbox_id" => "null"));
@@ -158,7 +168,7 @@ public function getChildren($order=null) {
" GROUP BY album_id " .
escape_string($sql_order);
- $this->children=album::getRecordsFromQuery("album", $sql);
+ $this->children=album::getRecordsFromQuery($sql);
return $this->children;
}
@@ -193,7 +203,7 @@ public function getChildrenForUser($order=null) {
" GROUP BY album_id" .
escape_string($sql_order);
- $this->children=album::getRecordsFromQuery("album", $sql);
+ $this->children=album::getRecordsFromQuery($sql);
return $this->children;
}
@@ -462,7 +472,7 @@ function getCoverphoto($autothumb=null,$children=null) {
" and gp.access_level >= p.level " .
$order;
}
- $coverphotos=photo::getRecordsFromQuery("photo", $sql);
+ $coverphotos=photo::getRecordsFromQuery($sql);
$coverphoto=array_shift($coverphotos);
}
@@ -498,7 +508,7 @@ public static function getByName($name) {
$query = "select album_id from " . DB_PREFIX . "albums where $where";
- return album::getRecordsFromQuery("album", $query);
+ return album::getRecordsFromQuery($query);
}
/**
@@ -543,7 +553,7 @@ public static function getTopN() {
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
}
- return parent::getTopNfromSQL("album", $sql);
+ return parent::getTopNfromSQL($sql);
}
@@ -566,7 +576,7 @@ function get_albums($user = null) {
$sql = "select * from " . DB_PREFIX . "albums order by album";
}
- return album::getRecordsFromQuery("album", $sql);
+ return album::getRecordsFromQuery($sql);
}
function get_newer_albums($user_id, $date = null) {
@@ -579,7 +589,7 @@ function get_newer_albums($user_id, $date = null) {
"' AND gp.changedate > '" . escape_string($date) . "' " .
"ORDER BY a.album_id";
- return album::getRecordsFromQuery("album", $sql);
+ return album::getRecordsFromQuery($sql);
}
function get_album_count($user = null) {
View
@@ -32,11 +32,21 @@
*/
class category extends zophTreeTable implements Organizer {
+ /** @var string The name of the database table */
+ protected static $table_name="categories";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("category_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("category");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="categories.php?parent_category_id=";
+
var $photoCount;
function __construct($id = 0) {
if($id && !is_numeric($id)) { die("category_id must be numeric"); }
- parent::__construct("categories", array("category_id"), array("category"));
$this->set("category_id", $id);
}
@@ -101,7 +111,7 @@ public function getChildren($order=null) {
" GROUP BY c.category_id " .
$order;
- $this->children=category::getRecordsFromQuery("category", $sql);
+ $this->children=category::getRecordsFromQuery($sql);
return $this->children;
}
@@ -288,7 +298,7 @@ function getCoverphoto($autothumb=null,$children=null) {
" AND gp.access_level >= p.level " .
$order;
}
- $coverphotos=photo::getRecordsFromQuery("photo", $sql);
+ $coverphotos=photo::getRecordsFromQuery($sql);
$coverphoto=array_shift($coverphotos);
}
@@ -401,7 +411,7 @@ public static function getByName($name) {
$query = "select category_id from " . DB_PREFIX . "categories where $where";
- return category::getRecordsFromQuery("category", $query);
+ return category::getRecordsFromQuery($query);
}
/**
@@ -448,7 +458,7 @@ public static function getTopN() {
"LIMIT 0, " . escape_string($user->prefs->get("reports_top_n"));
}
- return parent::getTopNfromSQL("category", $sql);
+ return parent::getTopNfromSQL($sql);
}
}
@@ -489,7 +499,7 @@ function get_category_count($user) {
$sql =
"SELECT category_id, parent_category_id FROM " .
DB_PREFIX . "categories as c";
- $cats=category::getRecordsFromQuery("category", $sql);
+ $cats=category::getRecordsFromQuery($sql);
$cat_clean=remove_empty($cats);
return count($cat_clean);
} else {
@@ -27,6 +27,18 @@
* @author Jeroen Roos
*/
abstract class confItem extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="conf";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("conf_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = true;
+ /** @var string URL for this class */
+ protected static $url="config.php#";
+
+
/** @var string Label to display */
protected $label;
/** @var string Longer description of item */
@@ -39,20 +51,15 @@
protected $required=false;
/** @var bool internal, internal settings can not be changed from webinterface */
protected $internal=false;
- /** @var array fields for database */
- public $fields=array();
/**
* Create confItem object
* @param string id, to fetch object from database.
* @retrun confItem new object
*/
public function __construct($id = 0) {
- $this->keepKeys=true;
if($id === 0 || preg_match("/^[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/", $id)) {
- parent::__construct("conf", array("conf_id"), array(""));
$this->set("conf_id", $id);
-
} else {
log::msg("Illegal configuration id", log::FATAL, log::VARS);
}
@@ -32,6 +32,17 @@
*/
class photoRelation extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="photo_relations";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("photo_id_1", "photo_id_2");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array();
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = true;
+ /** @var string URL for this class */
+ protected static $url="photo.php?photo_id=";
+
/**
* Create a new relation between two photos.
* order of the photos is not important
@@ -40,10 +51,8 @@ class photoRelation extends zophTable {
* @return photoRelation newly created photoRelation
*/
public function __construct(photo $photo_1, photo $photo_2) {
- parent::__construct("photo_relations", array("photo_id_1", "photo_id_2"), array(""));
$this->set("photo_id_1", $photo_1->getId());
$this->set("photo_id_2", $photo_2->getId());
- $this->keepKeys=true;
}
/**
@@ -133,7 +142,7 @@ public static function getRelated(photo $photo) {
" UNION SELECT photo_id_2 AS photo_id FROM " .
DB_PREFIX . "photo_relations WHERE" .
" photo_id_1 = " . (int) $photo->getId();
- $related=photo::getRecordsFromQuery("photo", $sql);
+ $related=photo::getRecordsFromQuery($sql);
return $related;
}
View
@@ -28,6 +28,17 @@
*/
class rating extends zophTable {
+ /** @var string The name of the database table */
+ protected static $table_name="photo_ratings";
+ /** @var array List of primary keys */
+ protected static $primary_keys=array("rating_id");
+ /** @var array Fields that may not be empty */
+ protected static $not_null=array("photo_id", "rating", "user_id");
+ /** @var bool keep keys with insert. In most cases the keys are set by the db with auto_increment */
+ protected static $keepKeys = false;
+ /** @var string URL for this class */
+ protected static $url="photo.php?rating_id=";
+
/**
* Create new rating object
@@ -36,7 +47,6 @@ class rating extends zophTable {
*/
public function __construct($id = 0) {
if($id && !is_numeric($id)) { die("rating_id must be numeric"); }
- parent::__construct("photo_ratings", array("rating_id"), array("photo_id", "rating", "user_id"));
$this->set("rating_id", $id);
}
@@ -63,7 +73,7 @@ public static function getRatings(photo $photo = null, user $user = null) {
}
}
- return self::getRecords("rating", null, $constraints);
+ return self::getRecords(null, $constraints);
}
/**
@@ -256,7 +256,7 @@ public static function createSelectArray(array $records, array $name_fields) {
foreach ($records as $rec) {
// this only makes sense when there is one key
- $id = $rec->get($rec->primary_keys[0]);
+ $id = $rec->getId();
$name = "";
foreach ($name_fields as $n) {
Oops, something went wrong.

0 comments on commit 9c88955

Please sign in to comment.