mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-19 20:13:27 +02:00
Use $db->exec where appropriate
May bring some performance boost (little, but still)
This commit is contained in:
@@ -15,11 +15,11 @@
|
||||
|
||||
/**
|
||||
* Wrapper for house information.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Unlike other {@link OTS_Base_DAO OTS_Base_DAO} child classes, OTS_House bases not only on database, but also loads some additional info from XML DOM node. It can't be load - it is always initialised with {@link http://www.php.net/manual/en/ref.dom.php DOMElement} object. Saving will only update database row - won't change XML data. Same about using {@link OTS_House::delete() delete() method}.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @package POT
|
||||
* @version 0.1.3
|
||||
* @property OTS_Player $owner House owner.
|
||||
@@ -38,23 +38,23 @@ class OTS_House extends OTS_Row_DAO
|
||||
{
|
||||
/**
|
||||
* House rent info.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $data = array();
|
||||
|
||||
|
||||
//private $columns = array('id', 'name', 'owner', 'paid', 'warnings', 'rent', 'beds');
|
||||
|
||||
/**
|
||||
* Information handler.
|
||||
*
|
||||
*
|
||||
* @var DOMElement
|
||||
*/
|
||||
private $element;
|
||||
|
||||
/**
|
||||
* Tiles list.
|
||||
*
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $tiles = array();
|
||||
@@ -67,7 +67,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function find($name)
|
||||
{
|
||||
// finds player's ID
|
||||
@@ -83,7 +83,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
public function setElement(DOMElement $element) {
|
||||
$this->element = $element;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks if object is loaded.
|
||||
*
|
||||
@@ -96,11 +96,11 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* Allows object serialisation.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return array List of properties that should be saved.
|
||||
*/
|
||||
public function __sleep()
|
||||
@@ -110,7 +110,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Saves info in database.
|
||||
*
|
||||
*
|
||||
* @throws PDOException On PDO operation error.
|
||||
*/
|
||||
public function save()
|
||||
@@ -118,7 +118,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
// inserts new record
|
||||
if( empty($this->data) )
|
||||
{
|
||||
$this->db->query('INSERT INTO ' . $this->db->tableName('houses') . ' (' . $this->db->fieldName('id') . ', ' . $this->db->fieldName('owner') . ', ' . $this->db->fieldName('paid') . ', ' . $this->db->fieldName('warnings') . ') VALUES (' . $this->getId() . ', ' . $this->data['owner'] . ', ' . $this->data['paid'] . ', ' . $this->data['warnings'] . ')');
|
||||
$this->db->exec('INSERT INTO ' . $this->db->tableName('houses') . ' (' . $this->db->fieldName('id') . ', ' . $this->db->fieldName('owner') . ', ' . $this->db->fieldName('paid') . ', ' . $this->db->fieldName('warnings') . ') VALUES (' . $this->getId() . ', ' . $this->data['owner'] . ', ' . $this->data['paid'] . ', ' . $this->data['warnings'] . ')');
|
||||
}
|
||||
// updates previous one
|
||||
else
|
||||
@@ -129,13 +129,13 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Deletes house info from database.
|
||||
*
|
||||
*
|
||||
* @throws PDOException On PDO operation error.
|
||||
*/
|
||||
public function delete()
|
||||
{
|
||||
// deletes row from database
|
||||
$this->db->query('DELETE FROM ' . $this->db->tableName('houses') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
|
||||
$this->db->exec('DELETE FROM ' . $this->db->tableName('houses') . ' WHERE ' . $this->db->fieldName('id') . ' = ' . $this->data['id']);
|
||||
|
||||
// resets object handle
|
||||
$this->data = array();
|
||||
@@ -143,7 +143,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns house's ID.
|
||||
*
|
||||
*
|
||||
* @return int House ID.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -160,7 +160,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Return house's name.
|
||||
*
|
||||
*
|
||||
* @return string House name.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -169,7 +169,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
if(isset($this->data['name'])) {
|
||||
return $this->data['name'];
|
||||
}
|
||||
|
||||
|
||||
if($this->element) {
|
||||
return $this->element->getAttribute('name');
|
||||
}
|
||||
@@ -177,7 +177,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns town ID in which house is located.
|
||||
*
|
||||
*
|
||||
* @return int Town ID.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -192,18 +192,18 @@ class OTS_House extends OTS_Row_DAO
|
||||
if(isset($this->data['townid'])) {
|
||||
return $this->data['townid'];
|
||||
}
|
||||
|
||||
|
||||
if($this->element) {
|
||||
return (int) $this->element->getAttribute('townid');
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns town name.
|
||||
*
|
||||
*
|
||||
* @return string Town name.
|
||||
* @throws E_OTS_NotLoaded When map file is not loaded to fetch towns names.
|
||||
*/
|
||||
@@ -214,7 +214,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns house rent cost.
|
||||
*
|
||||
*
|
||||
* @return int Rent cost.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -225,7 +225,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns house size.
|
||||
*
|
||||
*
|
||||
* @return int House size.
|
||||
* @throws DOMException On DOM operation error.
|
||||
*/
|
||||
@@ -236,7 +236,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns entry position.
|
||||
*
|
||||
*
|
||||
* @return OTS_MapCoords Entry coordinations on map.
|
||||
*/
|
||||
public function getEntry()
|
||||
@@ -248,12 +248,12 @@ class OTS_House extends OTS_Row_DAO
|
||||
if( isset($this->data['owner'])) {
|
||||
return $this->data['owner'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Returns current house owner.
|
||||
*
|
||||
*
|
||||
* @return OTS_Player|null Player that currently owns house (null if there is no owner).
|
||||
*/
|
||||
public function getOwner()
|
||||
@@ -273,11 +273,11 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Sets house owner.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This method only updates object state. To save changes in database you need to use {@link OTS_House::save() save() method} to flush changed to database.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param OTS_Player $player House owner to be set.
|
||||
* @throws E_OTS_NotLoaded If given <var>$player</var> object is not loaded.
|
||||
*/
|
||||
@@ -288,7 +288,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns paid date.
|
||||
*
|
||||
*
|
||||
* @return int|false Date timestamp until which house is rent (false if none).
|
||||
*/
|
||||
public function getPaid()
|
||||
@@ -306,11 +306,11 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Sets paid date.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This method only updates object state. To save changes in database you need to use {@link OTS_House::save() save() method} to flush changed to database.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param int $paid Sets paid timestamp to passed one.
|
||||
*/
|
||||
public function setPaid($paid)
|
||||
@@ -320,7 +320,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns house warnings.
|
||||
*
|
||||
*
|
||||
* @version 0.1.2
|
||||
* @return int|false Warnings text (false if none).
|
||||
*/
|
||||
@@ -339,11 +339,11 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Sets house warnings.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This method only updates object state. To save changes in database you need to use {@link OTS_House::save() save() method} to flush changed to database.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.2
|
||||
* @param int $warnings Sets house warnings.
|
||||
*/
|
||||
@@ -356,10 +356,10 @@ class OTS_House extends OTS_Row_DAO
|
||||
if(isset($this->data['bid'])) {
|
||||
return $this->data['bid'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function setBid($bid) {
|
||||
$this->data['bid'] = $bid;
|
||||
}
|
||||
@@ -368,10 +368,10 @@ class OTS_House extends OTS_Row_DAO
|
||||
if(isset($this->data['bid_end'])) {
|
||||
return $this->data['bid_end'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function setBidEnd($bid_end) {
|
||||
$this->data['bid_end'] = $bid_end;
|
||||
}
|
||||
@@ -380,7 +380,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
if(isset($this->data['last_bid'])) {
|
||||
return $this->data['last_bid'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -392,16 +392,16 @@ class OTS_House extends OTS_Row_DAO
|
||||
if(isset($this->data['highest_bidder'])) {
|
||||
return $this->data['highest_bidder'];
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function setHighestBidder($highest_bidder) {
|
||||
$this->data['highest_bidder'] = $highest_bidder;
|
||||
}
|
||||
/**
|
||||
* Adds tile to house.
|
||||
*
|
||||
*
|
||||
* @param OTS_MapCoords $tile Tile to be added.
|
||||
*/
|
||||
public function addTile(OTS_MapCoords $tile)
|
||||
@@ -411,11 +411,11 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns tiles list.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* This returns list of coords of tiles used by this house on map. It will succeed only if house object was created during map loading with houses file opened to assign loaded tiles.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @return array List of tiles.
|
||||
*/
|
||||
public function getTiles()
|
||||
@@ -425,7 +425,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* @param string $name Property name.
|
||||
* @return mixed Property value.
|
||||
* @throws E_OTS_NotLoaded When atempt to read info about map while map not being loaded.
|
||||
@@ -476,7 +476,7 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Magic PHP5 method.
|
||||
*
|
||||
*
|
||||
* @param string $name Property name.
|
||||
* @param mixed $value Property value.
|
||||
* @throws E_OTS_NotLoaded If passed parameter for owner field won't be loaded.
|
||||
@@ -505,11 +505,11 @@ class OTS_House extends OTS_Row_DAO
|
||||
|
||||
/**
|
||||
* Returns string representation of object.
|
||||
*
|
||||
*
|
||||
* <p>
|
||||
* If any display driver is currently loaded then it uses it's method. Otherwise just returns house ID.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @version 0.1.3
|
||||
* @since 0.1.3
|
||||
* @return string String representation of object.
|
||||
|
Reference in New Issue
Block a user