[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [11100] controller: refacturing
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [11100] controller: refacturing |
Date: |
Fri, 10 May 2013 07:53:37 +0000 |
Revision: 11100
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11100
Author: sigurdne
Date: 2013-05-10 07:53:37 +0000 (Fri, 10 May 2013)
Log Message:
-----------
controller: refacturing
Modified Paths:
--------------
trunk/controller/inc/class.hook_helper.inc.php
trunk/controller/inc/class.socase.inc.php
trunk/controller/inc/class.socheck_list.inc.php
trunk/controller/inc/class.uicase.inc.php
trunk/controller/inc/class.uicheck_list.inc.php
trunk/controller/inc/model/class.check_item_case.inc.php
Removed Paths:
-------------
trunk/controller/inc/helper/class.check_list_status_updater.inc.php
Modified: trunk/controller/inc/class.hook_helper.inc.php
===================================================================
--- trunk/controller/inc/class.hook_helper.inc.php 2013-05-10 07:24:54 UTC
(rev 11099)
+++ trunk/controller/inc/class.hook_helper.inc.php 2013-05-10 07:53:37 UTC
(rev 11100)
@@ -55,14 +55,14 @@
*/
public function home_mobilefrontend()
{
- $this->home('mobilefrontend');
+ $this->home();
}
/**
* Show info for homepage
*
* @return void
*/
- public function home($url_correction = '')
+ public function home()
{
$location_array = array();
$component_short_desc = array();
@@ -265,7 +265,7 @@
echo "\n".'<!-- BEGIN checklist info -->'."\n <h2
class='heading'>Mine planlagte kontroller</h2><div class='home-box'>" .
$my_planned_controls_HTML . "</div></div>\n".'<!-- END checklist info -->'."\n";
- // if($url_correction != 'mobilefrontend')
+
{
/* ======================================= UNDONE
ASSIGNED CONTROLS FOR CURRENT USER ================================= */
@@ -678,42 +678,42 @@
foreach($my_locations as $location)
{
- $controls = array();
- $components_with_controls_array = array();
- $location_code = $location["location_code"];
+ $controls = array();
+ $components_with_controls_array = array();
+ $location_code = $location["location_code"];
- $controls_at_location =
$so_control->get_controls_by_location( $location_code, $from_date_ts,
$to_date_ts, $repeat_type, "return_array", $location["role_id"] );
+ $controls_at_location =
$so_control->get_controls_by_location( $location_code, $from_date_ts,
$to_date_ts, $repeat_type, "return_array", $location["role_id"] );
- $level = count(explode('-', $location_code));
+ $level = count(explode('-', $location_code));
- if($level == 1)
- {
- // Fetches all controls for the components for
a location within time period
- $filter = "bim_item.location_code =
'$location_code' ";
- $components_with_controls_array =
$so_control->get_controls_by_component($from_date_ts, $to_date_ts,
$repeat_type, "return_array", $location["role_id"], $filter);
- }
- else
- {
- // Fetches all controls for the components for
a location within time period
- $filter = "bim_item.location_code LIKE
'$location_code%' ";
- $components_with_controls_array =
$so_control->get_controls_by_component($from_date_ts, $to_date_ts,
$repeat_type, "return_array", $location["role_id"], $filter);
- }
+ if($level == 1)
+ {
+ // Fetches all controls for the
components for a location within time period
+ $filter = "bim_item.location_code =
'$location_code' ";
+ $components_with_controls_array =
$so_control->get_controls_by_component($from_date_ts, $to_date_ts,
$repeat_type, "return_array", $location["role_id"], $filter);
+ }
+ else
+ {
+ // Fetches all controls for the
components for a location within time period
+ $filter = "bim_item.location_code LIKE
'$location_code%' ";
+ $components_with_controls_array =
$so_control->get_controls_by_component($from_date_ts, $to_date_ts,
$repeat_type, "return_array", $location["role_id"], $filter);
+ }
- if( count($controls_at_location) > 0 )
- {
- // Saves location code, location type and an
array containing controls at locations
- $my_controls[] = array( $location_code,
'location', $controls_at_location );
- }
+ if( count($controls_at_location) > 0 )
+ {
+ // Saves location code, location type
and an array containing controls at locations
+ $my_controls[] = array( $location_code,
'location', $controls_at_location );
+ }
- if( count($components_with_controls_array) > 0 )
- {
- foreach($components_with_controls_array as
$component)
+ if( count($components_with_controls_array) > 0 )
{
- // Saves location code, location type, an array
containing controls at locations and component object
- $my_controls[] = array( $location_code,
'component', $component['controls_array'], $component );
+ foreach($components_with_controls_array
as $component)
+ {
+ // Saves location code, location type,
an array containing controls at locations and component object
+ $my_controls[] = array( $location_code,
'component', $component['controls_array'], $component );
+ }
}
}
- }
return $my_controls;
}
Modified: trunk/controller/inc/class.socase.inc.php
===================================================================
--- trunk/controller/inc/class.socase.inc.php 2013-05-10 07:24:54 UTC (rev
11099)
+++ trunk/controller/inc/class.socase.inc.php 2013-05-10 07:53:37 UTC (rev
11100)
@@ -83,7 +83,7 @@
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'),
'int'));
$case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
$case->set_measurement($this->unmarshal($this->db->f('measurement'), 'string'));
-
$case->set_location_code($this->unmarshal($this->db->f('location_code'),
'string'));
+
$case->set_location_code($this->unmarshal($this->db->f('location_code'),
'string'));
return $case;
}
@@ -123,7 +123,7 @@
$case->set_modified_date($this->unmarshal($this->db->f('modified_date'),
'int'));
$case->set_modified_by($this->unmarshal($this->db->f('modified_by'), 'int'));
$case->set_measurement($this->unmarshal($this->db->f('measurement'), 'string'));
-
$case->set_location_code($this->unmarshal($this->db->f('location_code'),
'string'));
+
$case->set_location_code($this->unmarshal($this->db->f('location_code'),
'string'));
$cases_array[] = $case;
}
@@ -139,6 +139,8 @@
*/
function add(&$case)
{
+ $this->db->transaction_begin();
+
$cols = array(
'check_item_id',
'status',
@@ -150,7 +152,7 @@
'modified_date',
'modified_by',
'measurement',
- 'location_code'
+ 'location_code'
);
$values = array(
@@ -164,15 +166,78 @@
$this->marshal($case->get_modified_date(),
'int'),
$this->marshal($case->get_modified_by(), 'int'),
$this->marshal($case->get_measurement(),
'string'),
- $this->marshal($case->get_location_code(), 'string')
+ $this->marshal($case->get_location_code(),
'string')
);
- $sql = 'INSERT INTO controller_check_item_case (' . join(',', $cols) .
') VALUES (' . join(',', $values) . ')';
- $result = $this->db->query( $sql, __LINE__,__FILE__);
+ $sql = 'INSERT INTO controller_check_item_case (' .
join(',', $cols) . ') VALUES (' . join(',', $values) . ')';
+ $this->db->query( $sql, __LINE__,__FILE__);
+ $case_id =
$this->db->get_last_insert_id('controller_check_item_case', 'id');
+
+//--------
- return $result ?
$this->db->get_last_insert_id('controller_check_item_case', 'id') : 0;
+
$this->update_cases_on_check_list($case->get_check_item_id());
+
+
+//------
+
+ if($this->db->transaction_commit())
+ {
+ return $case_id;
+ }
+ else
+ {
+ return 0;
+ }
}
+
+ function update_cases_on_check_list($check_item_id = 0)
+ {
+ $check_item_id = (int) $check_item_id;
+ $sql = "SELECT check_list_id FROM
controller_check_item WHERE id = {$check_item_id}";
+
+ $this->db->query($sql, __LINE__,__FILE__);
+ $this->db->next_record();
+ $check_list_id = (int) $this->db->f('check_list_id');
+
+ $so_check_item =
CreateObject('controller.socheck_item');
+ $check_items =
$so_check_item->get_check_items_with_cases($check_list_id, $control_item_type =
null, $status = null, $messageStatus = null);
+
+ $num_open_cases = 0;
+ $num_pending_cases = 0;
+
+ foreach($check_items as $check_item)
+ {
+ foreach($check_item->get_cases_array() as $case)
+ {
+
+ if($case->get_status() ==
controller_check_item_case::STATUS_OPEN)
+ {
+ $num_open_cases++;
+ }
+
+ if($case->get_status() ==
controller_check_item_case::STATUS_PENDING)
+ {
+ $num_pending_cases++;
+ }
+ }
+ }
+
+ $values = array
+ (
+ 'num_open_cases' => $num_open_cases,
+ 'num_pending_cases' => $num_pending_cases,
+ );
+
+ if($num_open_cases > 0)
+ {
+ $values['status'] =
controller_check_list::STATUS_DONE;
+ }
+
+ $value_set = $this->db->validate_update($values);
+ $this->db->query("UPDATE controller_check_list SET
{$value_set} WHERE id = '{$check_list_id}'",__LINE__,__FILE__);
+ }
+
/**
* Updates an existing case object in database
*
@@ -181,6 +246,8 @@
*/
function update($case)
{
+ $this->db->transaction_begin();
+
$id = (int) $case->get_id();
$values = array(
@@ -194,12 +261,14 @@
'modified_date = ' .
$this->marshal($case->get_modified_date(), 'int'),
'modified_by = ' .
$this->marshal($case->get_modified_by(), 'int'),
'measurement = ' .
$this->marshal($case->get_measurement(), 'string'),
- 'location_code = ' . $this->marshal($case->get_location_code(),
'string')
+ 'location_code = ' .
$this->marshal($case->get_location_code(), 'string')
);
$result = $this->db->query('UPDATE
controller_check_item_case SET ' . join(',', $values) . " WHERE id=$id",
__LINE__,__FILE__);
- if( $result )
+
$this->update_cases_on_check_list($case->get_check_item_id());
+
+ if($this->db->transaction_commit())
{
return $id;
}
Modified: trunk/controller/inc/class.socheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.socheck_list.inc.php 2013-05-10 07:24:54 UTC
(rev 11099)
+++ trunk/controller/inc/class.socheck_list.inc.php 2013-05-10 07:53:37 UTC
(rev 11100)
@@ -854,7 +854,6 @@
$sql = 'UPDATE controller_check_list SET ' . join(',', $values)
. " WHERE id = {$id}";
-_debug_array($sql);
$result = $this->db->query($sql, __LINE__,__FILE__);
if($result)
Modified: trunk/controller/inc/class.uicase.inc.php
===================================================================
--- trunk/controller/inc/class.uicase.inc.php 2013-05-10 07:24:54 UTC (rev
11099)
+++ trunk/controller/inc/class.uicase.inc.php 2013-05-10 07:53:37 UTC (rev
11100)
@@ -44,7 +44,6 @@
include_class('controller', 'check_item_case', 'inc/model/');
include_class('controller', 'component', 'inc/model/');
- include_class('controller', 'check_list_status_updater', 'inc/helper/');
include_class('controller', 'location_finder', 'inc/helper/');
class controller_uicase extends phpgwapi_uicommon
@@ -256,9 +255,6 @@
if($case_id > 0)
{
- $cl_status_updater = new
check_list_status_updater();
- $cl_status_updater->update_check_list_status(
$check_list_id );
-
return json_encode( array( "status" => "saved"
) );
}
else
@@ -295,9 +291,6 @@
if($case_id > 0)
{
- $cl_status_updater = new
check_list_status_updater();
-
$cl_status_updater->update_check_list_status( $check_list_id );
-
$check_item =
$this->so_check_item->get_single($case->get_check_item_id());
$control_item =
$this->so_control_item->get_single($check_item->get_control_item_id());
@@ -595,10 +588,6 @@
// Gets check_list from check_item
$check_item = $this->so_check_item->get_single(
$check_item_id );
$check_list_id =
$check_item->get_check_list_id();
-
- // Updates number of open cases for check list
- $cl_status_updater = new
check_list_status_updater();
- $cl_status_updater->update_check_list_status(
$check_list_id );
}
}
@@ -616,9 +605,6 @@
if($status)
{
- $cl_status_updater = new
check_list_status_updater();
- $cl_status_updater->update_check_list_status(
$check_list_id );
-
return json_encode( array( "status" =>
"deleted" ) );
}
else
@@ -642,10 +628,8 @@
$case_id = $this->so->store($case);
- if($case_id > 0){
- $cl_status_updater = new
check_list_status_updater();
- $cl_status_updater->update_check_list_status(
$check_list_id );
-
+ if($case_id > 0)
+ {
return json_encode( array( "status" => "true" )
);
}
else
@@ -671,9 +655,6 @@
if($case_id > 0)
{
- $cl_status_updater = new
check_list_status_updater();
- $cl_status_updater->update_check_list_status(
$check_list_id );
-
return json_encode( array( "status" => "true" )
);
}
else
Modified: trunk/controller/inc/class.uicheck_list.inc.php
===================================================================
--- trunk/controller/inc/class.uicheck_list.inc.php 2013-05-10 07:24:54 UTC
(rev 11099)
+++ trunk/controller/inc/class.uicheck_list.inc.php 2013-05-10 07:53:37 UTC
(rev 11100)
@@ -44,7 +44,6 @@
include_class('controller', 'check_list', 'inc/model/');
include_class('controller', 'check_item', 'inc/model/');
include_class('controller', 'date_generator', 'inc/component/');
- include_class('controller', 'check_list_status_updater', 'inc/helper/');
include_class('controller', 'date_converter', 'inc/helper/');
include_class('controller', 'location_finder', 'inc/helper/');
@@ -500,9 +499,6 @@
{
$check_list_id = $this->so->store($check_list);
-// $cl_status_updater = new
check_list_status_updater();
-//
$cl_status_updater->update_check_list_status($check_list_id);
-//die();
if($check_list_id > 0)
{
$this->redirect(array('menuaction' =>
'controller.uicheck_list.edit_check_list', 'check_list_id' => $check_list_id));
Deleted: trunk/controller/inc/helper/class.check_list_status_updater.inc.php
===================================================================
--- trunk/controller/inc/helper/class.check_list_status_updater.inc.php
2013-05-10 07:24:54 UTC (rev 11099)
+++ trunk/controller/inc/helper/class.check_list_status_updater.inc.php
2013-05-10 07:53:37 UTC (rev 11100)
@@ -1,56 +0,0 @@
-<?php
- phpgw::import_class('controller.socheck_list');
- phpgw::import_class('controller.socheck_item');
-
- include_class('controller', 'check_list', 'inc/model/');
- include_class('controller', 'check_item', 'inc/model/');
-
- class check_list_status_updater {
-
- public function __construct()
- {
- $this->so_check_list =
CreateObject('controller.socheck_list');
- $this->so_check_item =
CreateObject('controller.socheck_item');
- }
-
- public function update_check_list_status( $check_list_id )
- {
- //$db_check_list = $this->so_check_list->get_db();
- //$db_check_list->transaction_begin();
-
- $check_list = $this->so_check_list->get_single(
$check_list_id );
-
- $check_items =
$this->so_check_item->get_check_items_with_cases($check_list_id,
$control_item_type = null, $status = null, $messageStatus = null);
-
- $num_open_cases = 0;
- $num_pending_cases = 0;
-
- foreach($check_items as $check_item)
- {
- foreach($check_item->get_cases_array() as $case)
- {
-
- if($case->get_status() ==
controller_check_item_case::STATUS_OPEN)
- {
- $num_open_cases++;
- }
-
- if($case->get_status() ==
controller_check_item_case::STATUS_PENDING)
- {
- $num_pending_cases++;
- }
- }
- }
-
- if($num_open_cases > 0)
- {
-
$check_list->set_status(controller_check_list::STATUS_DONE);
- }
-
- $check_list->set_num_open_cases($num_open_cases);
- $check_list->set_num_pending_cases($num_pending_cases);
-
- $this->so_check_list->store($check_list);
-
- }
-}
\ No newline at end of file
Modified: trunk/controller/inc/model/class.check_item_case.inc.php
===================================================================
--- trunk/controller/inc/model/class.check_item_case.inc.php 2013-05-10
07:24:54 UTC (rev 11099)
+++ trunk/controller/inc/model/class.check_item_case.inc.php 2013-05-10
07:53:37 UTC (rev 11100)
@@ -49,7 +49,7 @@
protected $modified_date;
protected $modified_by;
protected $measurement;
- protected $location_code;
+ protected $location_code;
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [11100] controller: refacturing,
Sigurd Nes <=