[Customisation Database Commits] r27 - in /trunk/customisationdb: develop/tests/class_review.php includes/titania/class_review.php includes/titania/classbase.php
Andreas Fischer
bantu at phpbb.de
Mon May 19 22:51:02 CEST 2008
Author: bantu
Date: Mon May 19 22:51:01 2008
New Revision: 27
Log:
And the updated version with a separate class with magic methods for getting and setting class properties.
Added:
trunk/customisationdb/includes/titania/classbase.php (with props)
Modified:
trunk/customisationdb/develop/tests/class_review.php
trunk/customisationdb/includes/titania/class_review.php
Modified: trunk/customisationdb/develop/tests/class_review.php
==============================================================================
*** trunk/customisationdb/develop/tests/class_review.php (original)
--- trunk/customisationdb/develop/tests/class_review.php Mon May 19 22:51:01 2008
***************
*** 17,23 ****
$starttime = $starttime[1] + $starttime[0];
define('IN_PHPBB', true);
! $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/titania/common.' . $phpEx);
--- 17,23 ----
$starttime = $starttime[1] + $starttime[0];
define('IN_PHPBB', true);
! $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../../';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/titania/common.' . $phpEx);
***************
*** 31,48 ****
echo '<pre>';
// Inserting
! $review = new review();
! $review->set_user_id(2);
! $review->set_rating(5);
$review->submit();
// Getting
! /*$review = new review(1);*/
// Updating
! /*$review = new review(2);
$review->set_text('[b]Blub blub[/b] :-P');
! $review->set_status(0);
$review->generate_text_for_storage(true, true, true);
$review->submit();*/
--- 31,48 ----
echo '<pre>';
// Inserting
! $review = new titania_review();
! $review->review_user_id = 2;
! $review->review_rating = 5;
$review->submit();
// Getting
! /*$review = new titania_review(1);*/
// Updating
! /*$review = new titania_review(2);
$review->set_text('[b]Blub blub[/b] :-P');
! $review->review_status = 0;
$review->generate_text_for_storage(true, true, true);
$review->submit();*/
Modified: trunk/customisationdb/includes/titania/class_review.php
==============================================================================
*** trunk/customisationdb/includes/titania/class_review.php (original)
--- trunk/customisationdb/includes/titania/class_review.php Mon May 19 22:51:01 2008
***************
*** 16,46 ****
exit;
}
/**
* Class to abstract contribution reviews.
* @package Titania
*/
! class review
{
// Table properties
! private $review_id;
! private $contrib_id = 0;
! private $review_text = '';
! private $review_text_bitfield = '';
! private $review_text_uid = '';
! private $review_text_options = 7;
! private $review_rating = 3;
! private $review_user_id = 0;
! private $review_status = 1;
! private $review_time = 0;
// Database data
private $data = array();
! // Additional properties
! private $review_text_for_storage = '';
! private $review_text_for_display = '';
! private $review_text_for_edit = '';
// Constructor
public function __construct($review_id = false)
--- 16,51 ----
exit;
}
+ if (!class_exists('titania_classbase'))
+ {
+ require($phpbb_root_path . 'includes/titania/classbase.' . $phpEx);
+ }
+
/**
* Class to abstract contribution reviews.
* @package Titania
*/
! class titania_review extends titania_classbase
{
// Table properties
! protected $properties = array(
! 'review_id' => 0,
! 'contrib_id' => 0,
! 'review_text' => '',
! 'review_text_bitfield' => '',
! 'review_text_uid' => '',
! 'review_text_options' => 7,
! 'review_rating' => 3,
! 'review_user_id' => 0,
! 'review_status' => 1,
! 'review_time' => 0,
! );
// Database data
private $data = array();
! // Additional attributes
! private $text_parsed_for_storage = false;
// Constructor
public function __construct($review_id = false)
***************
*** 48,59 ****
if ($review_id === false)
{
// We're going to create a new review
! $this->review_time = (int) time();
}
else
{
// We're going to perform operations on an existing review
! $this->load($review_id);
}
}
--- 53,65 ----
if ($review_id === false)
{
// We're going to create a new review
! $this->review_time = time();
}
else
{
// We're going to perform operations on an existing review
! $this->review_id = $review_id;
! $this->load();
}
}
***************
*** 109,266 ****
{
global $db;
! $sql = 'INSERT INTO ' . CDB_REVIEWS_TABLE . ' ' . $db->sql_build_array('INSERT', array(
! 'contrib_id' => $this->contrib_id,
! 'review_text' => $this->review_text,
! 'review_text_bitfield' => $this->review_text_bitfield,
! 'review_text_uid' => $this->review_text_uid,
! 'review_text_options' => $this->review_text_options,
! 'review_rating' => $this->review_rating,
! 'review_user_id' => $this->review_user_id,
! 'review_status' => $this->review_status,
! 'review_time' => $this->review_time,
! ));
$db->sql_query($sql);
! $this->review_id = (int) $db->sql_nextid();
}
// Get review data from the database
! private function load($review_id)
{
global $db;
$sql = 'SELECT *
FROM ' . CDB_REVIEWS_TABLE . '
! WHERE review_id = ' . (int) $review_id;
$result = $db->sql_query($sql);
$this->data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$this->set_text($this->data['review_text'], $this->data['review_text_bitfield'], $this->data['review_text_uid'], $this->data['review_text_options']);
- $this->text_parsed_for_storage = true;
! $this->set_review_id($this->data['review_id']);
! $this->set_contrib_id($this->data['contrib_id']);
! $this->set_rating($this->data['review_rating']);
! $this->set_user_id($this->data['review_user_id']);
! $this->set_status($this->data['review_status']);
! $this->review_time = (int) $this->data['review_time'];
}
// Parse text for db
public function generate_text_for_storage($allow_bbcode, $allow_urls, $allow_smilies)
{
! generate_text_for_storage($this->review_text, $this->review_text_uid, $this->review_text_bitfield, $this->review_text_options, $allow_bbcode, $allow_urls, $allow_smilies);
$this->text_parsed_for_storage = true;
}
// Parse text for display
private function generate_text_for_display()
{
! $this->review_text = generate_text_for_display($this->review_text, $this->review_text_uid, $this->review_text_bitfield, $this->review_text_options);
! $this->text_parsed_for_storage = false;
}
// Parse text for edit
private function generate_text_for_edit()
{
! $this->review_text = generate_text_for_edit($this->review_text, $this->review_text_uid, $this->review_text_options);
! $this->text_parsed_for_storage = false;
}
// Getters
- public function get_review_id()
- {
- return $this->review_id;
- }
-
- public function get_contrib_id()
- {
- return $this->contrib_id;
- }
-
public function get_text($editable = false)
{
if ($editable)
{
! $this->generate_text_for_edit();
}
else
{
! $this->generate_text_for_display();
}
-
- return $this->review_text;
- }
-
- public function get_rating()
- {
- return $this->review_rating;
- }
-
- public function get_user_id()
- {
- return $this->review_user_id;
- }
-
- public function get_status()
- {
- return $this->review_status;
}
- public function get_time()
- {
- return $this->review_time;
- }
-
-
// Setters
- public function set_review_id($review_id)
- {
- $this->review_id = (int) $review_id;
- }
-
- public function set_contrib_id($contrib_id)
- {
- $this->contrib_id = (int) $contrib_id;
- }
-
public function set_text($text, $uid = false, $bitfield = false, $flags = false)
{
! $this->review_text = (string) $text;
$this->text_parsed_for_storage = false;
if ($uid !== false)
{
! $this->review_text_uid = (string) $uid;
}
if ($bitfield !== false)
{
! $this->review_text_bitfield = (string) $bitfield;
}
if ($flags !== false)
{
! $this->review_text_options = (int) $flags;
}
}
-
- public function set_rating($rating)
- {
- $this->review_rating = (int) $rating;
- }
-
- public function set_user_id($user_id)
- {
- $this->review_user_id = (int) $user_id;
- }
-
- public function set_status($status)
- {
- $this->review_status = (int) $status;
- }
}
\ No newline at end of file
--- 115,225 ----
{
global $db;
! $sql_array = array();
! foreach ($this->properties as $key => $value)
! {
! $sql_array[$key] = $value;
! }
+ $sql = 'INSERT INTO ' . CDB_REVIEWS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_array);
$db->sql_query($sql);
! $this->review_id = $db->sql_nextid();
}
// Get review data from the database
! private function load()
{
global $db;
$sql = 'SELECT *
FROM ' . CDB_REVIEWS_TABLE . '
! WHERE review_id = ' . $this->review_id;
$result = $db->sql_query($sql);
$this->data = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$this->set_text($this->data['review_text'], $this->data['review_text_bitfield'], $this->data['review_text_uid'], $this->data['review_text_options']);
! $this->review_id = $this->data['review_id'];
! $this->contrib_id = $this->data['contrib_id'];
! $this->review_rating = $this->data['review_rating'];
! $this->review_user_id = $this->data['review_user_id'];
! $this->review_status = $this->data['review_status'];
! $this->review_time = $this->data['review_time'];
! $this->text_parsed_for_storage = true;
}
// Parse text for db
public function generate_text_for_storage($allow_bbcode, $allow_urls, $allow_smilies)
{
! // As per naderman
! $review_text = $this->review_text;
! $review_text_uid = $this->review_text_uid;
! $review_text_bitfield = $this->review_text_bitfield;
! $review_text_options = $this->review_text_options;
!
! generate_text_for_storage($review_text, $review_text_uid, $review_text_bitfield, $review_text_options, $allow_bbcode, $allow_urls, $allow_smilies);
!
! $this->review_text = $review_text;
! $this->review_text_uid = $review_text_uid;
! $this->review_text_bitfield = $review_text_bitfield;
! $this->review_text_options = $review_text_options;
!
$this->text_parsed_for_storage = true;
}
// Parse text for display
private function generate_text_for_display()
{
! return generate_text_for_display($this->review_text, $this->review_text_uid, $this->review_text_bitfield, $this->review_text_options);
}
// Parse text for edit
private function generate_text_for_edit()
{
! return generate_text_for_edit($this->review_text, $this->review_text_uid, $this->review_text_options);
}
// Getters
public function get_text($editable = false)
{
+ // Text needs to be from database or parsed for database.
+ if (!$this->text_parsed_for_storage)
+ {
+ $this->generate_text_for_storage(false, false, false);
+ }
+
if ($editable)
{
! return $this->generate_text_for_edit();
}
else
{
! return $this->generate_text_for_display();
}
}
// Setters
public function set_text($text, $uid = false, $bitfield = false, $flags = false)
{
! $this->review_text = $text;
$this->text_parsed_for_storage = false;
if ($uid !== false)
{
! $this->review_text_uid = $uid;
}
if ($bitfield !== false)
{
! $this->review_text_bitfield = $bitfield;
}
if ($flags !== false)
{
! $this->review_text_options = $flags;
}
}
}
\ No newline at end of file
Added: trunk/customisationdb/includes/titania/classbase.php
==============================================================================
*** trunk/customisationdb/includes/titania/classbase.php (added)
--- trunk/customisationdb/includes/titania/classbase.php Mon May 19 22:51:01 2008
***************
*** 0 ****
--- 1,67 ----
+ <?php
+ /**
+ *
+ * @package Titania
+ * @version $Id$
+ * @copyright (c) 2008 phpBB Customisation Database Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
+ *
+ */
+
+ /**
+ * @ignore
+ */
+ if (!defined('IN_PHPBB'))
+ {
+ exit;
+ }
+
+ /**
+ * Basic class providing basic magic methods.
+ * @package Titania
+ */
+ class titania_classbase
+ {
+ // Holds the properties of this class.
+ protected $properties = array();
+
+ // Returns a specific property $name
+ public function __get($name)
+ {
+ if (isset($this->properties[$name]))
+ {
+ return $this->properties[$name];
+ }
+ else
+ {
+ throw new exception ('Unknown property: ' . $name);
+ }
+ }
+
+ // Sets the property $name to $value
+ public function __set($name, $value)
+ {
+ if (isset($this->properties[$name]) && !is_array($this->properties[$name]))
+ {
+ $type = gettype($this->properties[$name]);
+ }
+
+ $this->properties[$name] = $value;
+
+ if (isset($type))
+ {
+ settype($this->properties[$name], $type);
+ }
+ }
+
+ // Checks if a property is set
+ public function __isset($name)
+ {
+ if (isset($this->properties[$name]))
+ {
+ return true;
+ }
+
+ return false;
+ }
+ }
\ No newline at end of file
Propchange: trunk/customisationdb/includes/titania/classbase.php
------------------------------------------------------------------------------
svn:eol-style = LF
Propchange: trunk/customisationdb/includes/titania/classbase.php
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: trunk/customisationdb/includes/titania/classbase.php
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the customisationdb-commits
mailing list