[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [8267] controller: License informtation, ID-tag - and
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [8267] controller: License informtation, ID-tag - and formatting |
Date: |
Sun, 11 Dec 2011 12:27:18 +0000 |
Revision: 8267
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=8267
Author: sigurdne
Date: 2011-12-11 12:27:18 +0000 (Sun, 11 Dec 2011)
Log Message:
-----------
controller: License informtation, ID-tag - and formatting
Modified Paths:
--------------
trunk/controller/inc/class.menu.inc.php
trunk/controller/inc/class.socheck_item.inc.php
trunk/controller/inc/class.socheck_list.inc.php
trunk/controller/inc/class.socommon.inc.php
trunk/controller/inc/class.socontrol.inc.php
trunk/controller/inc/class.socontrol_area.inc.php
trunk/controller/inc/class.socontrol_group.inc.php
trunk/controller/inc/class.socontrol_group_list.inc.php
trunk/controller/inc/class.socontrol_item.inc.php
trunk/controller/inc/class.socontrol_item_list.inc.php
trunk/controller/inc/class.soprocedure.inc.php
trunk/controller/inc/class.uicheck_list.inc.php
trunk/controller/inc/class.uicheck_list_for_component.inc.php
trunk/controller/inc/class.uicheck_list_for_location.inc.php
trunk/controller/inc/class.uicommon.inc.php
trunk/controller/inc/class.uicontrol.inc.php
trunk/controller/inc/class.uicontrol_group.inc.php
trunk/controller/inc/class.uicontrol_item.inc.php
trunk/controller/inc/class.uilocation_check_list.inc.php
trunk/controller/inc/class.uiprocedure.inc.php
trunk/controller/inc/helper/class.check_list_status_info.inc.php
trunk/controller/inc/hook_home.inc.php
trunk/controller/inc/model/class.check_item.inc.php
trunk/controller/inc/model/class.check_list.inc.php
trunk/controller/inc/model/class.control.inc.php
trunk/controller/inc/model/class.control_area.inc.php
trunk/controller/inc/model/class.control_group.inc.php
trunk/controller/inc/model/class.control_group_list.inc.php
trunk/controller/inc/model/class.control_item.inc.php
trunk/controller/inc/model/class.control_item_list.inc.php
trunk/controller/inc/model/class.model.inc.php
trunk/controller/inc/model/class.procedure.inc.php
trunk/controller/inc/model/class.schedule.inc.php
trunk/controller/templates/base/add_component_to_control.xsl
trunk/controller/templates/base/add_location_to_control.xsl
trunk/controller/templates/base/app_data.xsl
trunk/controller/templates/base/choose_control_items.xsl
trunk/controller/templates/base/common.xsl
trunk/controller/templates/base/component.xsl
trunk/controller/templates/base/control.xsl
trunk/controller/templates/base/control_check_lists.xsl
trunk/controller/templates/base/control_component.xsl
trunk/controller/templates/base/control_component_tabs.xsl
trunk/controller/templates/base/control_group.xsl
trunk/controller/templates/base/control_group_items.xsl
trunk/controller/templates/base/control_group_tabs.xsl
trunk/controller/templates/base/control_groups.xsl
trunk/controller/templates/base/control_item.xsl
trunk/controller/templates/base/control_location_tabs.xsl
trunk/controller/templates/base/control_locations.xsl
trunk/controller/templates/base/control_tabs.xsl
trunk/controller/templates/base/datatable.xsl
trunk/controller/templates/base/edit_check_list.xsl
trunk/controller/templates/base/procedure_item.xsl
trunk/controller/templates/base/sort_check_list.xsl
trunk/controller/templates/base/tab_view_check_lists.xsl
trunk/controller/templates/base/view_agg_check_lists_for_location_month.xsl
trunk/controller/templates/base/view_agg_check_lists_for_location_year.xsl
trunk/controller/templates/base/view_check_list.xsl
trunk/controller/templates/base/view_check_lists.xsl
trunk/controller/templates/base/view_check_lists_for_location.xsl
trunk/controller/templates/base/view_component_for_control.xsl
trunk/controller/templates/base/view_control_item_list.xsl
trunk/controller/templates/base/view_locations_for_control.xsl
trunk/controller/templates/base/yui_booking_i18n.xsl
Modified: trunk/controller/inc/class.menu.inc.php
===================================================================
--- trunk/controller/inc/class.menu.inc.php 2011-12-11 11:30:28 UTC (rev
8266)
+++ trunk/controller/inc/class.menu.inc.php 2011-12-11 12:27:18 UTC (rev
8267)
@@ -1,122 +1,151 @@
-<?php
- class controller_menu
- {
- function get_menu()
- {
- $incoming_app =
$GLOBALS['phpgw_info']['flags']['currentapp'];
- $GLOBALS['phpgw_info']['flags']['currentapp'] =
'controller';
- $menus = array();
-
- $menus['navbar'] = array
- (
- 'controller' => array
- (
- 'text' => lang('Controller'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol.view_control_details') ),
- 'image' => array('property',
'location'),
- 'order' => 10,
- 'group' => 'office'
- )
- );
-
-
if($GLOBALS['phpgw']->acl->check('.usertype.superuser',PHPGW_ACL_ADD,'controller'))
- {
- $menus['navigation'] = array
- (
- 'control' => array
- (
- 'text' => lang('Control'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol.control_list') ),
- 'image' => array('property',
'location_1'),
- 'children' => array(
-
'location_for_check_list' => array
-
(
-
'text' => lang('Location'),
-
'url' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction'=> 'controller.uicheck_list_for_location.index') ),
-
'image' => array('property', 'location_1')
-
),
-
'component_for_check_list' => array
-
(
-
'text' => lang('component'),
-
'url' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction'=> 'controller.uicheck_list_for_component.index') ),
-
'image' => array('property', 'entity_1')
-
)
-
)
- ),
- 'location_for_check_list' => array
- (
- 'text' =>
lang('location_connections'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicheck_list_for_location.index') ),
- 'image' => array('property',
'location_1')
- ),
- 'control_item' => array
- (
- 'text' => lang('Control_item'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol_item.index') ),
- 'image' => array('property',
'location_1')
- ),
- 'control_group' => array
- (
- 'text' =>
lang('Control_group'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol_group.index') ),
- 'image' => array('property',
'location_1')
- ),
- 'procedure' => array
- (
- 'text' => lang('Procedure'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uiprocedure.index') ),
- 'image' => array('property',
'location_1'),
- ),
- 'check_list' => array
- (
- 'text' => lang('Check_list'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicheck_list.index') ),
- 'image' => array('property',
'location_1'),
- ),
- 'location_check_list' => array
- (
- 'text' =>
lang('Check_list_location'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uilocation_check_list.view_agg_check_lists_for_location', 'year' =>
'2011', 'month' => '10') ),
- 'image' => array('property',
'location_1'),
- )
- );
- }
- else
- {
- $menus['navigation'] = array
- (
- 'check_list' => array
- (
- 'text' => lang('Check_list'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicheck_list.index') ),
- 'image' => array('property',
'location_1'),
- ),
- 'location_check_list' => array
- (
- 'text' =>
lang('Check_list_location'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uilocation_check_list.view_check_lists_for_location') ),
- 'image' => array('property',
'location_1'),
- ),
- );
- }
-
- if ( $GLOBALS['phpgw']->acl->check('run',
phpgwapi_acl::READ, 'admin')
- || $GLOBALS['phpgw']->acl->check('admin',
phpgwapi_acl::ADD, 'controller'))
- {
- $menus['admin'] = array
- (
- 'acl' => array
- (
- 'text' => lang('Configure
Access Permissions'),
- 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'preferences.uiadmin_acl.list_acl', 'acl_app' => 'controller') )
- )
- );
- }
-
- $menus['folders'] =
phpgwapi_menu::get_categories('bergen');
-
- $GLOBALS['phpgw_info']['flags']['currentapp'] =
$incoming_app;
-
- return $menus;
- }
- }
+<?php
+ /**
+ * phpGroupWare - controller: a part of a Facilities Management System.
+ *
+ * @author Erink Holm-Larsen <address@hidden>
+ * @author Torstein Vadla <address@hidden>
+ * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage controller
+ * @version $Id$
+ */
+
+ class controller_menu
+ {
+ function get_menu()
+ {
+ $incoming_app =
$GLOBALS['phpgw_info']['flags']['currentapp'];
+ $GLOBALS['phpgw_info']['flags']['currentapp'] =
'controller';
+ $menus = array();
+
+ $menus['navbar'] = array
+ (
+ 'controller' => array
+ (
+ 'text' => lang('Controller'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol.view_control_details') ),
+ 'image' => array('property',
'location'),
+ 'order' => 10,
+ 'group' => 'office'
+ )
+ );
+
+
if($GLOBALS['phpgw']->acl->check('.usertype.superuser',PHPGW_ACL_ADD,'controller'))
+ {
+ $menus['navigation'] = array
+ (
+ 'control' => array
+ (
+ 'text' => lang('Control'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol.control_list') ),
+ 'image' => array('property',
'location_1'),
+ 'children' => array(
+
'location_for_check_list' => array
+
(
+
'text' => lang('Location'),
+
'url' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction'=> 'controller.uicheck_list_for_location.index') ),
+
'image' => array('property', 'location_1')
+
),
+
'component_for_check_list' => array
+
(
+
'text' => lang('component'),
+
'url' => $GLOBALS['phpgw']->link('/index.php',
array('menuaction'=> 'controller.uicheck_list_for_component.index') ),
+
'image' => array('property', 'entity_1')
+
)
+
)
+ ),
+ 'location_for_check_list' => array
+ (
+ 'text' =>
lang('location_connections'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicheck_list_for_location.index') ),
+ 'image' => array('property',
'location_1')
+ ),
+ 'control_item' => array
+ (
+ 'text' => lang('Control_item'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol_item.index') ),
+ 'image' => array('property',
'location_1')
+ ),
+ 'control_group' => array
+ (
+ 'text' =>
lang('Control_group'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicontrol_group.index') ),
+ 'image' => array('property',
'location_1')
+ ),
+ 'procedure' => array
+ (
+ 'text' => lang('Procedure'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uiprocedure.index') ),
+ 'image' => array('property',
'location_1'),
+ ),
+ 'check_list' => array
+ (
+ 'text' => lang('Check_list'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicheck_list.index') ),
+ 'image' => array('property',
'location_1'),
+ ),
+ 'location_check_list' => array
+ (
+ 'text' =>
lang('Check_list_location'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uilocation_check_list.view_agg_check_lists_for_location', 'year' =>
'2011', 'month' => '10') ),
+ 'image' => array('property',
'location_1'),
+ )
+ );
+ }
+ else
+ {
+ $menus['navigation'] = array
+ (
+ 'check_list' => array
+ (
+ 'text' => lang('Check_list'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uicheck_list.index') ),
+ 'image' => array('property',
'location_1'),
+ ),
+ 'location_check_list' => array
+ (
+ 'text' =>
lang('Check_list_location'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uilocation_check_list.view_check_lists_for_location') ),
+ 'image' => array('property',
'location_1'),
+ ),
+ );
+ }
+
+ if ( $GLOBALS['phpgw']->acl->check('run',
phpgwapi_acl::READ, 'admin')
+ || $GLOBALS['phpgw']->acl->check('admin',
phpgwapi_acl::ADD, 'controller'))
+ {
+ $menus['admin'] = array
+ (
+ 'acl' => array
+ (
+ 'text' => lang('Configure
Access Permissions'),
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'preferences.uiadmin_acl.list_acl', 'acl_app' => 'controller') )
+ )
+ );
+ }
+
+ $menus['folders'] =
phpgwapi_menu::get_categories('bergen');
+
+ $GLOBALS['phpgw_info']['flags']['currentapp'] =
$incoming_app;
+
+ return $menus;
+ }
+ }
Modified: trunk/controller/inc/class.socheck_item.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_item.inc.php 2011-12-11 11:30:28 UTC
(rev 8266)
+++ trunk/controller/inc/class.socheck_item.inc.php 2011-12-11 12:27:18 UTC
(rev 8267)
@@ -1,105 +1,134 @@
-<?php
-phpgw::import_class('controller.socommon');
-
-include_class('controller', 'check_item', 'inc/model/');
-
-class controller_socheck_item extends controller_socommon
-{
- protected static $so;
-
- /**
- * Get a static reference to the storage object associated with this
model object
- *
- * @return controller_socontrol_group the storage object
- */
- public static function get_instance()
- {
- if (self::$so == null) {
- self::$so = CreateObject('controller.socheck_item');
- }
- return self::$so;
- }
-
- function get_query(string $sort_field, boolean $ascending, string
$search_for, string $search_type, array $filters, boolean $return_count){}
-
- function populate(int $object_id, &$object){}
-
- function add(&$check_item)
- {
- $cols = array(
- 'control_item_id',
- 'status',
- 'comment',
- 'check_list_id'
- );
-
- $values = array(
- $this->marshal($check_item->get_control_item_id(),
'int'),
- $this->marshal($check_item->get_status(), 'bool'),
- $this->marshal($check_item->get_comment(), 'string'),
- $this->marshal($check_item->get_check_list_id(), 'int')
- );
-
- $result = $this->db->query('INSERT INTO controller_check_item
(' . join(',', $cols) . ') VALUES (' . join(',', $values) . ')',
__LINE__,__FILE__);
-
- return isset($result) ?
$this->db->get_last_insert_id('controller_check_item', 'id') : 0;
- }
-
- function update($check_item)
- {
- $id = $check_item->get_id();
-
- $values = array(
- 'control_item_id = ' .
$this->marshal($check_item->get_control_item_id(), 'int'),
- 'status = ' . $this->marshal($check_item->get_status(),
'bool'),
- 'comment = ' .
$this->marshal($check_item->get_comment(), 'string'),
- 'check_list_id = ' .
$this->marshal($check_item->get_check_list_id(), 'int')
- );
-
- $result = $this->db->query('UPDATE controller_check_item SET '
. join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
-
- if( isset($result) )
- {
- return $id;
- }
- else
- {
- return 0;
- }
- }
-
- public function get_single($check_item_id)
- {
- $sql = "SELECT ci.*, coi.id as coi_id, coi.* ";
- $sql .= "FROM controller_check_item ci, controller_control_item
coi ";
- $sql .= "WHERE ci.id = $check_item_id ";
- $sql .= "AND ci.control_item_id=coi.id";
-
- $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
-
- if($this->db->next_record()) {
- $check_item = new
controller_check_item($this->unmarshal($this->db->f('id', true), 'int'));
-
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
-
$check_item->set_status($this->unmarshal($this->db->f('status', true), 'bool'));
-
$check_item->set_comment($this->unmarshal($this->db->f('comment', true),
'string'));
-
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
-
- $control_item = new
controller_control_item($this->unmarshal($this->db->f('coi_id', true), 'int'));
- $control_item->set_title($this->db->f('title', true),
'string');
- $control_item->set_required($this->db->f('required',
true), 'string');
-
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
- $control_item->set_how_to_do($this->db->f('how_to_do',
true), 'string');
-
$control_item->set_control_group_id($this->db->f('control_group_id', true),
'string');
-
- $check_item->set_control_item($control_item->toArray());
-
- return $check_item;
- }
- else
- {
- return null;
- }
- }
-
- function get_id_field_name(){}
-}
+<?php
+ /**
+ * phpGroupWare - controller: a part of a Facilities Management System.
+ *
+ * @author Erink Holm-Larsen <address@hidden>
+ * @author Torstein Vadla <address@hidden>
+ * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage controller
+ * @version $Id$
+ */
+
+ phpgw::import_class('controller.socommon');
+
+ include_class('controller', 'check_item', 'inc/model/');
+
+ class controller_socheck_item extends controller_socommon
+ {
+ protected static $so;
+
+ /**
+ * Get a static reference to the storage object associated with
this model object
+ *
+ * @return controller_socontrol_group the storage object
+ */
+ public static function get_instance()
+ {
+ if (self::$so == null) {
+ self::$so =
CreateObject('controller.socheck_item');
+ }
+ return self::$so;
+ }
+
+ function get_query(string $sort_field, boolean $ascending,
string $search_for, string $search_type, array $filters, boolean
$return_count){}
+
+ function populate(int $object_id, &$object){}
+
+ function add(&$check_item)
+ {
+ $cols = array(
+ 'control_item_id',
+ 'status',
+ 'comment',
+ 'check_list_id'
+ );
+
+ $values = array(
+
$this->marshal($check_item->get_control_item_id(), 'int'),
+ $this->marshal($check_item->get_status(),
'bool'),
+ $this->marshal($check_item->get_comment(),
'string'),
+
$this->marshal($check_item->get_check_list_id(), 'int')
+ );
+
+ $result = $this->db->query('INSERT INTO
controller_check_item (' . join(',', $cols) . ') VALUES (' . join(',', $values)
. ')', __LINE__,__FILE__);
+
+ return isset($result) ?
$this->db->get_last_insert_id('controller_check_item', 'id') : 0;
+ }
+
+ function update($check_item)
+ {
+ $id = $check_item->get_id();
+
+ $values = array(
+ 'control_item_id = ' .
$this->marshal($check_item->get_control_item_id(), 'int'),
+ 'status = ' .
$this->marshal($check_item->get_status(), 'bool'),
+ 'comment = ' .
$this->marshal($check_item->get_comment(), 'string'),
+ 'check_list_id = ' .
$this->marshal($check_item->get_check_list_id(), 'int')
+ );
+
+ $result = $this->db->query('UPDATE
controller_check_item SET ' . join(',', $values) . " WHERE id=$id",
__LINE__,__FILE__);
+
+ if( isset($result) )
+ {
+ return $id;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ public function get_single($check_item_id)
+ {
+ $sql = "SELECT ci.*, coi.id as coi_id, coi.* ";
+ $sql .= "FROM controller_check_item ci,
controller_control_item coi ";
+ $sql .= "WHERE ci.id = $check_item_id ";
+ $sql .= "AND ci.control_item_id=coi.id";
+
+ $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+
+ if($this->db->next_record()) {
+ $check_item = new
controller_check_item($this->unmarshal($this->db->f('id', true), 'int'));
+
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
+
$check_item->set_status($this->unmarshal($this->db->f('status', true), 'bool'));
+
$check_item->set_comment($this->unmarshal($this->db->f('comment', true),
'string'));
+
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
+
+ $control_item = new
controller_control_item($this->unmarshal($this->db->f('coi_id', true), 'int'));
+ $control_item->set_title($this->db->f('title',
true), 'string');
+
$control_item->set_required($this->db->f('required', true), 'string');
+
$control_item->set_what_to_do($this->db->f('what_to_do', true), 'string');
+
$control_item->set_how_to_do($this->db->f('how_to_do', true), 'string');
+
$control_item->set_control_group_id($this->db->f('control_group_id', true),
'string');
+
+
$check_item->set_control_item($control_item->toArray());
+
+ return $check_item;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ function get_id_field_name(){}
+ }
Modified: trunk/controller/inc/class.socheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_list.inc.php 2011-12-11 11:30:28 UTC
(rev 8266)
+++ trunk/controller/inc/class.socheck_list.inc.php 2011-12-11 12:27:18 UTC
(rev 8267)
@@ -1,478 +1,507 @@
-<?php
-phpgw::import_class('controller.socommon');
-
-include_class('controller', 'check_list', 'inc/model/');
-
-class controller_socheck_list extends controller_socommon
-{
- protected static $so;
-
- /**
- * Get a static reference to the storage object associated with this
model object
- *
- * @return controller_socontrol_group the storage object
- */
- public static function get_instance()
- {
- if (self::$so == null)
- {
- self::$so = CreateObject('controller.socheck_list');
- }
- return self::$so;
- }
-
- public function get_single($check_list_id)
- {
- $sql = "SELECT cl.id as cl_id, cl.status as cl_status,
cl.comment as cl_comment, deadline, ci.id as ci_id, ci.status as ci_status,
control_item_id, ci.comment as ci_comment, check_list_id FROM
controller_check_list cl, controller_check_item ci WHERE cl.id = $check_list_id
AND cl.id = ci.check_list_id;";
- $this->db->query($sql);
-
- $counter = 0;
- $check_list = null;
- while ($this->db->next_record())
- {
- if($counter == 0)
- {
- $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
-
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'bool'));
-
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
-
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
- }
-
- $check_item = new
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
-
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
-
$check_item->set_status($this->unmarshal($this->db->f('ci_status', true),
'bool'));
-
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true),
'string'));
-
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
-
- $check_items_array[] = $check_item->toArray();
-
- $counter++;
- }
-
- if($check_list != null)
- {
- $check_list->set_check_item_array($check_items_array);
- return $check_list->toArray();
- }
- else
- {
- return null;
- }
- }
-
- public function get_single_with_control_items($check_list_id)
- {
- $sql = "SELECT cl.id as cl_id, cl.status as cl_status,
cl.comment as cl_comment, deadline, ";
- $sql .= "ci.id as ci_id, ci.status as ci_status,
control_item_id, ci.comment as ci_comment, check_list_id, ";
- $sql .= "coi.title as coi_id, coi.title as coi_title,
coi.required as coi_required, coi.required as coi_required, ";
- $sql .= "coi.what_to_do as coi_what_to_do, coi.how_to_do as
coi_how_to_do, coi.control_group_id as coi_control_group_id ";
- $sql .= "FROM controller_check_list cl, controller_check_item
ci, controller_control_item as coi ";
- $sql .= "WHERE cl.id = $check_list_id ";
- $sql .= "AND cl.id = ci.check_list_id ";
- $sql .= "AND ci.control_item_id=coi.id;";
-
- $this->db->query($sql);
-
- $counter = 0;
- $check_list = null;
- while ($this->db->next_record())
- {
- if($counter == 0)
- {
- $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
-
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'bool'));
-
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
-
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
- }
-
- $check_item = new
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
-
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
-
$check_item->set_status($this->unmarshal($this->db->f('ci_status', true),
'bool'));
-
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true),
'string'));
-
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
-
- $control_item = new
controller_control_item($this->unmarshal($this->db->f('coi_id', true), 'int'));
- $control_item->set_title($this->db->f('coi_title',
true), 'string');
-
$control_item->set_required($this->db->f('coi_required', true), 'string');
-
$control_item->set_what_to_do($this->db->f('coi_what_to_do', true), 'string');
-
$control_item->set_how_to_do($this->db->f('coi_how_to_do', true), 'string');
-
$control_item->set_control_group_id($this->db->f('coi_control_group_id', true),
'string');
-
- $check_item->set_control_item($control_item->toArray());
-
- $check_items_array[] = $check_item->toArray();
-
- $counter++;
- }
-
- if($check_list != null)
- {
- $check_list->set_check_item_array($check_items_array);
- return $check_list->toArray();
- }
- else
- {
- return null;
- }
- }
-
- public function get_check_list()
- {
- $current_time = time();
-
- $buffer_in_days = 3600*24*7*5;
-
- $buffer_time = $current_time - $buffer_in_days;
-
- $sql = "SELECT p.* FROM controller_control p WHERE
$current_time >= p.start_date AND p.start_date > $buffer_time";
- $this->db->query($sql);
-
- while ($this->db->next_record())
- {
- $start_date = date("d.m.Y",
$this->db->f('start_date'));
- $end_date = date("d.m.Y", $this->db->f('end_date'));
-
- $control = new
controller_control($this->unmarshal($this->db->f('id', true), 'int'));
-
-
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
-
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
- $control->set_start_date($start_date);
- $control->set_end_date($end_date);
-
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
-
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
-
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
-
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
-
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
-
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
-
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
-
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
-
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
-
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
-
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
-
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
-
- $results[] = $control->toArray();
- }
-
- return $results;
- }
-
- function get_check_lists_for_control($control_id)
- {
- $sql = "SELECT cl.id as cl_id, cl.status as cl_status,
cl.comment as cl_comment, deadline, ";
- $sql .= "ci.id as ci_id, ci.status as ci_status,
control_item_id, ci.comment as ci_comment, check_list_id ";
- $sql .= "FROM controller_check_list cl, controller_check_item
ci ";
- $sql .= "WHERE cl.control_id = $control_id ";
- $sql .= "AND cl.id = ci.check_list_id ";
- $sql .= "ORDER BY cl.id;";
- $this->db->query($sql);
-
- $check_list_id = 0;
- $check_list = null;
- while ($this->db->next_record())
- {
- if( $this->db->f('cl_id', true) != $check_list_id )
- {
- if($check_list_id != 0)
- {
-
$check_list->set_check_item_array($check_items_array);
- $check_list_array[] =
$check_list->toArray();
- }
-
- $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
-
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'bool'));
-
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
-
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
-
- $check_items_array = array();
- }
-
- $check_item = new
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
-
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
-
$check_item->set_status($this->unmarshal($this->db->f('ci_status', true),
'bool'));
-
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true),
'string'));
-
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
-
- $check_items_array[] = $check_item->toArray();
-
- $check_list_id = $check_list->get_id();
- }
-
- if($check_list != null)
- {
- $check_list->set_check_item_array($check_items_array);
- $check_list_array[] = $check_list->toArray();
-
- return $check_list_array;
- }
- else
- {
- return null;
- }
- }
-
- function get_agg_check_lists_for_location( $location_code, $from_date,
$to_date )
- {
- $sql = "SELECT c.id as c_id, title, cl.id as cl_id,
c.repeat_type, c.repeat_interval, deadline, count(ci.id) ";
- $sql .= "FROM controller_check_list cl, controller_control c,
controller_check_item ci ";
- $sql .= "WHERE cl.location_code = $location_code ";
- $sql .= "AND c.repeat_type < 2 ";
- $sql .= "AND cl.control_id = c.id ";
- $sql .= "AND cl.id = ci.check_list_id ";
- $sql .= "AND deadline BETWEEN $from_date AND $to_date ";
- $sql .= "GROUP BY c.id, title, cl.id, cl.deadline,
c.repeat_type, c.repeat_interval ";
- $sql .= "ORDER BY c.id";
-
- $this->db->query($sql);
-
- $control_id = 0;
- $controls_array = array();
- $check_list_array = array();
- while ($this->db->next_record())
- {
- if( $this->db->f('c_id', true) != $control_id )
- {
- if($control_id != 0)
- {
- $controls_array[] = array( "control" =>
$control_array, "check_list" => $check_list_array);
- $check_list_array = array();
- }
-
- $control_array = array(
-
"id" => $this->unmarshal($this->db->f('c_id', true),
'int'),
-
"title" => $this->unmarshal($this->db->f('title', true),
'string'),
-
"repeat_type" => $this->unmarshal($this->db->f('repeat_type', true), 'int'),
-
"repeat_interval" => $this->unmarshal($this->db->f('repeat_interval', true),
'int')
- );
- }
-
- $check_list_array[] = array(
-
"cl_id" => $this->db->f('cl_id', true),
-
"deadline" => $this->db->f('deadline', true),
-
"count" => $this->db->f('count', true)
- );
-
- $control_id = $this->db->f('c_id', true);
- }
-
- if( !empty( $control_array ) )
- {
- $controls_array[] = array( "control" => $control_array,
"check_list" => $check_list_array);
-
- return $controls_array;
- }
- else
- {
- return null;
- }
- }
-
- function get_check_lists_for_location( $location_code, $from_date,
$to_date, $repeat_type )
- {
- $sql = "SELECT c.id as c_id, cl.id as cl_id, cl.status as
cl_status, cl.comment as cl_comment, ";
- $sql .= "deadline, planned_date, completed_date,
cl.location_code as cl_loc, c.* ";
- $sql .= "FROM controller_check_list cl, controller_control c ";
- $sql .= "WHERE cl.location_code = $location_code ";
- $sql .= "AND c.repeat_type = $repeat_type ";
- $sql .= "AND cl.control_id = c.id ";
- $sql .= "AND deadline BETWEEN $from_date AND $to_date";
- $sql .= "ORDER BY c.id;";
-
- $this->db->query($sql);
-
- $control_id = 0;
- $control = null;
- while ($this->db->next_record())
- {
- if( $this->db->f('c_id', true) != $control_id )
- {
- if($control_id != 0)
- {
-
$control->set_check_lists_array($check_lists_array);
- $controls_array[] = $control;
- }
-
- $control = new
controller_control($this->unmarshal($this->db->f('c_id', true), 'int'));
-
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
-
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
-
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
-
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
-
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
-
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
-
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
-
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
-
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
-
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
-
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
-
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
-
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
-
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
-
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
-
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
-
- $check_lists_array = array();
- }
-
- $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
-
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'string'));
-
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
-
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
-
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date',
true), 'int'));
-
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date',
true), 'int'));
-
$check_list->set_location_code($this->unmarshal($this->db->f('cl_loc', true),
'int'));
-
- $check_lists_array[] = $check_list;
-
- $control_id = $control->get_id();
- }
-
- if($control != null)
- {
- $control->set_check_lists_array($check_lists_array);
- $controls_array[] = $control;
-
- return $controls_array;
- }
- else
- {
- return null;
- }
- }
-
- function get_query(string $sort_field, boolean $ascending, string
$search_for, string $search_type, array $filters, boolean $return_count)
- {
- $current_time = time();
- $buffer_in_days = 3600*24*7*5;
- $buffer_time = $current_time - $buffer_in_days;
-
- $clauses = array('1=1');
- $clauses[] = "{$current_time} >= p.start_date AND p.start_date
> {$buffer_time}";
-
- $filter_clauses = array();
-
- // Search for based on search type
- if($search_for)
- {
- $search_for = $this->marshal($search_for,'field');
- $like_pattern = "'%".$search_for."%'";
- $like_clauses = array();
- switch($search_type){
- default:
- $like_clauses[] = "p.title $this->like
$like_pattern";
- break;
- }
-
- if(count($like_clauses))
- {
- $clauses[] = '(' . join(' OR ', $like_clauses)
. ')';
- }
- }
- //var_dump($filters);
- if(isset($filters[$this->get_id_field_name()]))
- {
- $filter_clauses[] = "p.id =
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
- }
-
- if(count($filter_clauses))
- {
- $clauses[] = join(' AND ', $filter_clauses);
- }
-
- $condition = join(' AND ', $clauses);
-
- $tables = "controller_control p";
- //$joins = " {$this->left_join} rental_document_types ON
(rental_document.type_id = rental_document_types.id)";
- //$joins = " {$this->left_join} controller_control_area ON
(controller_control.control_area_id = controller_control_area.id)";
- //$joins .= " {$this->left_join} controller_procedure ON
(controller_control.procedure_id = controller_procedure.id)";
-
- if($return_count)
- {
- $cols = 'COUNT(DISTINCT(p.id)) AS count';
- }
- else
- {
- $cols = 'p.* ';
- }
-
- $dir = $ascending ? 'ASC' : 'DESC';
- if($sort_field == 'id')
- {
- $sort_field = 'p.id';
- }
- $order = $sort_field ? "ORDER BY {$this->marshal($sort_field,
'field')} $dir ": '';
-
- return "SELECT {$cols} FROM {$tables} {$joins} WHERE
{$condition} {$order}";
- }
-
- function populate(int $control_id, &$control)
- {
- if($control == null)
- {
- $start_date = date("d.m.Y",
$this->db->f('start_date'));
- $end_date = date("d.m.Y", $this->db->f('end_date'));
- $control = new controller_control((int) $control_id);
-
-
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
-
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
- $control->set_start_date($start_date);
- $control->set_end_date($end_date);
-
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
-
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
-
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
-
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
-
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
-
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
-
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
-//
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
true), 'int'));
-
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
-
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
-
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
-
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
-
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
- }
-
- return $control;
- }
-
- function add(&$check_list)
- {
- $cols = array(
- 'control_id',
- 'status',
- 'comment',
- 'deadline'
- );
-
- $values = array(
- $this->marshal($check_list->get_control_id(), 'int'),
- $this->marshal($check_list->get_status(), 'bool'),
- $this->marshal($check_list->get_comment(), 'string'),
- $this->marshal($check_list->get_deadline(), 'int')
- );
-
- $result = $this->db->query('INSERT INTO controller_check_list
(' . join(',', $cols) . ') VALUES (' . join(',', $values) . ')',
__LINE__,__FILE__);
-
- return isset($result) ?
$this->db->get_last_insert_id('controller_check_list', 'id') : 0;
- }
-
- function update($object){}
-
- function get_id_field_name($extended_info = false)
- {
- if(!$extended_info)
- {
- $ret = 'id';
- }
- else
- {
- $ret = array
- (
- 'table' => 'control', // alias
- 'field' => 'id',
- 'translated' => 'id'
- );
- }
-
- return $ret;
- }
-}
+<?php
+ /**
+ * phpGroupWare - controller: a part of a Facilities Management System.
+ *
+ * @author Erink Holm-Larsen <address@hidden>
+ * @author Torstein Vadla <address@hidden>
+ * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage controller
+ * @version $Id$
+ */
+
+ phpgw::import_class('controller.socommon');
+
+ include_class('controller', 'check_list', 'inc/model/');
+
+ class controller_socheck_list extends controller_socommon
+ {
+ protected static $so;
+
+ /**
+ * Get a static reference to the storage object associated with
this model object
+ *
+ * @return controller_socontrol_group the storage object
+ */
+ public static function get_instance()
+ {
+ if (self::$so == null)
+ {
+ self::$so =
CreateObject('controller.socheck_list');
+ }
+ return self::$so;
+ }
+
+ public function get_single($check_list_id)
+ {
+ $sql = "SELECT cl.id as cl_id, cl.status as cl_status,
cl.comment as cl_comment, deadline, ci.id as ci_id, ci.status as ci_status,
control_item_id, ci.comment as ci_comment, check_list_id FROM
controller_check_list cl, controller_check_item ci WHERE cl.id = $check_list_id
AND cl.id = ci.check_list_id;";
+ $this->db->query($sql);
+
+ $counter = 0;
+ $check_list = null;
+ while ($this->db->next_record())
+ {
+ if($counter == 0)
+ {
+ $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'bool'));
+
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
+
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
+ }
+
+ $check_item = new
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
+
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
+
$check_item->set_status($this->unmarshal($this->db->f('ci_status', true),
'bool'));
+
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true),
'string'));
+
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
+
+ $check_items_array[] = $check_item->toArray();
+
+ $counter++;
+ }
+
+ if($check_list != null)
+ {
+
$check_list->set_check_item_array($check_items_array);
+ return $check_list->toArray();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public function get_single_with_control_items($check_list_id)
+ {
+ $sql = "SELECT cl.id as cl_id, cl.status as cl_status,
cl.comment as cl_comment, deadline, ";
+ $sql .= "ci.id as ci_id, ci.status as ci_status,
control_item_id, ci.comment as ci_comment, check_list_id, ";
+ $sql .= "coi.title as coi_id, coi.title as coi_title,
coi.required as coi_required, coi.required as coi_required, ";
+ $sql .= "coi.what_to_do as coi_what_to_do,
coi.how_to_do as coi_how_to_do, coi.control_group_id as coi_control_group_id ";
+ $sql .= "FROM controller_check_list cl,
controller_check_item ci, controller_control_item as coi ";
+ $sql .= "WHERE cl.id = $check_list_id ";
+ $sql .= "AND cl.id = ci.check_list_id ";
+ $sql .= "AND ci.control_item_id=coi.id;";
+
+ $this->db->query($sql);
+
+ $counter = 0;
+ $check_list = null;
+ while ($this->db->next_record())
+ {
+ if($counter == 0)
+ {
+ $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'bool'));
+
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
+
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
+ }
+
+ $check_item = new
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
+
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
+
$check_item->set_status($this->unmarshal($this->db->f('ci_status', true),
'bool'));
+
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true),
'string'));
+
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
+
+ $control_item = new
controller_control_item($this->unmarshal($this->db->f('coi_id', true), 'int'));
+
$control_item->set_title($this->db->f('coi_title', true), 'string');
+
$control_item->set_required($this->db->f('coi_required', true), 'string');
+
$control_item->set_what_to_do($this->db->f('coi_what_to_do', true), 'string');
+
$control_item->set_how_to_do($this->db->f('coi_how_to_do', true), 'string');
+
$control_item->set_control_group_id($this->db->f('coi_control_group_id', true),
'string');
+
+
$check_item->set_control_item($control_item->toArray());
+
+ $check_items_array[] = $check_item->toArray();
+
+ $counter++;
+ }
+
+ if($check_list != null)
+ {
+
$check_list->set_check_item_array($check_items_array);
+ return $check_list->toArray();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public function get_check_list()
+ {
+ $current_time = time();
+
+ $buffer_in_days = 3600*24*7*5;
+
+ $buffer_time = $current_time - $buffer_in_days;
+
+ $sql = "SELECT p.* FROM controller_control p WHERE
$current_time >= p.start_date AND p.start_date > $buffer_time";
+ $this->db->query($sql);
+
+ while ($this->db->next_record())
+ {
+ $start_date = date("d.m.Y",
$this->db->f('start_date'));
+ $end_date = date("d.m.Y",
$this->db->f('end_date'));
+
+ $control = new
controller_control($this->unmarshal($this->db->f('id', true), 'int'));
+
+
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
+ $control->set_start_date($start_date);
+ $control->set_end_date($end_date);
+
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
+
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
+
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
+
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
+
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
+
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
+
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
+
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
+
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
+
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
+
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
+
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
+
+ $results[] = $control->toArray();
+ }
+
+ return $results;
+ }
+
+ function get_check_lists_for_control($control_id)
+ {
+ $sql = "SELECT cl.id as cl_id, cl.status as cl_status,
cl.comment as cl_comment, deadline, ";
+ $sql .= "ci.id as ci_id, ci.status as ci_status,
control_item_id, ci.comment as ci_comment, check_list_id ";
+ $sql .= "FROM controller_check_list cl,
controller_check_item ci ";
+ $sql .= "WHERE cl.control_id = $control_id ";
+ $sql .= "AND cl.id = ci.check_list_id ";
+ $sql .= "ORDER BY cl.id;";
+ $this->db->query($sql);
+
+ $check_list_id = 0;
+ $check_list = null;
+ while ($this->db->next_record())
+ {
+ if( $this->db->f('cl_id', true) !=
$check_list_id )
+ {
+ if($check_list_id != 0)
+ {
+
$check_list->set_check_item_array($check_items_array);
+ $check_list_array[] =
$check_list->toArray();
+ }
+
+ $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'bool'));
+
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
+
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
+
+ $check_items_array = array();
+ }
+
+ $check_item = new
controller_check_item($this->unmarshal($this->db->f('ci_id', true), 'int'));
+
$check_item->set_control_item_id($this->unmarshal($this->db->f('control_item_id',
true), 'int'));
+
$check_item->set_status($this->unmarshal($this->db->f('ci_status', true),
'bool'));
+
$check_item->set_comment($this->unmarshal($this->db->f('ci_comment', true),
'string'));
+
$check_item->set_check_list_id($this->unmarshal($this->db->f('check_list_id',
true), 'int'));
+
+ $check_items_array[] = $check_item->toArray();
+
+ $check_list_id = $check_list->get_id();
+ }
+
+ if($check_list != null)
+ {
+
$check_list->set_check_item_array($check_items_array);
+ $check_list_array[] = $check_list->toArray();
+
+ return $check_list_array;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ function get_agg_check_lists_for_location( $location_code,
$from_date, $to_date )
+ {
+ $sql = "SELECT c.id as c_id, title, cl.id as cl_id,
c.repeat_type, c.repeat_interval, deadline, count(ci.id) ";
+ $sql .= "FROM controller_check_list cl,
controller_control c, controller_check_item ci ";
+ $sql .= "WHERE cl.location_code = $location_code ";
+ $sql .= "AND c.repeat_type < 2 ";
+ $sql .= "AND cl.control_id = c.id ";
+ $sql .= "AND cl.id = ci.check_list_id ";
+ $sql .= "AND deadline BETWEEN $from_date AND $to_date ";
+ $sql .= "GROUP BY c.id, title, cl.id, cl.deadline,
c.repeat_type, c.repeat_interval ";
+ $sql .= "ORDER BY c.id";
+
+ $this->db->query($sql);
+
+ $control_id = 0;
+ $controls_array = array();
+ $check_list_array = array();
+ while ($this->db->next_record())
+ {
+ if( $this->db->f('c_id', true) != $control_id )
+ {
+ if($control_id != 0)
+ {
+ $controls_array[] = array(
"control" => $control_array, "check_list" => $check_list_array);
+ $check_list_array = array();
+ }
+
+ $control_array = array(
+
"id" => $this->unmarshal($this->db->f('c_id',
true), 'int'),
+
"title" => $this->unmarshal($this->db->f('title',
true), 'string'),
+
"repeat_type" => $this->unmarshal($this->db->f('repeat_type',
true), 'int'),
+
"repeat_interval" => $this->unmarshal($this->db->f('repeat_interval',
true), 'int')
+
);
+ }
+
+ $check_list_array[] = array(
+
"cl_id" => $this->db->f('cl_id', true),
+
"deadline" => $this->db->f('deadline', true),
+
"count" => $this->db->f('count', true)
+
);
+
+ $control_id = $this->db->f('c_id', true);
+ }
+
+ if( !empty( $control_array ) )
+ {
+ $controls_array[] = array( "control" =>
$control_array, "check_list" => $check_list_array);
+
+ return $controls_array;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ function get_check_lists_for_location( $location_code,
$from_date, $to_date, $repeat_type )
+ {
+ $sql = "SELECT c.id as c_id, cl.id as cl_id, cl.status
as cl_status, cl.comment as cl_comment, ";
+ $sql .= "deadline, planned_date, completed_date,
cl.location_code as cl_loc, c.* ";
+ $sql .= "FROM controller_check_list cl,
controller_control c ";
+ $sql .= "WHERE cl.location_code = $location_code ";
+ $sql .= "AND c.repeat_type = $repeat_type ";
+ $sql .= "AND cl.control_id = c.id ";
+ $sql .= "AND deadline BETWEEN $from_date AND $to_date";
+ $sql .= "ORDER BY c.id;";
+
+ $this->db->query($sql);
+
+ $control_id = 0;
+ $control = null;
+ while ($this->db->next_record())
+ {
+ if( $this->db->f('c_id', true) != $control_id )
+ {
+ if($control_id != 0)
+ {
+
$control->set_check_lists_array($check_lists_array);
+ $controls_array[] = $control;
+ }
+
+ $control = new
controller_control($this->unmarshal($this->db->f('c_id', true), 'int'));
+
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
+
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
+
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
+
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
+
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
+
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
+
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
+
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
+
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
+
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
+
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
+
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
+
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
+
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
+
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
+
+ $check_lists_array = array();
+ }
+
+ $check_list = new
controller_check_list($this->unmarshal($this->db->f('cl_id', true), 'int'));
+
$check_list->set_status($this->unmarshal($this->db->f('cl_status', true),
'string'));
+
$check_list->set_comment($this->unmarshal($this->db->f('cl_comment', true),
'string'));
+
$check_list->set_deadline($this->unmarshal($this->db->f('deadline', true),
'int'));
+
$check_list->set_planned_date($this->unmarshal($this->db->f('planned_date',
true), 'int'));
+
$check_list->set_completed_date($this->unmarshal($this->db->f('completed_date',
true), 'int'));
+
$check_list->set_location_code($this->unmarshal($this->db->f('cl_loc', true),
'int'));
+
+ $check_lists_array[] = $check_list;
+
+ $control_id = $control->get_id();
+ }
+
+ if($control != null)
+ {
+
$control->set_check_lists_array($check_lists_array);
+ $controls_array[] = $control;
+
+ return $controls_array;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ function get_query(string $sort_field, boolean $ascending,
string $search_for, string $search_type, array $filters, boolean $return_count)
+ {
+ $current_time = time();
+ $buffer_in_days = 3600*24*7*5;
+ $buffer_time = $current_time - $buffer_in_days;
+
+ $clauses = array('1=1');
+ $clauses[] = "{$current_time} >= p.start_date AND
p.start_date > {$buffer_time}";
+
+ $filter_clauses = array();
+
+ // Search for based on search type
+ if($search_for)
+ {
+ $search_for =
$this->marshal($search_for,'field');
+ $like_pattern = "'%".$search_for."%'";
+ $like_clauses = array();
+ switch($search_type){
+ default:
+ $like_clauses[] = "p.title
$this->like $like_pattern";
+ break;
+ }
+
+ if(count($like_clauses))
+ {
+ $clauses[] = '(' . join(' OR ',
$like_clauses) . ')';
+ }
+ }
+ //var_dump($filters);
+ if(isset($filters[$this->get_id_field_name()]))
+ {
+ $filter_clauses[] = "p.id =
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
+ }
+
+ if(count($filter_clauses))
+ {
+ $clauses[] = join(' AND ', $filter_clauses);
+ }
+
+ $condition = join(' AND ', $clauses);
+
+ $tables = "controller_control p";
+ //$joins = " {$this->left_join} rental_document_types
ON (rental_document.type_id = rental_document_types.id)";
+ //$joins = " {$this->left_join} controller_control_area
ON (controller_control.control_area_id = controller_control_area.id)";
+ //$joins .= " {$this->left_join} controller_procedure
ON (controller_control.procedure_id = controller_procedure.id)";
+
+ if($return_count)
+ {
+ $cols = 'COUNT(DISTINCT(p.id)) AS count';
+ }
+ else
+ {
+ $cols = 'p.* ';
+ }
+
+ $dir = $ascending ? 'ASC' : 'DESC';
+ if($sort_field == 'id')
+ {
+ $sort_field = 'p.id';
+ }
+ $order = $sort_field ? "ORDER BY
{$this->marshal($sort_field, 'field')} $dir ": '';
+
+ return "SELECT {$cols} FROM {$tables} {$joins} WHERE
{$condition} {$order}";
+ }
+
+ function populate(int $control_id, &$control)
+ {
+ if($control == null)
+ {
+ $start_date = date("d.m.Y",
$this->db->f('start_date'));
+ $end_date = date("d.m.Y",
$this->db->f('end_date'));
+ $control = new controller_control((int)
$control_id);
+
+
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
+ $control->set_start_date($start_date);
+ $control->set_end_date($end_date);
+
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
+
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
+
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
+
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
+
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
+
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
+
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
+ //
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
true), 'int'));
+
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
+
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
+
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
+
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
+
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
+ }
+
+ return $control;
+ }
+
+ function add(&$check_list)
+ {
+ $cols = array(
+ 'control_id',
+ 'status',
+ 'comment',
+ 'deadline'
+ );
+
+ $values = array(
+ $this->marshal($check_list->get_control_id(),
'int'),
+ $this->marshal($check_list->get_status(),
'bool'),
+ $this->marshal($check_list->get_comment(),
'string'),
+ $this->marshal($check_list->get_deadline(),
'int')
+ );
+
+ $result = $this->db->query('INSERT INTO
controller_check_list (' . join(',', $cols) . ') VALUES (' . join(',', $values)
. ')', __LINE__,__FILE__);
+
+ return isset($result) ?
$this->db->get_last_insert_id('controller_check_list', 'id') : 0;
+ }
+
+ function update($object){}
+
+ function get_id_field_name($extended_info = false)
+ {
+ if(!$extended_info)
+ {
+ $ret = 'id';
+ }
+ else
+ {
+ $ret = array
+ (
+ 'table' => 'control',
// alias
+ 'field' => 'id',
+ 'translated' => 'id'
+ );
+ }
+
+ return $ret;
+ }
+ }
Modified: trunk/controller/inc/class.socommon.inc.php
===================================================================
--- trunk/controller/inc/class.socommon.inc.php 2011-12-11 11:30:28 UTC (rev
8266)
+++ trunk/controller/inc/class.socommon.inc.php 2011-12-11 12:27:18 UTC (rev
8267)
@@ -1,326 +1,354 @@
-<?php
-abstract class controller_socommon
-{
- protected $db;
- protected $like;
- protected $join;
- protected $left_join;
-
- public function __construct()
- {
- $this->db = clone $GLOBALS['phpgw']->db;
- $this->like = & $this->db->like;
- $this->join = & $this->db->join;
- $this->left_join = & $this->db->left_join;
- }
-
- /**
- * Marshal values according to type
- * @param $value the value
- * @param $type the type of value
- * @return database value
- */
- protected function marshal($value, $type)
- {
- if($value === null)
- {
- return 'NULL';
- }
- else if($type == 'int')
- {
- if($value == '')
- {
- return 'NULL';
- }
- return intval($value);
- }
- else if($type == 'float')
- {
- return str_replace(',', '.', $value);
- }
- else if($type == 'field')
- {
- return $this->db->db_addslashes($value);
- }
-
- return "'" . $this->db->db_addslashes($value) . "'";
- }
-
- /*
-
- /**
- * Unmarchal database values according to type
- * @param $value the field value
- * @param $type a string dictating value type
- * @return the php value
- */
- protected function unmarshal($value, $type)
- {
- if($type == 'bool')
- {
- return (boolean)$value;
- }
- elseif($value === null || $value == 'NULL')
- {
- return null;
- }
- elseif($type == 'int')
- {
- return intval($value);
- }
- elseif($type == 'float')
- {
- return floatval($value);
- }
- return $value;
- }
-
- /**
- * Get the count of the specified query. Query must return a signel
column
- * called count.
- *
- * @param $sql the sql query
- * @return the count value
- */
- protected function get_query_count($sql)
- {
- $result = $this->db->query($sql);
- if($result && $this->db->next_record())
- {
- return $this->unmarshal($this->db->f('count', true),
'int');
- }
- }
-
- /**
- * Implementing classes must return an instance of itself.
- *
- * @return the class instance.
- */
- public abstract static function get_instance();
-
- /**
- * Convenience method for getting one single object. Calls get() with
the
- * specified id as a filter.
- *
- * @param $id int with id of object to return.
- * @return object with the specified id, null if not found.
- */
- public function get_single(int $id)
- {
- $objects = $this->get(null, null, null, null, null, null,
array($this->get_id_field_name() => $id));
- if(count($objects) > 0)
- {
- $keys = array_keys($objects);
- return $objects[$keys[0]];
- }
- return null;
- }
-
- /**
- * Method for retrieving the db-object (security "forgotten")
- */
- public function get_db(){
- return $this->db;
- }
-
- /**
- * Method for retreiving objects.
- *
- * @param $start_index int with index of first object.
- * @param $num_of_objects int with max number of objects to return.
- * @param $sort_field string representing the object field to sort on.
- * @param $ascending boolean true for ascending sort on sort field,
false
- * for descending.
- * @param $search_for string with free text search query.
- * @param $search_type string with the query type.
- * @param $filters array with key => value of filters.
- * @return array of objects. May return an empty
- * array, never null. The array keys are the respective index numbers.
- */
- public function get(int $start_index, int $num_of_objects, string
$sort_field, boolean $ascending, string $search_for, string $search_type, array
$filters)
- {
- $results = array(); // Array to store
result objects
- $map = array(); // Array to hold number
of records per target object
- $check_map = array(); // Array to hold the actual
number of record read per target object
- $object_ids = array(); // All of the object ids
encountered
- $added_object_ids = array();// All of the added objects ids
-
- // Retrieve information about the table name and the name and
alias of id column
- // $break_on_limit - flag indicating whether to break the
loop when the number of records
- // for all the
result objects are traversed
- $id_field_name_info = $this->get_id_field_name(true);
- if(is_array($id_field_name_info))
- {
- $break_on_limit = true;
- $id_field_name = $id_field_name_info['translated'];
- }
- else
- {
- $break_on_limit = false;
- $id_field_name = $id_field_name_info;
- }
-
- // Special case: Sort on id field. Always changed to the id
field name.
- // $break_when_num_of_objects_reached - flag indicating to
break the loop when the number of
- // results are reached and we are sure that the
records are ordered by the id
- if($sort_field == null || $sort_field == 'id' || $sort_field ==
'')
- {
- $sort_field = $id_field_name;
- $break_when_num_of_objects_reached = true;
- }
- else
- {
- $break_when_num_of_objects_reached = false;
- }
-
- // Only allow positive start index
- if($start_index < 0)
- {
- $start_index = 0;
- }
-
- // test-input for break on ordered queries
- $db2 = clone($this->db);
-
- $sql = $this->get_query($sort_field, $ascending, $search_for,
$search_type, $filters, false);
-
- $sql_parts = explode('1=1',$sql); // Split the query to insert
extra condition on test for break
- $this->db->query($sql,__LINE__, __FILE__, false, true);
-
- while ($this->db->next_record()) // Runs through all of the
results
- {
- $should_populate_object = false; // Default value - we
won't populate object
- $result_id =
$this->unmarshal($this->db->f($id_field_name), 'int'); // The id of object
-
- if(in_array($result_id, $added_object_ids)) // Object
with this id already added
- {
- $should_populate_object = true; // We should
populate this object as we already have it in our result array
- }
- else // Object isn't already added to array
- {
- if(!in_array($result_id, $object_ids)) //
Haven't already added this id
- {
- $object_ids[] = $result_id; // We have
to add the new id
- }
- // We have to check if we should populate this
object
- if(count($object_ids) > $start_index) // We're
at index above start index
- {
- if($num_of_objects == null ||
count($results) < $num_of_objects) // We haven't found all the objects we're
looking for
- {
- $should_populate_object = true;
// We should populate this object
- $added_object_ids[] =
$result_id; // We keep the id
- }
- }
- }
- if($should_populate_object)
- {
- $result = &$results[$result_id];
- $results[$result_id] =
$this->populate($result_id,$result);
- $last_result_id = $result_id;
- $map[$result_id] = (int)$map[$result_id] +1;
- }
-
- //Stop looping when array not sorted on other then id
and wanted number of results is reached
- if(count($results) == $num_of_objects &&
$last_result_id != $result_id && $break_when_num_of_objects_reached)
- {
- break;
- }
- // else stop looping when wanted number of results is
reached all records for result objects are read
- else if($break_on_limit && (count($results) ==
$num_of_objects) && $last_result_id != $result_id)
- {
- $id_ok = 0;
- foreach ($map as $_result_id => $_count)
- {
- if(!isset($check_map[$_result_id]))
- {
- // Query the number of records
for the specific object in question
- $sql2 = "{$sql_parts[0]} 1=1
AND {$id_field_name_info['table']}.{$id_field_name_info['field']} =
{$_result_id} {$sql_parts[1]}";
- $db2->query($sql2,__LINE__,
__FILE__);
- $db2->next_record();
- $check_map[$_result_id] =
$db2->num_rows();
- }
- if( $check_map[$_result_id] ==
$_count )
- {
- $id_ok++;
- }
- }
- if($id_ok == $num_of_objects)
- {
- break;
- }
- }
- }
-
- return $results;
- }
-
- /**
- * Returns count of matching objects.
- *
- * @param $search_for string with free text search query.
- * @param $search_type string with the query type.
- * @param $filters array with key => value of filters.
- * @return int with object count.
- */
- public function get_count(string $search_for, string $search_type,
array $filters)
- {
- return $this->get_query_count($this->get_query(null, null,
$search_for, $search_type, $filters, true));
- }
-
- /**
- * Implementing classes must return the name of the field used in the
query
- * returned from get_query().
- *
- * @return string with name of id field.
- */
- protected abstract function get_id_field_name();
-
- /**
- * Returns SQL for retrieving matching objects or object count.
- *
- * @param $start_index int with index of first object.
- * @param $num_of_objects int with max number of objects to return.
- * @param $sort_field string representing the object field to sort on.
- * @param $ascending boolean true for ascending sort on sort field,
false
- * for descending.
- * @param $search_for string with free text search query.
- * @param $search_type string with the query type.
- * @param $filters array with key => value of filters.
- * @param $return_count boolean telling to return only the count of the
- * matching objects, or the objects themself.
- * @return string with SQL.
- */
-
- protected abstract function get_query(string $sort_field, boolean
$ascending, string $search_for, string $search_type, array $filters, boolean
$return_count);
-
- protected abstract function populate(int $object_id, &$object);
-
- protected abstract function add(&$object);
-
- protected abstract function update($object);
-
- /**
- * Store the object in the database. If the object has no ID it is
assumed to be new and
- * inserted for the first time. The object is then updated with the new
insert id.
- */
-
- public function store(&$object)
- {
- if ($object->validates()) {
- if ($object->get_id() > 0) {
- // We can assume this composite came from the
database since it has an ID. Update the existing row
- return $this->update($object);
- }
- else
- {
- // This object does not have an ID, so will be
saved as a new DB row
- return $this->add($object);
- }
- }
-
- // The object did not validate
- return false;
- }
-
-}
-?>
\ No newline at end of file
+<?php
+ /**
+ * phpGroupWare - controller: a part of a Facilities Management System.
+ *
+ * @author Erink Holm-Larsen <address@hidden>
+ * @author Torstein Vadla <address@hidden>
+ * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage controller
+ * @version $Id$
+ */
+
+ abstract class controller_socommon
+ {
+ protected $db;
+ protected $like;
+ protected $join;
+ protected $left_join;
+
+ public function __construct()
+ {
+ $this->db = clone
$GLOBALS['phpgw']->db;
+ $this->like = & $this->db->like;
+ $this->join = & $this->db->join;
+ $this->left_join = & $this->db->left_join;
+ }
+
+ /**
+ * Marshal values according to type
+ * @param $value the value
+ * @param $type the type of value
+ * @return database value
+ */
+ protected function marshal($value, $type)
+ {
+ if($value === null)
+ {
+ return 'NULL';
+ }
+ else if($type == 'int')
+ {
+ if($value == '')
+ {
+ return 'NULL';
+ }
+ return intval($value);
+ }
+ else if($type == 'float')
+ {
+ return str_replace(',', '.', $value);
+ }
+ else if($type == 'field')
+ {
+ return $this->db->db_addslashes($value);
+ }
+
+ return "'" . $this->db->db_addslashes($value) . "'";
+ }
+
+ /*
+
+ /**
+ * Unmarchal database values according to type
+ * @param $value the field value
+ * @param $type a string dictating value type
+ * @return the php value
+ */
+ protected function unmarshal($value, $type)
+ {
+ if($type == 'bool')
+ {
+ return (boolean)$value;
+ }
+ elseif($value === null || $value == 'NULL')
+ {
+ return null;
+ }
+ elseif($type == 'int')
+ {
+ return intval($value);
+ }
+ elseif($type == 'float')
+ {
+ return floatval($value);
+ }
+ return $value;
+ }
+
+ /**
+ * Get the count of the specified query. Query must return a
signel column
+ * called count.
+ *
+ * @param $sql the sql query
+ * @return the count value
+ */
+ protected function get_query_count($sql)
+ {
+ $result = $this->db->query($sql);
+ if($result && $this->db->next_record())
+ {
+ return $this->unmarshal($this->db->f('count',
true), 'int');
+ }
+ }
+
+ /**
+ * Implementing classes must return an instance of itself.
+ *
+ * @return the class instance.
+ */
+ public abstract static function get_instance();
+
+ /**
+ * Convenience method for getting one single object. Calls
get() with the
+ * specified id as a filter.
+ *
+ * @param $id int with id of object to return.
+ * @return object with the specified id, null if not found.
+ */
+ public function get_single(int $id)
+ {
+ $objects = $this->get(null, null, null, null, null,
null, array($this->get_id_field_name() => $id));
+ if(count($objects) > 0)
+ {
+ $keys = array_keys($objects);
+ return $objects[$keys[0]];
+ }
+ return null;
+ }
+
+ /**
+ * Method for retrieving the db-object (security "forgotten")
+ */
+ public function get_db(){
+ return $this->db;
+ }
+
+ /**
+ * Method for retreiving objects.
+ *
+ * @param $start_index int with index of first object.
+ * @param $num_of_objects int with max number of objects to
return.
+ * @param $sort_field string representing the object field to
sort on.
+ * @param $ascending boolean true for ascending sort on sort
field, false
+ * for descending.
+ * @param $search_for string with free text search query.
+ * @param $search_type string with the query type.
+ * @param $filters array with key => value of filters.
+ * @return array of objects. May return an empty
+ * array, never null. The array keys are the respective index
numbers.
+ */
+ public function get(int $start_index, int $num_of_objects,
string $sort_field, boolean $ascending, string $search_for, string
$search_type, array $filters)
+ {
+ $results = array(); // Array to
store result objects
+ $map = array(); // Array to
hold number of records per target object
+ $check_map = array(); // Array to hold the
actual number of record read per target object
+ $object_ids = array(); // All of the object
ids encountered
+ $added_object_ids = array();// All of the added objects
ids
+
+ // Retrieve information about the table name and the
name and alias of id column
+ // $break_on_limit - flag indicating whether to
break the loop when the number of records
+ // for all
the result objects are traversed
+ $id_field_name_info = $this->get_id_field_name(true);
+ if(is_array($id_field_name_info))
+ {
+ $break_on_limit = true;
+ $id_field_name =
$id_field_name_info['translated'];
+ }
+ else
+ {
+ $break_on_limit = false;
+ $id_field_name = $id_field_name_info;
+ }
+
+ // Special case: Sort on id field. Always changed to
the id field name.
+ // $break_when_num_of_objects_reached - flag indicating
to break the loop when the number of
+ // results are reached and we are sure
that the records are ordered by the id
+ if($sort_field == null || $sort_field == 'id' ||
$sort_field == '')
+ {
+ $sort_field = $id_field_name;
+ $break_when_num_of_objects_reached = true;
+ }
+ else
+ {
+ $break_when_num_of_objects_reached = false;
+ }
+
+ // Only allow positive start index
+ if($start_index < 0)
+ {
+ $start_index = 0;
+ }
+
+ // test-input for break on ordered queries
+ $db2 = clone($this->db);
+
+ $sql = $this->get_query($sort_field, $ascending,
$search_for, $search_type, $filters, false);
+
+ $sql_parts = explode('1=1',$sql); // Split the query to
insert extra condition on test for break
+ $this->db->query($sql,__LINE__, __FILE__, false, true);
+
+ while ($this->db->next_record()) // Runs through all of
the results
+ {
+ $should_populate_object = false; // Default
value - we won't populate object
+ $result_id =
$this->unmarshal($this->db->f($id_field_name), 'int'); // The id of object
+
+ if(in_array($result_id, $added_object_ids)) //
Object with this id already added
+ {
+ $should_populate_object = true; // We
should populate this object as we already have it in our result array
+ }
+ else // Object isn't already added to array
+ {
+ if(!in_array($result_id, $object_ids))
// Haven't already added this id
+ {
+ $object_ids[] = $result_id; //
We have to add the new id
+ }
+ // We have to check if we should
populate this object
+ if(count($object_ids) > $start_index)
// We're at index above start index
+ {
+ if($num_of_objects == null ||
count($results) < $num_of_objects) // We haven't found all the objects we're
looking for
+ {
+ $should_populate_object
= true; // We should populate this object
+ $added_object_ids[] =
$result_id; // We keep the id
+ }
+ }
+ }
+ if($should_populate_object)
+ {
+ $result = &$results[$result_id];
+ $results[$result_id] =
$this->populate($result_id,$result);
+ $last_result_id = $result_id;
+ $map[$result_id] =
(int)$map[$result_id] +1;
+ }
+
+ //Stop looping when array not sorted on other
then id and wanted number of results is reached
+ if(count($results) == $num_of_objects &&
$last_result_id != $result_id && $break_when_num_of_objects_reached)
+ {
+ break;
+ }
+ // else stop looping when wanted number of
results is reached all records for result objects are read
+ else if($break_on_limit && (count($results) ==
$num_of_objects) && $last_result_id != $result_id)
+ {
+ $id_ok = 0;
+ foreach ($map as $_result_id => $_count)
+ {
+
if(!isset($check_map[$_result_id]))
+ {
+ // Query the number of
records for the specific object in question
+ $sql2 =
"{$sql_parts[0]} 1=1 AND
{$id_field_name_info['table']}.{$id_field_name_info['field']} = {$_result_id}
{$sql_parts[1]}";
+
$db2->query($sql2,__LINE__, __FILE__);
+ $db2->next_record();
+ $check_map[$_result_id]
= $db2->num_rows();
+ }
+ if( $check_map[$_result_id]
== $_count )
+ {
+ $id_ok++;
+ }
+ }
+ if($id_ok == $num_of_objects)
+ {
+ break;
+ }
+ }
+ }
+
+ return $results;
+ }
+
+ /**
+ * Returns count of matching objects.
+ *
+ * @param $search_for string with free text search query.
+ * @param $search_type string with the query type.
+ * @param $filters array with key => value of filters.
+ * @return int with object count.
+ */
+ public function get_count(string $search_for, string
$search_type, array $filters)
+ {
+ return $this->get_query_count($this->get_query(null,
null, $search_for, $search_type, $filters, true));
+ }
+
+ /**
+ * Implementing classes must return the name of the field used
in the query
+ * returned from get_query().
+ *
+ * @return string with name of id field.
+ */
+ protected abstract function get_id_field_name();
+
+ /**
+ * Returns SQL for retrieving matching objects or object count.
+ *
+ * @param $start_index int with index of first object.
+ * @param $num_of_objects int with max number of objects to
return.
+ * @param $sort_field string representing the object field to
sort on.
+ * @param $ascending boolean true for ascending sort on sort
field, false
+ * for descending.
+ * @param $search_for string with free text search query.
+ * @param $search_type string with the query type.
+ * @param $filters array with key => value of filters.
+ * @param $return_count boolean telling to return only the
count of the
+ * matching objects, or the objects themself.
+ * @return string with SQL.
+ */
+
+ protected abstract function get_query(string $sort_field,
boolean $ascending, string $search_for, string $search_type, array $filters,
boolean $return_count);
+
+ protected abstract function populate(int $object_id, &$object);
+
+ protected abstract function add(&$object);
+
+ protected abstract function update($object);
+
+ /**
+ * Store the object in the database. If the object has no ID it
is assumed to be new and
+ * inserted for the first time. The object is then updated with
the new insert id.
+ */
+
+ public function store(&$object)
+ {
+ if ($object->validates()) {
+ if ($object->get_id() > 0) {
+ // We can assume this composite came
from the database since it has an ID. Update the existing row
+ return $this->update($object);
+ }
+ else
+ {
+ // This object does not have an ID, so
will be saved as a new DB row
+ return $this->add($object);
+ }
+ }
+
+ // The object did not validate
+ return false;
+ }
+
+ }
Modified: trunk/controller/inc/class.socontrol.inc.php
===================================================================
--- trunk/controller/inc/class.socontrol.inc.php 2011-12-11 11:30:28 UTC
(rev 8266)
+++ trunk/controller/inc/class.socontrol.inc.php 2011-12-11 12:27:18 UTC
(rev 8267)
@@ -1,447 +1,476 @@
-<?php
-phpgw::import_class('controller.socommon');
-
-include_class('controller', 'control', 'inc/model/');
-
-class controller_socontrol extends controller_socommon
-{
- protected static $so;
-
- /**
- * Get a static reference to the storage object associated with this
model object
- *
- * @return controller_soparty the storage object
- */
- public static function get_instance()
- {
- if (self::$so == null) {
- self::$so = CreateObject('controller.socontrol');
- }
- return self::$so;
- }
-
- /**
- * Function for adding a new control to the database. Updates the
control object.
- *
- * @param activitycalendar_activity $activity the party to be added
- * @return bool true if successful, false otherwise
- */
- function add(&$control)
- {
- $title = $control->get_title();
-
- $sql = "INSERT INTO controller_control (title) VALUES
('$title')";
- $result = $this->db->query($sql, __LINE__,__FILE__);
-
- if(isset($result)) {
-
- // Set the new control ID
-
$control->set_id($this->db->get_last_insert_id('controller_control', 'id'));
-
- // Forward this request to the update method
- return $this->update($control);
- }
- else
- {
- return false;
- }
- }
-
- /**
- * Update the database values for an existing activity object.
- *
- * @param $activity the activity to be updated
- * @return boolean true if successful, false otherwise
- */
- function update($control)
- {
-
- $id = intval($control->get_id());
-
- $values = array(
- 'title = ' . $this->marshal($control->get_title(),
'string'),
- 'description = ' .
$this->marshal($control->get_description(), 'string'),
- 'start_date = ' .
$this->marshal($control->get_start_date(), 'int'),
- 'end_date = ' .
$this->marshal($control->get_end_date(), 'int'),
- 'control_area_id = ' .
$this->marshal($control->get_control_area_id()),
- 'repeat_type = ' .
$this->marshal($control->get_repeat_type(), 'string'),
- 'repeat_interval = ' .
$this->marshal($control->get_repeat_interval(), 'string'),
- 'procedure_id = ' .
$this->marshal($control->get_procedure_id(), 'int'),
- 'responsibility_id = ' .
$this->marshal($control->get_responsibility_id(), 'int')
- );
-
- $result = $this->db->query('UPDATE controller_control SET ' .
join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
-
- if( isset($result) ){
- return $id;
- }else{
- return 0;
- }
-
- // Kommenterte denne ut midlertidig.
- //Trenger id-en som ble lagret når controllen blir lagret.
- //return isset($result);
- }
-
-
-
- function get_controls_by_control_area($control_area_id)
- {
- $controls_array = array();
-
- $sql = "SELECT * FROM controller_control WHERE
control_area_id=$control_area_id";
- $this->db->query($sql);
-
- while($this->db->next_record()) {
- $control = new
controller_control($this->unmarshal($this->db->f('id', true), 'int'));
-
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
-
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
-
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
-
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
-
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
-
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
-
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
-
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
-
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
-
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
-
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
-
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
-
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
-
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
-
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
-
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
-
- $controls_array[] = $control->toArray();
- }
-
- if( count( $controls_array ) > 0 ){
- return $controls_array;
- }
- else
- {
- return null;
- }
- }
-
- function get_locations_for_control($control_id)
- {
- $controls_array = array();
-
- $sql = "SELECT c.id, c.title, cll.location_code ";
- $sql .= "FROM controller_control c,
controller_control_location_list cll ";
- $sql .= "WHERE cll.control_id = $control_id ";
- $sql .= "AND cll.control_id = c.id";
-
- $this->db->query($sql);
-
- while($this->db->next_record()) {
- $control_id = $this->unmarshal($this->db->f('id',
true), 'int');
- $title = $this->unmarshal($this->db->f('title', true),
'string');
- $location_code =
$this->unmarshal($this->db->f('location_code', true), 'int');
-
- $location_array =
execMethod('property.bolocation.read_single', array('location_code' =>
$location_code));
-
- $controls_array[] = array("id" => $control_id, "title"
=> $title, "location_code" => $location_code, "loc1_name" =>
$location_array["loc1_name"]);
- }
-
- if( count( $controls_array ) > 0 ){
- return $controls_array;
- }
- else
- {
- return null;
- }
- }
-
- function add_location_to_control($control_id, $location_code)
- {
- $sql = "INSERT INTO controller_control_location_list
(control_id, location_code) values($control_id, $location_code)";
- $this->db->query($sql);
- }
-
- function add_component_to_control($control_id, $component_id)
- {
- $sql = "INSERT INTO controller_control_component_list
(control_id, component_id) values($control_id, $component_id)";
- $this->db->query($sql);
- }
-
- function get_id_field_name($extended_info = false)
- {
- if(!$extended_info)
- {
- $ret = 'id';
- }
- else
- {
- $ret = array
- (
- 'table' => 'control', // alias
- 'field' => 'id',
- 'translated' => 'id'
- );
- }
-
- return $ret;
- }
-
- protected function get_query(string $sort_field, boolean $ascending,
string $search_for, string $search_type, array $filters, boolean $return_count)
- {
- $clauses = array('1=1');
-
- $filter_clauses = array();
-
- // Search for based on search type
- if($search_for)
- {
- $search_for = $this->marshal($search_for,'field');
- $like_pattern = "'%".$search_for."%'";
- $like_clauses = array();
- switch($search_type){
- default:
- $like_clauses[] =
"controller_control.title $this->like $like_pattern";
- $like_clauses[] =
"controller_control.description $this->like $like_pattern";
- break;
- }
-
- if(count($like_clauses))
- {
- $clauses[] = '(' . join(' OR ', $like_clauses)
. ')';
- }
- }
- //var_dump($filters);
- if(isset($filters[$this->get_id_field_name()]))
- {
- $filter_clauses[] = "controller_control.id =
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
- }
- if(isset($filters['control_areas']))
- {
- $filter_clauses[] = "controller_control.control_area_id
= {$this->marshal($filters['control_areas'],'int')}";
- }
- if(isset($filters['responsibilities']))
- {
- $filter_clauses[] =
"controller_control.responsibility_id =
{$this->marshal($filters['responsibilities'],'int')}";
- }
-
- if(count($filter_clauses))
- {
- $clauses[] = join(' AND ', $filter_clauses);
- }
-
-
- $condition = join(' AND ', $clauses);
-
- $tables = "controller_control";
- //$joins = " {$this->left_join} rental_document_types ON
(rental_document.type_id = rental_document_types.id)";
- $joins = " {$this->left_join} controller_control_area ON
(controller_control.control_area_id = controller_control_area.id)";
- $joins .= " {$this->left_join} controller_procedure ON
(controller_control.procedure_id = controller_procedure.id)";
- $joins .= " {$this->left_join} fm_responsibility_role ON
(controller_control.responsibility_id = fm_responsibility_role.id)";
-
- if($return_count)
- {
- $cols = 'COUNT(DISTINCT(controller_control.id)) AS
count';
- }
- else
- {
- $cols = 'controller_control.id,
controller_control.title, controller_control.description,
controller_control.start_date, controller_control.end_date,
controller_control.procedure_id, controller_control.control_area_id,
controller_control.requirement_id, controller_control.costresponsibility_id,
controller_control.responsibility_id, controller_control.component_type_id,
controller_control.component_id, controller_control.location_code,
controller_control.repeat_type, controller_control.repeat_interval,
controller_control.enabled, controller_control_area.title AS control_area_name,
controller_procedure.title AS procedure_name, fm_responsibility_role.name AS
responsibility_name ';
- }
-
- $dir = $ascending ? 'ASC' : 'DESC';
- if($sort_field == 'title')
- {
- $sort_field = 'controller_control.title';
- }
- else if($sort_field == 'id')
- {
- $sort_field = 'controller_control.id';
- }
- $order = $sort_field ? "ORDER BY {$this->marshal($sort_field,
'field')} $dir ": '';
-
- return "SELECT {$cols} FROM {$tables} {$joins} WHERE
{$condition} {$order}";
-
- }
-
- function populate(int $control_id, &$control)
- {
- if($control == null) {
- $control = new controller_control((int) $control_id);
-
-
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
-
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
-
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
-
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
-
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
-
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
-
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
-
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
-
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
-
$control->set_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
true), 'string'));
-
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
-
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
-//
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
true), 'int'));
-
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
-
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
-
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
-
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
-
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
- }
-
- return $control;
- }
-
- /**
- * Get single control
- *
- * @param $id id of the control to return
- * @return a controller_control
- */
- function get_single($id)
- {
- $id = (int)$id;
-
- $joins = " {$this->left_join} controller_control_area ON
(c.control_area_id = controller_control_area.id)";
- $joins .= " {$this->left_join} controller_procedure ON
(c.procedure_id = controller_procedure.id)";
- $joins .= " {$this->left_join} fm_responsibility_role ON
(c.responsibility_id = fm_responsibility_role.id)";
-
- $sql = "SELECT c.*, controller_control_area.title AS
control_area_name, controller_procedure.title AS procedure_name,
fm_responsibility_role.name AS responsibility_name FROM controller_control c
{$joins} WHERE c.id = " . $id;
- $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
- $this->db->next_record();
-
- $control = new controller_control((int) $id);
-
- $control->set_title($this->unmarshal($this->db->f('title',
true), 'string'));
-
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
-
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
-
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
-
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
-
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
-
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
-
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
-
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
-
$control->set_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
true), 'string'));
-
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
-
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
-//
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
true), 'int'));
-
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
-
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
-
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
-
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
-
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
-
- return $control;
- }
-
- function get_roles()
- {
- $ret_array = array();
- $ret_array[0] = array('id' => 0,'name' => lang('Not
selected'));
- $sql = "select * from fm_responsibility_role ORDER BY name";
- $this->db->query($sql, __LINE__, __FILE__);
- $i = 1;
- while($this->db->next_record())
- {
- $ret_array[$i]['id'] = $this->db->f('id');
- $ret_array[$i]['name'] = $this->db->f('name');
- $i++;
- }
- return $ret_array;
- }
-
- function get_bim_types($ifc = null)
- {
- $ret_array = array();
- if($ifc != null)
- {
- if($ifc == 1)
- $where_clause = "WHERE is_ifc";
- else
- $where_clause = "WHERE NOT is_ifc";
- }
- $sql = "select * from fm_bim_type {$where_clause} ORDER BY
name";
- $this->db->query($sql, __LINE__, __FILE__);
- $i = 1;
- while($this->db->next_record())
- {
- $ret_array[$i]['id'] = $this->db->f('id');
- $ret_array[$i]['name'] = $this->db->f('name');
- $i++;
- }
- return $ret_array;
- }
-
- public function getAllBimItems($noOfObjects = null, $bim_type = null) {
- $filters = array();
- if($noOfObjects != null && is_numeric($noOfObjects))
- {
- $limit = "LIMIT {$noOfObjects}";
- }
- else
- {
- $limit = "LIMIT 10";
- }
- if($bim_type != null && is_numeric($bim_type))
- {
- $filter = " AND fm_bim_type.id = {$bim_type}";
- }
- $sql = "SELECT fm_bim_item.id, fm_bim_type.name AS type,
fm_bim_item.guid FROM public.fm_bim_item, public.fm_bim_type WHERE
fm_bim_item.type = fm_bim_type.id {$filter} {$limit}";
- $bimItemArray = array();
- $this->db->query($sql, __LINE__, __FILE__);
- $i=1;
- while($this->db->next_record())
- {
- $bimItemArray[$i]['id'] = $this->db->f('id');
- $bimItemArray[$i]['guid'] = $this->db->f('guid');
- $bimItemArray[$i]['type'] = $this->db->f('type');
- //$bimItemArray[$i]['xml_representation'] =
$this->db->f('xml_representation',true);
- //$bimItemArray[] = $bimItem;
- $i++;
- }
-
- return $bimItemArray;
- }
-
- public function get_control_component($noOfObjects = null, $bim_type =
null)
- {
- $filters = array();
- if($noOfObjects != null && is_numeric($noOfObjects))
- {
- $limit = "LIMIT {$noOfObjects}";
- }
- else
- {
- $limit = "LIMIT 10";
- }
-
- $joins = " {$this->left_join} controller_control_component_list
ON (c.id = controller_control_component_list.control_id)";
- $joins .= " {$this->left_join} fm_bim_item ON
(controller_control_component_list.component_id = fm_bim_item.id)";
- $joins .= " {$this->left_join} fm_bim_type ON
(fm_bim_item.type= fm_bim_type.id)";
- //$joins .= " {$this->left_join} fm_responsibility_role ON
(c.responsibility_id = fm_responsibility_role.id)";
- $sql = "SELECT c.id AS control_id, c.title AS control_title,
fm_bim_type.name AS type_name, fm_bim_item.id AS bim_id, fm_bim_item.guid as
bim_item_guid FROM controller_control c {$joins} {$limit}";
- $controlArray = array();
- $this->db->query($sql, __LINE__, __FILE__);
- $i=1;
- while($this->db->next_record())
- {
- $controlArray[$i]['id'] = $this->db->f('control_id');
- $controlArray[$i]['title'] =
$this->db->f('control_title');
- $controlArray[$i]['bim_id'] = $this->db->f('bim_id');
- $controlArray[$i]['bim_item_guid'] =
$this->db->f('bim_item_guid');
- $controlArray[$i]['bim_type'] =
$this->db->f('type_name');
- $i++;
- }
-
- return $controlArray;
- }
-
- public function getBimItemAttributeValue($bimItemGuid, $attribute)
- {
- $columnAlias = "attribute_values";
- $sql = "select
array_to_string(xpath('descendant-or-self::*[{$attribute}]/{$attribute}/text()',
(select xml_representation from fm_bim_item where guid='{$bimItemGuid}')),
',') as $columnAlias";
- $this->db->query($sql,__LINE__,__FILE__);
- if($this->db->num_rows() > 0)
- {
- $this->db->next_record();
- $result = $this->db->f($columnAlias,true);
- return preg_split('/,/', $result);
- }
- }
-}
+<?php
+ /**
+ * phpGroupWare - controller: a part of a Facilities Management System.
+ *
+ * @author Erink Holm-Larsen <address@hidden>
+ * @author Torstein Vadla <address@hidden>
+ * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage controller
+ * @version $Id$
+ */
+
+ phpgw::import_class('controller.socommon');
+
+ include_class('controller', 'control', 'inc/model/');
+
+ class controller_socontrol extends controller_socommon
+ {
+ protected static $so;
+
+ /**
+ * Get a static reference to the storage object associated with
this model object
+ *
+ * @return controller_soparty the storage object
+ */
+ public static function get_instance()
+ {
+ if (self::$so == null) {
+ self::$so =
CreateObject('controller.socontrol');
+ }
+ return self::$so;
+ }
+
+ /**
+ * Function for adding a new control to the database. Updates
the control object.
+ *
+ * @param activitycalendar_activity $activity the party to be
added
+ * @return bool true if successful, false otherwise
+ */
+ function add(&$control)
+ {
+ $title = $control->get_title();
+
+ $sql = "INSERT INTO controller_control (title) VALUES
('$title')";
+ $result = $this->db->query($sql, __LINE__,__FILE__);
+
+ if(isset($result)) {
+
+ // Set the new control ID
+
$control->set_id($this->db->get_last_insert_id('controller_control', 'id'));
+
+ // Forward this request to the update method
+ return $this->update($control);
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /**
+ * Update the database values for an existing activity object.
+ *
+ * @param $activity the activity to be updated
+ * @return boolean true if successful, false otherwise
+ */
+ function update($control)
+ {
+
+ $id = intval($control->get_id());
+
+ $values = array(
+ 'title = ' .
$this->marshal($control->get_title(), 'string'),
+ 'description = ' .
$this->marshal($control->get_description(), 'string'),
+ 'start_date = ' .
$this->marshal($control->get_start_date(), 'int'),
+ 'end_date = ' .
$this->marshal($control->get_end_date(), 'int'),
+ 'control_area_id = ' .
$this->marshal($control->get_control_area_id()),
+ 'repeat_type = ' .
$this->marshal($control->get_repeat_type(), 'string'),
+ 'repeat_interval = ' .
$this->marshal($control->get_repeat_interval(), 'string'),
+ 'procedure_id = ' .
$this->marshal($control->get_procedure_id(), 'int'),
+ 'responsibility_id = ' .
$this->marshal($control->get_responsibility_id(), 'int')
+ );
+
+ $result = $this->db->query('UPDATE controller_control
SET ' . join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
+
+ if( isset($result) ){
+ return $id;
+ }else{
+ return 0;
+ }
+
+ // Kommenterte denne ut midlertidig.
+ //Trenger id-en som ble lagret når controllen blir
lagret.
+ //return isset($result);
+ }
+
+
+
+ function get_controls_by_control_area($control_area_id)
+ {
+ $controls_array = array();
+
+ $sql = "SELECT * FROM controller_control WHERE
control_area_id=$control_area_id";
+ $this->db->query($sql);
+
+ while($this->db->next_record()) {
+ $control = new
controller_control($this->unmarshal($this->db->f('id', true), 'int'));
+
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
+
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
+
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
+
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
+
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
+
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
+
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
+
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
+
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
+
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
+
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
+
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
+
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
+
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
+
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
+
+ $controls_array[] = $control->toArray();
+ }
+
+ if( count( $controls_array ) > 0 ){
+ return $controls_array;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ function get_locations_for_control($control_id)
+ {
+ $controls_array = array();
+
+ $sql = "SELECT c.id, c.title, cll.location_code ";
+ $sql .= "FROM controller_control c,
controller_control_location_list cll ";
+ $sql .= "WHERE cll.control_id = $control_id ";
+ $sql .= "AND cll.control_id = c.id";
+
+ $this->db->query($sql);
+
+ while($this->db->next_record()) {
+ $control_id =
$this->unmarshal($this->db->f('id', true), 'int');
+ $title = $this->unmarshal($this->db->f('title',
true), 'string');
+ $location_code =
$this->unmarshal($this->db->f('location_code', true), 'int');
+
+ $location_array =
execMethod('property.bolocation.read_single', array('location_code' =>
$location_code));
+
+ $controls_array[] = array("id" => $control_id,
"title" => $title, "location_code" => $location_code, "loc1_name" =>
$location_array["loc1_name"]);
+ }
+
+ if( count( $controls_array ) > 0 ){
+ return $controls_array;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ function add_location_to_control($control_id, $location_code)
+ {
+ $sql = "INSERT INTO controller_control_location_list
(control_id, location_code) values($control_id, $location_code)";
+ $this->db->query($sql);
+ }
+
+ function add_component_to_control($control_id, $component_id)
+ {
+ $sql = "INSERT INTO controller_control_component_list
(control_id, component_id) values($control_id, $component_id)";
+ $this->db->query($sql);
+ }
+
+ function get_id_field_name($extended_info = false)
+ {
+ if(!$extended_info)
+ {
+ $ret = 'id';
+ }
+ else
+ {
+ $ret = array
+ (
+ 'table' => 'control',
// alias
+ 'field' => 'id',
+ 'translated' => 'id'
+ );
+ }
+
+ return $ret;
+ }
+
+ protected function get_query(string $sort_field, boolean
$ascending, string $search_for, string $search_type, array $filters, boolean
$return_count)
+ {
+ $clauses = array('1=1');
+
+ $filter_clauses = array();
+
+ // Search for based on search type
+ if($search_for)
+ {
+ $search_for =
$this->marshal($search_for,'field');
+ $like_pattern = "'%".$search_for."%'";
+ $like_clauses = array();
+ switch($search_type){
+ default:
+ $like_clauses[] =
"controller_control.title $this->like $like_pattern";
+ $like_clauses[] =
"controller_control.description $this->like $like_pattern";
+ break;
+ }
+
+ if(count($like_clauses))
+ {
+ $clauses[] = '(' . join(' OR ',
$like_clauses) . ')';
+ }
+ }
+ //var_dump($filters);
+ if(isset($filters[$this->get_id_field_name()]))
+ {
+ $filter_clauses[] = "controller_control.id =
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
+ }
+ if(isset($filters['control_areas']))
+ {
+ $filter_clauses[] =
"controller_control.control_area_id =
{$this->marshal($filters['control_areas'],'int')}";
+ }
+ if(isset($filters['responsibilities']))
+ {
+ $filter_clauses[] =
"controller_control.responsibility_id =
{$this->marshal($filters['responsibilities'],'int')}";
+ }
+
+ if(count($filter_clauses))
+ {
+ $clauses[] = join(' AND ', $filter_clauses);
+ }
+
+
+ $condition = join(' AND ', $clauses);
+
+ $tables = "controller_control";
+ //$joins = " {$this->left_join} rental_document_types
ON (rental_document.type_id = rental_document_types.id)";
+ $joins = " {$this->left_join} controller_control_area
ON (controller_control.control_area_id = controller_control_area.id)";
+ $joins .= " {$this->left_join} controller_procedure ON
(controller_control.procedure_id = controller_procedure.id)";
+ $joins .= " {$this->left_join} fm_responsibility_role
ON (controller_control.responsibility_id = fm_responsibility_role.id)";
+
+ if($return_count)
+ {
+ $cols = 'COUNT(DISTINCT(controller_control.id))
AS count';
+ }
+ else
+ {
+ $cols = 'controller_control.id,
controller_control.title, controller_control.description,
controller_control.start_date, controller_control.end_date,
controller_control.procedure_id, controller_control.control_area_id,
controller_control.requirement_id, controller_control.costresponsibility_id,
controller_control.responsibility_id, controller_control.component_type_id,
controller_control.component_id, controller_control.location_code,
controller_control.repeat_type, controller_control.repeat_interval,
controller_control.enabled, controller_control_area.title AS control_area_name,
controller_procedure.title AS procedure_name, fm_responsibility_role.name AS
responsibility_name ';
+ }
+
+ $dir = $ascending ? 'ASC' : 'DESC';
+ if($sort_field == 'title')
+ {
+ $sort_field = 'controller_control.title';
+ }
+ else if($sort_field == 'id')
+ {
+ $sort_field = 'controller_control.id';
+ }
+ $order = $sort_field ? "ORDER BY
{$this->marshal($sort_field, 'field')} $dir ": '';
+
+ return "SELECT {$cols} FROM {$tables} {$joins} WHERE
{$condition} {$order}";
+
+ }
+
+ function populate(int $control_id, &$control)
+ {
+ if($control == null) {
+ $control = new controller_control((int)
$control_id);
+
+
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
+
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
+
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
+
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
+
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
+
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
+
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
+
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
+
$control->set_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
true), 'string'));
+
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
+
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
+ //
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
true), 'int'));
+
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
+
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
+
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
+
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
+
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
+ }
+
+ return $control;
+ }
+
+ /**
+ * Get single control
+ *
+ * @param $id id of the control to return
+ * @return a controller_control
+ */
+ function get_single($id)
+ {
+ $id = (int)$id;
+
+ $joins = " {$this->left_join} controller_control_area
ON (c.control_area_id = controller_control_area.id)";
+ $joins .= " {$this->left_join} controller_procedure ON
(c.procedure_id = controller_procedure.id)";
+ $joins .= " {$this->left_join} fm_responsibility_role
ON (c.responsibility_id = fm_responsibility_role.id)";
+
+ $sql = "SELECT c.*, controller_control_area.title AS
control_area_name, controller_procedure.title AS procedure_name,
fm_responsibility_role.name AS responsibility_name FROM controller_control c
{$joins} WHERE c.id = " . $id;
+ $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+ $this->db->next_record();
+
+ $control = new controller_control((int) $id);
+
+
$control->set_title($this->unmarshal($this->db->f('title', true), 'string'));
+
$control->set_description($this->unmarshal($this->db->f('description', true),
'boolean'));
+
$control->set_start_date($this->unmarshal($this->db->f('start_date', true),
'int'));
+
$control->set_end_date($this->unmarshal($this->db->f('end_date', true), 'int'));
+
$control->set_procedure_id($this->unmarshal($this->db->f('procedure_id', true),
'int'));
+
$control->set_procedure_name($this->unmarshal($this->db->f('procedure_name',
true), 'string'));
+
$control->set_requirement_id($this->unmarshal($this->db->f('requirement_id',
true), 'int'));
+
$control->set_costresponsibility_id($this->unmarshal($this->db->f('costresponsibility_id',
true), 'int'));
+
$control->set_responsibility_id($this->unmarshal($this->db->f('responsibility_id',
true), 'int'));
+
$control->set_responsibility_name($this->unmarshal($this->db->f('responsibility_name',
true), 'string'));
+
$control->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'int'));
+
$control->set_control_area_name($this->unmarshal($this->db->f('control_area_name',
true), 'string'));
+ //
$control->set_control_group_id($this->unmarshal($this->db->f('control_group_id',
true), 'int'));
+
$control->set_component_type_id($this->unmarshal($this->db->f('component_type_id',
true), 'int'));
+
$control->set_component_id($this->unmarshal($this->db->f('component_id', true),
'int'));
+
$control->set_location_code($this->unmarshal($this->db->f('location_code',
true), 'int'));
+
$control->set_repeat_type($this->unmarshal($this->db->f('repeat_type', true),
'int'));
+
$control->set_repeat_interval($this->unmarshal($this->db->f('repeat_interval',
true), 'int'));
+
+ return $control;
+ }
+
+ function get_roles()
+ {
+ $ret_array = array();
+ $ret_array[0] = array('id' => 0,'name' => lang('Not
selected'));
+ $sql = "select * from fm_responsibility_role ORDER BY
name";
+ $this->db->query($sql, __LINE__, __FILE__);
+ $i = 1;
+ while($this->db->next_record())
+ {
+ $ret_array[$i]['id'] = $this->db->f('id');
+ $ret_array[$i]['name'] = $this->db->f('name');
+ $i++;
+ }
+ return $ret_array;
+ }
+
+ function get_bim_types($ifc = null)
+ {
+ $ret_array = array();
+ if($ifc != null)
+ {
+ if($ifc == 1)
+ $where_clause = "WHERE is_ifc";
+ else
+ $where_clause = "WHERE NOT is_ifc";
+ }
+ $sql = "select * from fm_bim_type {$where_clause} ORDER
BY name";
+ $this->db->query($sql, __LINE__, __FILE__);
+ $i = 1;
+ while($this->db->next_record())
+ {
+ $ret_array[$i]['id'] = $this->db->f('id');
+ $ret_array[$i]['name'] = $this->db->f('name');
+ $i++;
+ }
+ return $ret_array;
+ }
+
+ public function getAllBimItems($noOfObjects = null, $bim_type =
null) {
+ $filters = array();
+ if($noOfObjects != null && is_numeric($noOfObjects))
+ {
+ $limit = "LIMIT {$noOfObjects}";
+ }
+ else
+ {
+ $limit = "LIMIT 10";
+ }
+ if($bim_type != null && is_numeric($bim_type))
+ {
+ $filter = " AND fm_bim_type.id = {$bim_type}";
+ }
+ $sql = "SELECT fm_bim_item.id, fm_bim_type.name AS
type, fm_bim_item.guid FROM public.fm_bim_item, public.fm_bim_type WHERE
fm_bim_item.type = fm_bim_type.id {$filter} {$limit}";
+ $bimItemArray = array();
+ $this->db->query($sql, __LINE__, __FILE__);
+ $i=1;
+ while($this->db->next_record())
+ {
+ $bimItemArray[$i]['id'] = $this->db->f('id');
+ $bimItemArray[$i]['guid'] =
$this->db->f('guid');
+ $bimItemArray[$i]['type'] =
$this->db->f('type');
+ //$bimItemArray[$i]['xml_representation'] =
$this->db->f('xml_representation',true);
+ //$bimItemArray[] = $bimItem;
+ $i++;
+ }
+
+ return $bimItemArray;
+ }
+
+ public function get_control_component($noOfObjects = null,
$bim_type = null)
+ {
+ $filters = array();
+ if($noOfObjects != null && is_numeric($noOfObjects))
+ {
+ $limit = "LIMIT {$noOfObjects}";
+ }
+ else
+ {
+ $limit = "LIMIT 10";
+ }
+
+ $joins = " {$this->left_join}
controller_control_component_list ON (c.id =
controller_control_component_list.control_id)";
+ $joins .= " {$this->left_join} fm_bim_item ON
(controller_control_component_list.component_id = fm_bim_item.id)";
+ $joins .= " {$this->left_join} fm_bim_type ON
(fm_bim_item.type= fm_bim_type.id)";
+ //$joins .= " {$this->left_join} fm_responsibility_role
ON (c.responsibility_id = fm_responsibility_role.id)";
+ $sql = "SELECT c.id AS control_id, c.title AS
control_title, fm_bim_type.name AS type_name, fm_bim_item.id AS bim_id,
fm_bim_item.guid as bim_item_guid FROM controller_control c {$joins} {$limit}";
+ $controlArray = array();
+ $this->db->query($sql, __LINE__, __FILE__);
+ $i=1;
+ while($this->db->next_record())
+ {
+ $controlArray[$i]['id'] =
$this->db->f('control_id');
+ $controlArray[$i]['title'] =
$this->db->f('control_title');
+ $controlArray[$i]['bim_id'] =
$this->db->f('bim_id');
+ $controlArray[$i]['bim_item_guid'] =
$this->db->f('bim_item_guid');
+ $controlArray[$i]['bim_type'] =
$this->db->f('type_name');
+ $i++;
+ }
+
+ return $controlArray;
+ }
+
+ public function getBimItemAttributeValue($bimItemGuid,
$attribute)
+ {
+ $columnAlias = "attribute_values";
+ $sql = "select
array_to_string(xpath('descendant-or-self::*[{$attribute}]/{$attribute}/text()',
(select xml_representation from fm_bim_item where guid='{$bimItemGuid}')),
',') as $columnAlias";
+ $this->db->query($sql,__LINE__,__FILE__);
+ if($this->db->num_rows() > 0)
+ {
+ $this->db->next_record();
+ $result = $this->db->f($columnAlias,true);
+ return preg_split('/,/', $result);
+ }
+ }
+ }
Modified: trunk/controller/inc/class.socontrol_area.inc.php
===================================================================
--- trunk/controller/inc/class.socontrol_area.inc.php 2011-12-11 11:30:28 UTC
(rev 8266)
+++ trunk/controller/inc/class.socontrol_area.inc.php 2011-12-11 12:27:18 UTC
(rev 8267)
@@ -1,211 +1,240 @@
-<?php
-phpgw::import_class('controller.socommon');
-
-include_class('controller', 'control_area', 'inc/model/');
-
-class controller_socontrol_area extends controller_socommon
-{
- protected static $so;
-
- /**
- * Get a static reference to the storage object associated with this
model object
- *
- * @return controller_soparty the storage object
- */
- public static function get_instance()
- {
- if (self::$so == null)
- {
- self::$so = CreateObject('controller.socontrol_area');
- }
- return self::$so;
- }
-
- /**
- * Function for adding a new activity to the database. Updates the
activity object.
- *
- * @param activitycalendar_activity $activity the party to be added
- * @return bool true if successful, false otherwise
- */
- function add(&$control_area)
- {
-
- $control_area = $control_area->get_control_area();
-
- $sql = "INSERT INTO controller_control_area (type_name) VALUES
('$title')";
- $result = $this->db->query($sql, __LINE__,__FILE__);
-
- if(isset($result)) {
- // Set the new party ID
-
$control_area->set_id($this->db->get_last_insert_id('controller_control_area',
'id'));
- // Forward this request to the update method
- return $this->update($control_area);
- }
- else
- {
- return false;
- }
-
- }
-
- /**
- * Update the database values for an existing activity object.
- *
- * @param $activity the activity to be updated
- * @return boolean true if successful, false otherwise
- */
-
- function update($control_area)
- {
- $id = intval($control_area->get_id());
-
- $values = array(
- '$type_name = ' .
$this->marshal($control_area->get_type_name(), 'string')
- );
-
- //var_dump('UPDATE activity_activity SET ' . join(',', $values)
. " WHERE id=$id");
- $result = $this->db->query('UPDATE controller_control_area SET
' . join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
-
- return isset($result);
- }
-
- /**
- * Get single procedure
- *
- * @param $id id of the procedure to return
- * @return a controller_procedure
- */
- function get_single($id)
- {
- $id = (int)$id;
-
- $sql = "SELECT p.* FROM controller_control_area p WHERE p.id =
" . $id;
- $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
- $this->db->next_record();
-
- $control_area = new
controller_control_area($this->unmarshal($this->db->f('id', true), 'int'));
- $control_area->set_title($this->unmarshal($this->db->f('title',
true), 'string'));
-
- return $control_area;
- }
-
- /**
- * Get a list of procedure objects matching the specific filters
- *
- * @param $start search result offset
- * @param $results number of results to return
- * @param $sort field to sort by
- * @param $query LIKE-based query string
- * @param $filters array of custom filters
- * @return list of rental_composite objects
- */
- function get_control_area_array($start = 0, $results = 1000, $sort =
null, $dir = '', $query = null, $search_option = null, $filters = array())
- {
- $results = array();
-
- //$condition = $this->get_conditions($query,
$filters,$search_option);
- $order = $sort ? "ORDER BY $sort $dir ": '';
-
- //$sql = "SELECT * FROM controller_procedure WHERE $condition
$order";
- $sql = "SELECT * FROM controller_control_area $order";
- $this->db->limit_query($sql, $start, __LINE__, __FILE__,
$limit);
-
- while ($this->db->next_record()) {
- $control_area = new
controller_control_area($this->unmarshal($this->db->f('id', true), 'int'));
-
$control_area->set_title($this->unmarshal($this->db->f('title', true),
'string'));
-
- $results[] = $control_area;
- }
-
- return $results;
- }
-
- function get_control_areas_as_array($start = 0, $results = 1000, $sort
= null, $dir = '', $query = null, $search_option = null, $filters = array())
- {
- $results = array();
-
- //$condition = $this->get_conditions($query,
$filters,$search_option);
- $order = $sort ? "ORDER BY $sort $dir ": '';
-
- //$sql = "SELECT * FROM controller_procedure WHERE $condition
$order";
- $sql = "SELECT * FROM controller_control_area $order";
- $this->db->limit_query($sql, $start, __LINE__, __FILE__,
$limit);
-
- while ($this->db->next_record()) {
- $control_area = new
controller_control_area($this->unmarshal($this->db->f('id', true), 'int'));
-
$control_area->set_title($this->unmarshal($this->db->f('title', true),
'string'));
-
- $results[] = $control_area->toArray();
- }
-
- return $results;
- }
-
- function get_control_area_select_array()
- {
- $results = array();
- $results[] = array('id' => 0,'name' => lang('Not
selected'));
- $this->db->query("SELECT id, title as name FROM
controller_control_area ORDER BY name ASC", __LINE__, __FILE__);
- while ($this->db->next_record())
- {
- $results[] = array('id' => $this->db->f('id',
false),
- 'name' =>
$this->db->f('name', false));
- }
- return $results;
- }
-
- function get_id_field_name($extended_info = false)
- {
- /*
- if(!$extended_info)
- {
- $ret = 'id';
- }
- else
- {
- $ret = array
- (
- 'table' => 'activity', // alias
- 'field' => 'id',
- 'translated' => 'id'
- );
- }
- */
- return $ret;
- }
-
- protected function get_query(string $sort_field, boolean $ascending,
string $search_for, string $search_type, array $filters, boolean $return_count)
- {
-
-
- }
-
- function populate(int $control_area_id, &$control_area)
- {
- /*
- if($control_area == null) {
- $control_area = new activitycalendar_activity((int)
$activity_id);
-
-
$control_area->set_title($this->unmarshal($this->db->f('title'), 'string'));
-
$control_area->set_organization_id($this->unmarshal($this->db->f('organization_id'),
'int'));
-
$control_area->set_type_id($this->unmarshal($this->db->f('type_id'), 'int'));
-
$control_area->set_district($this->unmarshal($this->db->f('district'), 'int'));
-
$control_area->set_office($this->unmarshal($this->db->f('office'), 'int'));
-
$control_area->set_category($this->unmarshal($this->db->f('category'), 'int'));
-
$control_area->set_state($this->unmarshal($this->db->f('state'), 'int'));
-
$control_area->set_target($this->unmarshal($this->db->f('target'), 'string'));
-
$control_area->set_description($this->unmarshal($this->db->f('description'),
'string'));
-
$control_area->set_arena($this->unmarshal($this->db->f('arena'), 'string'));
-
$control_area->set_internal_arena($this->unmarshal($this->db->f('internal_arena'),
'string'));
-
$control_area->set_time($this->unmarshal($this->db->f('time'), 'string'));
-
$control_area->set_last_change_date($this->unmarshal($this->db->f('last_change_date'),
'int'));
-
$control_area->set_special_adaptation($this->unmarshal($this->db->f('special_adaptation',
'bool')));
-
$control_area->set_secret($this->unmarshal($this->db->f('secret'), 'string'));
-
-
- }
- */
- return $control_area;
- }
-
-}
+<?php
+ /**
+ * phpGroupWare - controller: a part of a Facilities Management System.
+ *
+ * @author Erink Holm-Larsen <address@hidden>
+ * @author Torstein Vadla <address@hidden>
+ * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage controller
+ * @version $Id$
+ */
+
+ phpgw::import_class('controller.socommon');
+
+ include_class('controller', 'control_area', 'inc/model/');
+
+ class controller_socontrol_area extends controller_socommon
+ {
+ protected static $so;
+
+ /**
+ * Get a static reference to the storage object associated with
this model object
+ *
+ * @return controller_soparty the storage object
+ */
+ public static function get_instance()
+ {
+ if (self::$so == null)
+ {
+ self::$so =
CreateObject('controller.socontrol_area');
+ }
+ return self::$so;
+ }
+
+ /**
+ * Function for adding a new activity to the database. Updates
the activity object.
+ *
+ * @param activitycalendar_activity $activity the party to be
added
+ * @return bool true if successful, false otherwise
+ */
+ function add(&$control_area)
+ {
+
+ $control_area = $control_area->get_control_area();
+
+ $sql = "INSERT INTO controller_control_area (type_name)
VALUES ('$title')";
+ $result = $this->db->query($sql, __LINE__,__FILE__);
+
+ if(isset($result)) {
+ // Set the new party ID
+
$control_area->set_id($this->db->get_last_insert_id('controller_control_area',
'id'));
+ // Forward this request to the update method
+ return $this->update($control_area);
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
+ /**
+ * Update the database values for an existing activity object.
+ *
+ * @param $activity the activity to be updated
+ * @return boolean true if successful, false otherwise
+ */
+
+ function update($control_area)
+ {
+ $id = intval($control_area->get_id());
+
+ $values = array(
+ '$type_name = ' .
$this->marshal($control_area->get_type_name(), 'string')
+ );
+
+ //var_dump('UPDATE activity_activity SET ' . join(',',
$values) . " WHERE id=$id");
+ $result = $this->db->query('UPDATE
controller_control_area SET ' . join(',', $values) . " WHERE id=$id",
__LINE__,__FILE__);
+
+ return isset($result);
+ }
+
+ /**
+ * Get single procedure
+ *
+ * @param $id id of the procedure to return
+ * @return a controller_procedure
+ */
+ function get_single($id)
+ {
+ $id = (int)$id;
+
+ $sql = "SELECT p.* FROM controller_control_area p WHERE
p.id = " . $id;
+ $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+ $this->db->next_record();
+
+ $control_area = new
controller_control_area($this->unmarshal($this->db->f('id', true), 'int'));
+
$control_area->set_title($this->unmarshal($this->db->f('title', true),
'string'));
+
+ return $control_area;
+ }
+
+ /**
+ * Get a list of procedure objects matching the specific filters
+ *
+ * @param $start search result offset
+ * @param $results number of results to return
+ * @param $sort field to sort by
+ * @param $query LIKE-based query string
+ * @param $filters array of custom filters
+ * @return list of rental_composite objects
+ */
+ function get_control_area_array($start = 0, $results = 1000,
$sort = null, $dir = '', $query = null, $search_option = null, $filters =
array())
+ {
+ $results = array();
+
+ //$condition = $this->get_conditions($query,
$filters,$search_option);
+ $order = $sort ? "ORDER BY $sort $dir ": '';
+
+ //$sql = "SELECT * FROM controller_procedure WHERE
$condition $order";
+ $sql = "SELECT * FROM controller_control_area $order";
+ $this->db->limit_query($sql, $start, __LINE__,
__FILE__, $limit);
+
+ while ($this->db->next_record()) {
+ $control_area = new
controller_control_area($this->unmarshal($this->db->f('id', true), 'int'));
+
$control_area->set_title($this->unmarshal($this->db->f('title', true),
'string'));
+
+ $results[] = $control_area;
+ }
+
+ return $results;
+ }
+
+ function get_control_areas_as_array($start = 0, $results =
1000, $sort = null, $dir = '', $query = null, $search_option = null, $filters =
array())
+ {
+ $results = array();
+
+ //$condition = $this->get_conditions($query,
$filters,$search_option);
+ $order = $sort ? "ORDER BY $sort $dir ": '';
+
+ //$sql = "SELECT * FROM controller_procedure WHERE
$condition $order";
+ $sql = "SELECT * FROM controller_control_area $order";
+ $this->db->limit_query($sql, $start, __LINE__,
__FILE__, $limit);
+
+ while ($this->db->next_record()) {
+ $control_area = new
controller_control_area($this->unmarshal($this->db->f('id', true), 'int'));
+
$control_area->set_title($this->unmarshal($this->db->f('title', true),
'string'));
+
+ $results[] = $control_area->toArray();
+ }
+
+ return $results;
+ }
+
+ function get_control_area_select_array()
+ {
+ $results = array();
+ $results[] = array('id' => 0,'name' =>
lang('Not selected'));
+ $this->db->query("SELECT id, title as name FROM
controller_control_area ORDER BY name ASC", __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array('id' =>
$this->db->f('id', false),
+
'name' => $this->db->f('name', false));
+ }
+ return $results;
+ }
+
+ function get_id_field_name($extended_info = false)
+ {
+ /*
+ if(!$extended_info)
+ {
+ $ret = 'id';
+ }
+ else
+ {
+ $ret = array
+ (
+ 'table' => 'activity',
// alias
+ 'field' => 'id',
+ 'translated' => 'id'
+ );
+ }
+ */
+ return $ret;
+ }
+
+ protected function get_query(string $sort_field, boolean
$ascending, string $search_for, string $search_type, array $filters, boolean
$return_count)
+ {
+
+
+ }
+
+ function populate(int $control_area_id, &$control_area)
+ {
+ /*
+ if($control_area == null) {
+ $control_area = new
activitycalendar_activity((int) $activity_id);
+
+
$control_area->set_title($this->unmarshal($this->db->f('title'), 'string'));
+
$control_area->set_organization_id($this->unmarshal($this->db->f('organization_id'),
'int'));
+
$control_area->set_type_id($this->unmarshal($this->db->f('type_id'), 'int'));
+
$control_area->set_district($this->unmarshal($this->db->f('district'), 'int'));
+
$control_area->set_office($this->unmarshal($this->db->f('office'), 'int'));
+
$control_area->set_category($this->unmarshal($this->db->f('category'), 'int'));
+
$control_area->set_state($this->unmarshal($this->db->f('state'), 'int'));
+
$control_area->set_target($this->unmarshal($this->db->f('target'), 'string'));
+
$control_area->set_description($this->unmarshal($this->db->f('description'),
'string'));
+
$control_area->set_arena($this->unmarshal($this->db->f('arena'), 'string'));
+
$control_area->set_internal_arena($this->unmarshal($this->db->f('internal_arena'),
'string'));
+
$control_area->set_time($this->unmarshal($this->db->f('time'), 'string'));
+
$control_area->set_last_change_date($this->unmarshal($this->db->f('last_change_date'),
'int'));
+
$control_area->set_special_adaptation($this->unmarshal($this->db->f('special_adaptation',
'bool')));
+
$control_area->set_secret($this->unmarshal($this->db->f('secret'), 'string'));
+
+
+ }
+ */
+ return $control_area;
+ }
+
+ }
Modified: trunk/controller/inc/class.socontrol_group.inc.php
===================================================================
--- trunk/controller/inc/class.socontrol_group.inc.php 2011-12-11 11:30:28 UTC
(rev 8266)
+++ trunk/controller/inc/class.socontrol_group.inc.php 2011-12-11 12:27:18 UTC
(rev 8267)
@@ -1,316 +1,345 @@
-<?php
-phpgw::import_class('controller.socommon');
-
-include_class('controller', 'control_group', 'inc/model/');
-
-class controller_socontrol_group extends controller_socommon
-{
- protected static $so;
-
- /**
- * Get a static reference to the storage object associated with this
model object
- *
- * @return controller_socontrol_group the storage object
- */
- public static function get_instance()
- {
- if (self::$so == null) {
- self::$so = CreateObject('controller.socontrol_group');
- }
- return self::$so;
- }
-
- /**
- * Function for adding a new control group to the database.
- *
- * @param controller_control_group $control_group the control group to
be added
- * @return int id of the new control group object
- */
- function add(&$control_group)
- {
- $cols = array(
- 'group_name',
- 'procedure_id',
- 'control_area_id',
- 'building_part_id'
- );
-
- $values = array(
- $this->marshal($control_group->get_group_name(),
'string'),
- $this->marshal($control_group->get_procedure_id(),
'int'),
- $this->marshal($control_group->get_control_area_id(),
'int'),
- $this->marshal($control_group->get_building_part_id(),
'int'),
- );
-
- $result = $this->db->query('INSERT INTO
controller_control_group (' . join(',', $cols) . ') VALUES (' . join(',',
$values) . ')', __LINE__,__FILE__);
-
- if(isset($result))
- {
- // Get the new control group ID and return it
- return
$this->db->get_last_insert_id('controller_control_group', 'id');
- }
- else
- {
- return 0;
- }
-
- }
-
- /**
- * Update the database values for an existing activity object.
- *
- * @param $activity the activity to be updated
- * @return boolean true if successful, false otherwise
- */
-
- function update($control_group)
- {
- $id = intval($control_group->get_id());
-
- $values = array(
- 'group_name = ' .
$this->marshal($control_group->get_group_name(), 'string'),
- 'procedure_id = '.
$this->marshal($control_group->get_procedure_id(), 'int'),
- 'control_area_id = ' .
$this->marshal($control_group->get_control_area_id(), 'int'),
- 'building_part_id = ' .
$this->marshal($control_group->get_building_part_id(), 'int')
- );
-
- //var_dump('UPDATE activity_activity SET ' . join(',', $values)
. " WHERE id=$id");
- $result = $this->db->query('UPDATE controller_control_group SET
' . join(',', $values) . " WHERE id=$id", __LINE__,__FILE__);
-
- return isset($result);
- }
-
- /**
- * Get single procedure
- *
- * @param $id id of the procedure to return
- * @return a controller_procedure
- */
- function get_single($id)
- {
- $id = (int)$id;
-
- $joins = " {$this->left_join} fm_building_part ON
(p.building_part_id = CAST(fm_building_part.id AS INT))";
- $joins .= " {$this->left_join} controller_procedure ON
(p.procedure_id = controller_procedure.id)";
- $joins .= " {$this->left_join} controller_control_area ON
(p.control_area_id = controller_control_area.id)";
-
- $sql = "SELECT p.*, fm_building_part.descr AS
building_part_descr, controller_procedure.title as procedure_title,
controller_control_area.title as control_area_name FROM
controller_control_group p {$joins} WHERE p.id = " . $id;
- $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
- $this->db->next_record();
-
- $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
-
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
-
$control_group->set_procedure_id($this->unmarshal($this->db->f('procedure_id'),
'int'));
-
$control_group->set_procedure_name($this->unmarshal($this->db->f('procedure_title'),
'string'));
-
$control_group->set_control_area_id($this->unmarshal($this->db->f('control_area_id'),
'int'));
-
$control_group->set_control_area_name($this->unmarshal($this->db->f('control_area_name'),
'string'));
-
$control_group->set_building_part_id($this->unmarshal($this->db->f('building_part_id'),
'int'));
-
$control_group->set_building_part_descr($this->unmarshal($this->db->f('building_part_descr'),
'string'));
-
- return $control_group;
- }
-
- /**
- * Get a list of procedure objects matching the specific filters
- *
- * @param $start search result offset
- * @param $results number of results to return
- * @param $sort field to sort by
- * @param $query LIKE-based query string
- * @param $filters array of custom filters
- * @return list of rental_composite objects
- */
- function get_control_group_array($start = 0, $results = 1000, $sort =
null, $dir = '', $query = null, $search_option = null, $filters = array())
- {
- $results = array();
-
- //$condition = $this->get_conditions($query,
$filters,$search_option);
- $order = $sort ? "ORDER BY $sort $dir ": '';
-
- //$sql = "SELECT * FROM controller_procedure WHERE $condition
$order";
- $sql = "SELECT * FROM controller_control_group $order";
- $this->db->limit_query($sql, $start, __LINE__, __FILE__,
$limit);
-
- while ($this->db->next_record())
- {
- $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
-
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
-
- $results[] = $control_group;
- }
-
- return $results;
- }
-
- function get_control_group_select_array()
- {
- $results = array();
- $results[] = array('id' => 0,'name' => lang('Not
selected'));
- $this->db->query("SELECT id, group_name as name FROM
controller_control_group ORDER BY name ASC", __LINE__, __FILE__);
- while ($this->db->next_record())
- {
- $results[] = array('id' => $this->db->f('id',
false),
- 'name' =>
$this->db->f('name', false));
- }
- return $results;
- }
-
- function get_building_part_select_array($selected_building_part_id)
- {
- $results = array();
- $results[] = array('id' => 0,'name' => lang('Not
selected'));
- $this->db->query("SELECT id, descr as name FROM
fm_building_part ORDER BY id ASC", __LINE__, __FILE__);
- while ($this->db->next_record())
- {
- $curr_id = $this->db->f('id', false);
- if($selected_building_part_id &&
$selected_building_part_id > 0 && $selected_building_part_id == $curr_id)
- {
- $results[] = array('id' =>
$this->db->f('id', false),
-
'name' => $this->db->f('name', false),
-
'selected' => 'yes');
- }
- else
- {
- $results[] = array('id' =>
$this->db->f('id', false),
-
'name' => $this->db->f('name', false));
- }
- }
- return $results;
- }
-
- function get_control_groups_as_objects($control_area_id, $limit)
- {
- $results = array();
-
- $sql = "SELECT * FROM controller_control_group WHERE
control_area_id=$control_area_id";
- $this->db->limit_query($sql, $start, __LINE__, __FILE__,
$limit);
-
- while ($this->db->next_record()) {
- $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
-
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
-
$control_group->set_procedure_id($this->unmarshal($this->db->f('procedure_id',
true), 'string'));
-
$control_group->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'string'));
-
- $results[] = $control_group;
- }
-
- return $results;
- }
-
- function get_control_groups_as_array($control_area_id)
- {
- $results = array();
-
- $sql = "SELECT * FROM controller_control_group WHERE
control_area_id=$control_area_id";
- $this->db->query($sql);
-
- while ($this->db->next_record()) {
- $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
-
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
-
$control_group->set_procedure_id($this->unmarshal($this->db->f('procedure_id',
true), 'string'));
-
$control_group->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'string'));
-
- $results[] = $control_group->toArray();
- }
-
- return $results;
- }
-
- function get_id_field_name($extended_info = false)
- {
-
- if(!$extended_info)
- {
- $ret = 'id';
- }
- else
- {
- $ret = array
- (
- 'table' =>
'controller_control_group', // alias
- 'field' => 'id',
- 'translated' => 'id'
- );
- }
-
- return $ret;
- }
-
- protected function get_query(string $sort_field, boolean $ascending,
string $search_for, string $search_type, array $filters, boolean $return_count)
- {
- $clauses = array('1=1');
- if($search_for)
- {
- $like_pattern = "'%" .
$this->db->db_addslashes($search_for) . "%'";
- $like_clauses = array();
- switch($search_type){
- default:
- $like_clauses[] =
"controller_control_group.group_name $this->like $like_pattern";
- break;
- }
- if(count($like_clauses))
- {
- $clauses[] = '(' . join(' OR ', $like_clauses)
. ')';
- }
- }
-
- $filter_clauses = array();
-
- if(isset($filters[$this->get_id_field_name()]))
- {
- $filter_clauses[] = "controller_control_group.id =
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
- }
- if(isset($filters['control_areas']))
- {
- $filter_clauses[] =
"controller_control_group.control_area_id =
{$this->marshal($filters['control_areas'],'int')}";
- }
-
- if(count($filter_clauses))
- {
- $clauses[] = join(' AND ', $filter_clauses);
- }
-
- $condition = join(' AND ', $clauses);
-
- $tables = "controller_control_group";
- $joins = " {$this->left_join} fm_building_part ON
(building_part_id = CAST(fm_building_part.id AS INT))";
- $joins .= " {$this->left_join} controller_procedure ON
(controller_control_group.procedure_id = controller_procedure.id)";
- $joins .= " {$this->left_join} controller_control_area ON
(controller_control_group.control_area_id = controller_control_area.id)";
- //$joins .= " {$this->left_join} rental_contract_composite ON
(rental_contract_composite.composite_id = rental_composite.id)";
- //$joins .= " {$this->left_join} rental_contract ON
(rental_contract.id = rental_contract_composite.contract_id)";
-
- if($return_count) // We should only return a count
- {
- $cols = 'COUNT(DISTINCT(controller_control_group.id))
AS count';
- }
- else
- {
- $cols .= "controller_control_group.id, group_name,
controller_control_group.procedure_id, controller_control_group.control_area_id
as control_area_id, ";
- $cols .= "building_part_id, fm_building_part.descr AS
building_part_descr, controller_procedure.title as procedure_title, ";
- $cols .= "controller_control_area.title as
control_area_name ";
- }
- $dir = $ascending ? 'ASC' : 'DESC';
- $order = $sort_field ? "ORDER BY {$this->marshal($sort_field,
'field')} $dir ": '';
-
- //var_dump("SELECT {$cols} FROM {$tables} {$joins} WHERE
{$condition} {$order}");
-
- return "SELECT {$cols} FROM {$tables} {$joins} WHERE
{$condition} {$order}";
- }
-
- function populate(int $control_group_id, &$control_group)
- {
- if($control_group == null) {
- $control_group = new controller_control_group((int)
$control_group_id);
-
-
$control_group->set_group_name($this->unmarshal($this->db->f('group_name'),
'string'));
-
$control_group->set_procedure_id($this->unmarshal($this->db->f('procedure_id'),
'int'));
-
$control_group->set_procedure_name($this->unmarshal($this->db->f('procedure_title'),
'string'));
-
$control_group->set_control_area_id($this->unmarshal($this->db->f('control_area_id'),
'int'));
-
$control_group->set_control_area_name($this->unmarshal($this->db->f('control_area_name'),
'string'));
-
$control_group->set_building_part_id($this->unmarshal($this->db->f('building_part_id'),
'int'));
-
$control_group->set_building_part_descr($this->unmarshal($this->db->f('building_part_descr'),
'string'));
- }
- //var_dump($control_group);
- return $control_group;
- }
-}
+<?php
+ /**
+ * phpGroupWare - controller: a part of a Facilities Management System.
+ *
+ * @author Erink Holm-Larsen <address@hidden>
+ * @author Torstein Vadla <address@hidden>
+ * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc.
http://www.fsf.org/
+ * This file is part of phpGroupWare.
+ *
+ * phpGroupWare is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * phpGroupWare is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with phpGroupWare; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
+ *
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License
+ * @internal Development of this application was funded by
http://www.bergen.kommune.no/
+ * @package property
+ * @subpackage controller
+ * @version $Id$
+ */
+
+ phpgw::import_class('controller.socommon');
+
+ include_class('controller', 'control_group', 'inc/model/');
+
+ class controller_socontrol_group extends controller_socommon
+ {
+ protected static $so;
+
+ /**
+ * Get a static reference to the storage object associated with
this model object
+ *
+ * @return controller_socontrol_group the storage object
+ */
+ public static function get_instance()
+ {
+ if (self::$so == null) {
+ self::$so =
CreateObject('controller.socontrol_group');
+ }
+ return self::$so;
+ }
+
+ /**
+ * Function for adding a new control group to the database.
+ *
+ * @param controller_control_group $control_group the control
group to be added
+ * @return int id of the new control group object
+ */
+ function add(&$control_group)
+ {
+ $cols = array(
+ 'group_name',
+ 'procedure_id',
+ 'control_area_id',
+ 'building_part_id'
+ );
+
+ $values = array(
+
$this->marshal($control_group->get_group_name(), 'string'),
+
$this->marshal($control_group->get_procedure_id(), 'int'),
+
$this->marshal($control_group->get_control_area_id(), 'int'),
+
$this->marshal($control_group->get_building_part_id(), 'int'),
+ );
+
+ $result = $this->db->query('INSERT INTO
controller_control_group (' . join(',', $cols) . ') VALUES (' . join(',',
$values) . ')', __LINE__,__FILE__);
+
+ if(isset($result))
+ {
+ // Get the new control group ID and return it
+ return
$this->db->get_last_insert_id('controller_control_group', 'id');
+ }
+ else
+ {
+ return 0;
+ }
+
+ }
+
+ /**
+ * Update the database values for an existing activity object.
+ *
+ * @param $activity the activity to be updated
+ * @return boolean true if successful, false otherwise
+ */
+
+ function update($control_group)
+ {
+ $id = intval($control_group->get_id());
+
+ $values = array(
+ 'group_name = ' .
$this->marshal($control_group->get_group_name(), 'string'),
+ 'procedure_id = '.
$this->marshal($control_group->get_procedure_id(), 'int'),
+ 'control_area_id = ' .
$this->marshal($control_group->get_control_area_id(), 'int'),
+ 'building_part_id = ' .
$this->marshal($control_group->get_building_part_id(), 'int')
+ );
+
+ //var_dump('UPDATE activity_activity SET ' . join(',',
$values) . " WHERE id=$id");
+ $result = $this->db->query('UPDATE
controller_control_group SET ' . join(',', $values) . " WHERE id=$id",
__LINE__,__FILE__);
+
+ return isset($result);
+ }
+
+ /**
+ * Get single procedure
+ *
+ * @param $id id of the procedure to return
+ * @return a controller_procedure
+ */
+ function get_single($id)
+ {
+ $id = (int)$id;
+
+ $joins = " {$this->left_join} fm_building_part ON
(p.building_part_id = CAST(fm_building_part.id AS INT))";
+ $joins .= " {$this->left_join} controller_procedure
ON (p.procedure_id = controller_procedure.id)";
+ $joins .= " {$this->left_join}
controller_control_area ON (p.control_area_id = controller_control_area.id)";
+
+ $sql = "SELECT p.*, fm_building_part.descr AS
building_part_descr, controller_procedure.title as procedure_title,
controller_control_area.title as control_area_name FROM
controller_control_group p {$joins} WHERE p.id = " . $id;
+ $this->db->limit_query($sql, 0, __LINE__, __FILE__, 1);
+ $this->db->next_record();
+
+ $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
+
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
+
$control_group->set_procedure_id($this->unmarshal($this->db->f('procedure_id'),
'int'));
+
$control_group->set_procedure_name($this->unmarshal($this->db->f('procedure_title'),
'string'));
+
$control_group->set_control_area_id($this->unmarshal($this->db->f('control_area_id'),
'int'));
+
$control_group->set_control_area_name($this->unmarshal($this->db->f('control_area_name'),
'string'));
+
$control_group->set_building_part_id($this->unmarshal($this->db->f('building_part_id'),
'int'));
+
$control_group->set_building_part_descr($this->unmarshal($this->db->f('building_part_descr'),
'string'));
+
+ return $control_group;
+ }
+
+ /**
+ * Get a list of procedure objects matching the specific filters
+ *
+ * @param $start search result offset
+ * @param $results number of results to return
+ * @param $sort field to sort by
+ * @param $query LIKE-based query string
+ * @param $filters array of custom filters
+ * @return list of rental_composite objects
+ */
+ function get_control_group_array($start = 0, $results = 1000,
$sort = null, $dir = '', $query = null, $search_option = null, $filters =
array())
+ {
+ $results = array();
+
+ //$condition = $this->get_conditions($query,
$filters,$search_option);
+ $order = $sort ? "ORDER BY $sort $dir ": '';
+
+ //$sql = "SELECT * FROM controller_procedure WHERE
$condition $order";
+ $sql = "SELECT * FROM controller_control_group $order";
+ $this->db->limit_query($sql, $start, __LINE__,
__FILE__, $limit);
+
+ while ($this->db->next_record())
+ {
+ $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
+
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
+
+ $results[] = $control_group;
+ }
+
+ return $results;
+ }
+
+ function get_control_group_select_array()
+ {
+ $results = array();
+ $results[] = array('id' => 0,'name' =>
lang('Not selected'));
+ $this->db->query("SELECT id, group_name as name
FROM controller_control_group ORDER BY name ASC", __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $results[] = array('id' =>
$this->db->f('id', false),
+
'name' => $this->db->f('name', false));
+ }
+ return $results;
+ }
+
+ function
get_building_part_select_array($selected_building_part_id)
+ {
+ $results = array();
+ $results[] = array('id' => 0,'name' =>
lang('Not selected'));
+ $this->db->query("SELECT id, descr as name FROM
fm_building_part ORDER BY id ASC", __LINE__, __FILE__);
+ while ($this->db->next_record())
+ {
+ $curr_id = $this->db->f('id', false);
+ if($selected_building_part_id &&
$selected_building_part_id > 0 && $selected_building_part_id == $curr_id)
+ {
+ $results[] = array('id' =>
$this->db->f('id', false),
+
'name' => $this->db->f('name', false),
+
'selected' => 'yes');
+ }
+ else
+ {
+ $results[] = array('id' =>
$this->db->f('id', false),
+
'name' => $this->db->f('name', false));
+ }
+ }
+ return $results;
+ }
+
+ function get_control_groups_as_objects($control_area_id, $limit)
+ {
+ $results = array();
+
+ $sql = "SELECT * FROM controller_control_group WHERE
control_area_id=$control_area_id";
+ $this->db->limit_query($sql, $start, __LINE__,
__FILE__, $limit);
+
+ while ($this->db->next_record()) {
+ $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
+
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
+
$control_group->set_procedure_id($this->unmarshal($this->db->f('procedure_id',
true), 'string'));
+
$control_group->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'string'));
+
+ $results[] = $control_group;
+ }
+
+ return $results;
+ }
+
+ function get_control_groups_as_array($control_area_id)
+ {
+ $results = array();
+
+ $sql = "SELECT * FROM controller_control_group WHERE
control_area_id=$control_area_id";
+ $this->db->query($sql);
+
+ while ($this->db->next_record()) {
+ $control_group = new
controller_control_group($this->unmarshal($this->db->f('id', true), 'int'));
+
$control_group->set_group_name($this->unmarshal($this->db->f('group_name',
true), 'string'));
+
$control_group->set_procedure_id($this->unmarshal($this->db->f('procedure_id',
true), 'string'));
+
$control_group->set_control_area_id($this->unmarshal($this->db->f('control_area_id',
true), 'string'));
+
+ $results[] = $control_group->toArray();
+ }
+
+ return $results;
+ }
+
+ function get_id_field_name($extended_info = false)
+ {
+
+ if(!$extended_info)
+ {
+ $ret = 'id';
+ }
+ else
+ {
+ $ret = array
+ (
+ 'table' =>
'controller_control_group', // alias
+ 'field' => 'id',
+ 'translated' => 'id'
+ );
+ }
+
+ return $ret;
+ }
+
+ protected function get_query(string $sort_field, boolean
$ascending, string $search_for, string $search_type, array $filters, boolean
$return_count)
+ {
+ $clauses = array('1=1');
+ if($search_for)
+ {
+ $like_pattern = "'%" .
$this->db->db_addslashes($search_for) . "%'";
+ $like_clauses = array();
+ switch($search_type){
+ default:
+ $like_clauses[] =
"controller_control_group.group_name $this->like $like_pattern";
+ break;
+ }
+ if(count($like_clauses))
+ {
+ $clauses[] = '(' . join(' OR ',
$like_clauses) . ')';
+ }
+ }
+
+ $filter_clauses = array();
+
+ if(isset($filters[$this->get_id_field_name()]))
+ {
+ $filter_clauses[] =
"controller_control_group.id =
{$this->marshal($filters[$this->get_id_field_name()],'int')}";
+ }
+ if(isset($filters['control_areas']))
+ {
+ $filter_clauses[] =
"controller_control_group.control_area_id =
{$this->marshal($filters['control_areas'],'int')}";
+ }
+
+ if(count($filter_clauses))
+ {
+ $clauses[] = join(' AND ', $filter_clauses);
+ }
+
+ $condition = join(' AND ', $clauses);
+
+ $tables = "controller_control_group";
+ $joins = " {$this->left_join} fm_building_part ON
(building_part_id = CAST(fm_building_part.id AS INT))";
@@ Diff output truncated at 153600 characters. @@
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [8267] controller: License informtation, ID-tag - and formatting,
Sigurd Nes <=