[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [6707] Multiple changes and tests to sobim
From: |
Petur Bjorn Thorsteinsson |
Subject: |
[Fmsystem-commits] [6707] Multiple changes and tests to sobim |
Date: |
Mon, 27 Dec 2010 12:29:55 +0000 |
Revision: 6707
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=6707
Author: peturbjorn
Date: 2010-12-27 12:29:55 +0000 (Mon, 27 Dec 2010)
Log Message:
-----------
Multiple changes and tests to sobim
Modified Paths:
--------------
branches/dev-bim2/property/inc/class.sobim.inc.php
branches/dev-bim2/property/tests/BIM/PropertyBimTestSuite.php
branches/dev-bim2/property/tests/BIM/TestSObim.php
Modified: branches/dev-bim2/property/inc/class.sobim.inc.php
===================================================================
--- branches/dev-bim2/property/inc/class.sobim.inc.php 2010-12-27 09:42:50 UTC
(rev 6706)
+++ branches/dev-bim2/property/inc/class.sobim.inc.php 2010-12-27 12:29:55 UTC
(rev 6707)
@@ -1,197 +1,188 @@
<?php
-//phpgw::import_class('property.boitem');
- interface sobim {
-
- const bimItemTable = 'fm_bim_data';
- /*
- * @return array of BIM objects
- */
- public function getAll();
- /*
- * @param int id
- * @return BIMItem
- */
- public function getBimObject($bimObjectId);
-
-
- }
- class sobim_impl implements sobim
- {
- /* @var phpgwapi_db_ */
- private $db;
- public function __construct(& $db) {
- // $this->db = & $GLOBALS['phpgw']->db;
- $this->db = $db;
- }
- /*
- * @return Array an array of BimItem objects
- */
- public function getAll() {
- $sql = 'SELECT fm_bim_data.id, fm_bim_type."name" AS "type",
fm_bim_data.guid, fm_bim_data.xml_representation '.
+interface sobim {
+
+ const bimItemTable = 'fm_bim_data';
+ const bimTypeTable = 'fm_bim_type';
+ /*
+ * @return array of BIM objects
+ */
+ public function getAll();
+ /*
+ * @param int id
+ * @return BIMItem
+ */
+ public function getBimItem($bimObjectId);
+
+ public function addBimItem($bimItem);
+ public function deleteBimItem($guid);
+ public function checkIfBimItemExists($guid);
+}
+class sobim_impl implements sobim
+{
+ /* @var phpgwapi_db_ */
+ private $db;
+
+ public function __construct(& $db) {
+ // $this->db = & $GLOBALS['phpgw']->db;
+ $this->db = $db;
+ }
+ /*
+ * @return Array an array of BimItem objects
+ */
+ public function getAll() {
+ $sql = 'SELECT fm_bim_data.id, fm_bim_type.name AS type,
fm_bim_data.guid, fm_bim_data.xml_representation '.
'FROM public.fm_bim_data,
public.fm_bim_type '.
- 'WHERE fm_bim_data."type" =
fm_bim_type.id;';
- $bimItemArray = array();
- $this->db->query($sql);
- while($this->db->next_record())
- {
- $bimItem = new
BimItem($this->db->f('id'),$this->db->f('guid'), $this->db->f('type'),
$this->db->f('xml_representation'));
- array_push($bimItemArray, $bimItem);
- }
-
- return $bimItemArray;
- }
-
-
- public function getBimObject($bimObjectGuid){
-
- }
-
+ 'WHERE fm_bim_data.type =
fm_bim_type.id';
+ $bimItemArray = array();
+ $this->db->query($sql);
+ while($this->db->next_record())
+ {
+ $bimItem = new
BimItem($this->db->f('id'),$this->db->f('guid'), $this->db->f('type'),
$this->db->f('xml_representation'));
+ array_push($bimItemArray, $bimItem);
+ }
+ return $bimItemArray;
+ }
-
- /**
- * Retreive any number of items.
- * @param array $data
- * @return array Array of zero or more items
- */
- public function read(array $data)
- {
- $select_cols = array(
+ public function getBimItem($bimObjectGuid){
+ $sql = 'SELECT fm_bim_data.id, fm_bim_type.name AS type,
fm_bim_data.guid, fm_bim_data.xml_representation '.
+ 'FROM public.fm_bim_data,
public.fm_bim_type '.
+ 'WHERE fm_bim_data.type =
fm_bim_type.id ' .
+ 'AND fm_bim_data.guid =\''.$bimObjectGuid.'\'';
+ $this->db->query($sql);
+ if($this->db->num_rows() == 0) {
+ throw new Exception('Item not found!');
+ } else {
+ $this->db->next_record();
+ return new
BimItem($this->db->f('id'),$this->db->f('guid'), $this->db->f('type'),
$this->db->f('xml_representation'));
+ }
+ }
+
+ public function addBimItem($bimItem) {
+ /* @var $bimItem BimItem */
+ $sql = "INSERT INTO ".self::bimItemTable." (type, guid,
xml_representation) values (";
+ $sql = $sql."(select id from ".self::bimTypeTable." where name
= '$bimItem->getType()'),";
+ $sql = $sql."'$bimItem->getGuid()', '$bimItem->getXml()')";
+ if(is_null($this->db->query($sql,__LINE__,__FILE__))) {
+ throw new Exception('Query to add item was
unsuccessful');
+ } else {
+ return $this->db->num_rows();
+ }
+ }
+
+ public function checkIfBimItemExists($guid) {
+ $resultAlias = 'test_item_count';
+ $sql = "SELECT count(id) as $resultAlias from
public.".self::bimItemTable." where guid = '$guid'";
+
+ if(is_null($this->db->query($sql,__LINE__,__FILE__))) {
+ throw new Exception('Query to check items was
unsuccessful');
+ } else {
+ $this->db->next_record();
+ $rowCountOfItemTypes = $this->db->f($resultAlias);
+ return (bool)$rowCountOfItemTypes;
+ }
+ }
+ /*
+ * @return number of affected rows
+ */
+ public function deleteBimItem($guid) {
+ $sql = "Delete from public.".self::bimItemTable." where guid =
'$guid'";
+ if(is_null($this->db->query($sql,__LINE__,__FILE__))) {
+ throw new Exception('Query to delete item was
unsuccessful');
+ } else {
+ return $this->db->num_rows();
+ }
+ }
+
+
+
+ /**
+ * Retreive any number of items.
+ * @param array $data
+ * @return array Array of zero or more items
+ */
+ public function read(array $data)
+ {
+
+ $select_cols = array(
'i.id',
'i.group_id',
'i.location_id',
'i.vendor_id',
'i.installed'
- );
- $from_tables = array('fm_item i');
- $joins = array(
+ );
+ $from_tables = array('fm_item i');
+ $joins = array(
//$this->db->left_join.' fm_item_group g ON i.group_id = g.id',
$this->db->left_join.' fm_vendor v ON i.vendor_id = v.id'
- );
- $where_clauses = array(' WHERE 1=1');
+ );
+ $where_clauses = array(' WHERE 1=1');
- if($specific_item_id) {
- // FIXME Sanitize input!!
- $where_clauses[] = "i.id = $specific_item_id";
- }
+ if($specific_item_id) {
+ // FIXME Sanitize input!!
+ $where_clauses[] = "i.id = $specific_item_id";
+ }
- $sql = 'SELECT ' . implode($select_cols, ', ') .
+ $sql = 'SELECT ' . implode($select_cols, ', ') .
' FROM ' . implode($from_tables, ', ') .
- implode($joins, ' ') .
- implode($where_clauses, ' AND ');
-
- $this->db->query($sql);
- $i = 0;
- while($this->db->next_record())
- {
- $items[$i]['id'] = $this->db->f('id');
- $items[$i]['group'] = $this->db->f('group_id');
- $items[$i]['location'] = $this->db->f('location_id');
- $items[$i]['vendor'] = $this->db->f('vendor_id');
- $items[$i]['installed']= $this->db->f('installed');
+ implode($joins, ' ') .
+ implode($where_clauses, ' AND ');
+
+ $this->db->query($sql);
+ $i = 0;
+ while($this->db->next_record())
+ {
+ $items[$i]['id'] = $this->db->f('id');
+ $items[$i]['group'] = $this->db->f('group_id');
+ $items[$i]['location'] = $this->db->f('location_id');
+ $items[$i]['vendor'] = $this->db->f('vendor_id');
+ $items[$i]['installed']= $this->db->f('installed');
- $i++;
- }
+ $i++;
+ }
- return $items;
- }
+ return $items;
+ }
+}
+class BimItem {
+ private $databaseId;
+ private $guid;
+ private $type;
+ private $xml;
+
+ function __construct($databaseId = null, $guid = null, $type = null,
$xml = null) {
+ //$this->databaseId = (is_null($databaseId)) ? null :
(int)$databaseId;
+ $this->databaseId = (int)$databaseId;
+ $this->guid = $guid;
+ $this->type = $type;
+ $this->xml = $xml;
+ }
+ function getDatabaseId() {
+ return $this->databaseId;
+ }
+ function setDatabaseId($databaseId) {
+ $this->databaseId = $databaseId;
+ }
+ function getGuid() {
+ return $this->guid;
+ }
+ function getType() {
+ return $this->type;
+ }
+ function setType($type) {
+ $this->type = $type;
+ }
+ function getXml() {
+ return $this->xml;
+ }
+
+
+}
- /**
- * Creates fully populated objects out of an item array.
- *
- * @param array $items Array of items in the same format as that
returned from get_items().
- * @return mixed Array of item objects og null if failed.
- */
- private function populate(array $items)
- {
- if(!is_array($items))
- {
- return null;
- }
- $return_objects = array();
- $sogroup = property_sogroup::singleton();
-
- foreach($items as $item)
- {
- $item_obj = new property_boitem($items['installed_date']);
- $item_obj->set_group($sogroup->get($item['group_id']));
-
- $return_objects[] = $item_obj;
- }
-
- return $return_objects;
- }
-
-
- /**
- * Save changes on an item to database or insert a new one if ID is
empty.
- *
- * @param property_boitem $obj
- */
- public function save(property_boitem $obj)
- {
- // If item has an ID, do an update, otherwise, do an insert
- $ins_or_upd = ($obj->get_id() != null ? 'UPDATE' : 'INSERT INTO');
- $table = 'fm_item';
- $cols = array('id', 'group_id', 'location_id', 'vendor_id',
'installed');
- $values = array($obj->get_id(),
- $obj->get_group()->get_id(),
- $obj->get_location_id(),
- $obj->get_vendor_id(),
- $obj->get_installed_date());
- }
-
-
- /**
- * Get total number of records (rows) in item table
- *
- * @return integer No. of records
- */
- public function total_records()
- {
- $sql = 'SELECT COUNT(id) AS rows FROM fm_item';
-
- $this->db->query($sql);
- // Move pointer to first row
- $this->db->next_record();
- // Get value of 'rows' column
- return (int) $this->db->f('rows');
- }
- }
-
- class BimItem {
- private $databaseId;
- private $guid;
- private $type;
- private $xml;
-
- function __construct($databaseId = null, $guid = null, $type = null,
$xml = null) {
- //$this->databaseId = (is_null($databaseId)) ? null :
(int)$databaseId;
- $this->databaseId = (int)$databaseId;
- $this->guid = $guid;
- $this->type = $type;
- $this->xml = $xml;
- }
- function getDatabaseId() {
- return $this->databaseId;
- }
- function getGuid() {
- return $this->guid;
- }
- function getType() {
- return $this->type;
- }
- function getXml() {
- return $this->xml;
- }
-
- }
-
-
Modified: branches/dev-bim2/property/tests/BIM/PropertyBimTestSuite.php
===================================================================
--- branches/dev-bim2/property/tests/BIM/PropertyBimTestSuite.php
2010-12-27 09:42:50 UTC (rev 6706)
+++ branches/dev-bim2/property/tests/BIM/PropertyBimTestSuite.php
2010-12-27 12:29:55 UTC (rev 6707)
@@ -18,6 +18,7 @@
define('PHPGW_API_UNIT_TEST_PATH', dirname(__FILE__));
+
include('..\..\inc\class.sobim.inc.php');
include('..\..\inc\class.sobimtype.inc.php');
@@ -103,6 +104,8 @@
*/
public function tearDown()
{
+ //$this->removeTestItems();
+ //$this->removeTestTypes();
$GLOBALS['phpgw']->session->destroy(self::$sessionid);
}
@@ -127,7 +130,6 @@
//throw new Exception('At least one item already exists
in database');
} else {
- echo "no";
$this->insertTestItem($this->projectXml->asXML(),
$this->projectType, $this->projectGuid);
$this->insertTestItem($this->buildingStorey1xml->asXML(),
$this->buildingStorey1Type, $this->buildingStorey1Guid);
$this->insertTestItem($this->buildingStorey2xml->asXML(),
$this->buildingStorey2Type, $this->buildingStorey2Guid);
Modified: branches/dev-bim2/property/tests/BIM/TestSObim.php
===================================================================
--- branches/dev-bim2/property/tests/BIM/TestSObim.php 2010-12-27 09:42:50 UTC
(rev 6706)
+++ branches/dev-bim2/property/tests/BIM/TestSObim.php 2010-12-27 12:29:55 UTC
(rev 6707)
@@ -23,7 +23,7 @@
-class TestSOnotes extends PHPUnit_Framework_TestCase
+class TestSObim extends PHPUnit_Framework_TestCase
{
private $bimTypeTableName = 'fm_bim_type';
private $bimItemTableName = 'fm_bim_data';
@@ -72,8 +72,7 @@
*/
protected function tearDown()
{
- //$this->removeTestItems();
- //$this->removeTestTypes();
+
}
@@ -113,6 +112,31 @@
}
}
-
+ public function testGetBimItem() {
+ $sobim = new sobim_impl($this->db);
+ /* @var $bimItem BimItem */
+ $bimItem = $sobim->getBimItem($this->projectGuid);
+ $this->assertNotNull($bimItem);
+ $bimItem->setDatabaseId(0);
+ $localBimItem = new BimItem(0, $this->projectGuid,
$this->projectType, $this->projectXml->asXML());
+ $this->assertEquals($localBimItem, $bimItem);
+ }
+ public function testIfBimItemExists() {
+ $sobim = new sobim_impl($this->db);
+
$this->assertTrue($sobim->checkIfBimItemExists($this->projectGuid));
+ }
+
+ public function testDeleteBimItem() {
+ $sobim = new sobim_impl($this->db);
+ $this->assertEquals(1,
$sobim->deleteBimItem($this->projectGuid));
+ }
+
+ public function testAddBimItem() {
+ $sobim = new sobim_impl($this->db);
+ $itemToBeAdded = new BimItem(null, $this->projectGuid,
$this->projectType, $this->projectXml->asXML());
+ var_dump($itemToBeAdded);
+ $this->assertEquals(1, $sobim->addBimItem($itemToBeAdded));
+ }
+
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [6707] Multiple changes and tests to sobim,
Petur Bjorn Thorsteinsson <=