[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [15549] rental: more on application
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [15549] rental: more on application |
Date: |
Tue, 30 Aug 2016 17:08:17 +0000 (UTC) |
Revision: 15549
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15549
Author: sigurdne
Date: 2016-08-30 17:08:17 +0000 (Tue, 30 Aug 2016)
Log Message:
-----------
rental: more on application
Modified Paths:
--------------
trunk/phpgwapi/inc/class.socommon.inc.php
trunk/rental/inc/class.uiapplication.inc.php
trunk/rental/inc/model/class.application.inc.php
trunk/rental/inc/model/class.model.inc.php
trunk/rental/templates/base/application.xsl
Added Paths:
-----------
trunk/rental/inc/class.boapplication.inc.php
Modified: trunk/phpgwapi/inc/class.socommon.inc.php
===================================================================
--- trunk/phpgwapi/inc/class.socommon.inc.php 2016-08-30 15:40:45 UTC (rev
15548)
+++ trunk/phpgwapi/inc/class.socommon.inc.php 2016-08-30 17:08:17 UTC (rev
15549)
@@ -169,23 +169,6 @@
*/
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(0, 0, '', false, '', '',
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")
@@ -196,50 +179,6 @@
}
/**
- * 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 bool 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, bool $ascending, string $search_for, string $search_type,
array $filters )
- {
- // Only allow positive start index
- if ($start_index < 0)
- {
- $start_index = 0;
- }
-
-
- $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
-
- if($num_of_objects)
- {
- $this->db->limit_query($sql, $start_index,
__LINE__, __FILE__, (int)$num_of_objects);
- }
- else
- {
- $this->db->query($sql,__LINE__,__FILE__);
- }
-
- $results = array();
-
- while ($this->db->next_record())
- {
- $results[] =
$this->populate((int)$this->db->f('id'));
- }
-
- return $results;
- }
- /**
* Return all entries matching $params. Valid parameters:
*
* - $params['start']: Search result offset
@@ -377,6 +316,7 @@
'dir' => $dir
);
}
+
protected function primary_key_conditions( $id_params )
{
if (is_array($id_params))
@@ -482,62 +422,7 @@
}
}
- /**
- * 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 bool 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 bool telling to return only the count
of the
- * matching objects, or the objects themself.
- * @return string with SQL.
- */
- protected function get_query( string $sort_field, bool
$ascending, string $search_for, string $search_type, array $filters, bool
$return_count )
- {
- //Add columns to this array to include them in the query
- $columns = array();
-
- if ($sort_field != null)
- {
- $dir = $ascending ? 'ASC' : 'DESC';
- if ($sort_field == 'name')
- {
- $order = "ORDER BY
{$this->table_name}.last_name {$dir}, {$this->table_name}.first_name {$dir}";
- $this->sort_field =
array("{$this->table_name}.last_name", "{$this->table_name}.first_name");
- }
- else
- {
- if ($sort_field == 'address')
- {
- $sort_field =
"{$this->table_name}.address1";
- $this->sort_field =
array("{$this->table_name}.address1");
- }
- $order = "ORDER BY
{$this->marshal($sort_field, 'field')} $dir";
- }
- }
-
- $condition = $this->_get_conditions( $search_for,
$filters );
- if ($return_count) // We should only return a count
- {
- $cols =
"COUNT(DISTINCT({$this->table_name}.id)) AS count";
- }
- else
- {
- $columns[] = "{$this->table_name}.*";
- $cols = implode(',', $columns);
- }
-
- $joins = '';
-
- return $sql = "SELECT {$cols} FROM {$this->table_name}
{$joins} WHERE {$condition} {$order}";
- }
-
function _get_conditions( $query, $filters )
{
$clauses = array('1=1');
@@ -655,18 +540,6 @@
return array($cols, $joins);
}
- /**
- * 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('',
false, $search_for, $search_type, $filters, true));
- }
/**
* Implementing classes must return the name of the field used
in the query
@@ -833,21 +706,15 @@
*/
public function store( &$object )
{
- if ($object->validates())
+ if ($object->get_id() > 0)
{
- 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);
- }
+ // We can assume this composite came from the
database since it has an ID. Update the existing row
+ return $this->update($object);
}
-
- // The object did not validate
- return false;
+ else
+ {
+ // This object does not have an ID, so will be
saved as a new DB row
+ return $this->add($object);
+ }
}
}
Added: trunk/rental/inc/class.boapplication.inc.php
===================================================================
--- trunk/rental/inc/class.boapplication.inc.php
(rev 0)
+++ trunk/rental/inc/class.boapplication.inc.php 2016-08-30 17:08:17 UTC
(rev 15549)
@@ -0,0 +1,126 @@
+<?php
+ /**
+ * phpGroupWare
+ *
+ * @author Sigurd Nes <address@hidden>
+ * @copyright Copyright (C) 2016 Free Software Foundation
http://www.fsf.org/
+ * @license http://www.gnu.org/licenses/gpl.html GNU General Public
License v2 or later
+ * @internal
+ * @package rental
+ * @subpackage application
+ * @version $Id:$
+ */
+
+ /*
+ This program 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.
+
+ This program 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+ phpgw::import_class('rental.soapplication');
+
+ include_class('rental', 'application', 'inc/model/');
+
+ class rental_boapplication
+ {
+ protected static
+ $bo,
+ $fields;
+
+
+ public function __construct()
+ {
+ $this->fields = rental_application::get_fields();
+ }
+
+ /**
+ * Implementing classes must return an instance of itself.
+ *
+ * @return the class instance.
+ */
+ public static function get_instance()
+ {
+ if (self::$bo == null)
+ {
+ self::$bo = new rental_boapplication();
+ }
+ return self::$bo;
+ }
+
+ public function store($object)
+ {
+ return
rental_soapplication::get_instance()->store($object);
+ }
+
+ public function read($params)
+ {
+ return
rental_soapplication::get_instance()->read($params);
+ }
+
+ public function read_single($id, $return_object = true)
+ {
+ if ($id)
+ {
+ $application =
rental_soapplication::get_instance()->read_single($id, $return_object);
+ }
+ else
+ {
+ $application = new rental_application();
+ }
+
+ return $application;
+ }
+
+ public function build_default_read_params()
+ {
+ $fields = $this->fields;
+
+ $search = phpgw::get_var('search');
+ $order = phpgw::get_var('order');
+ $draw = phpgw::get_var('draw', 'int');
+ $columns = phpgw::get_var('columns');
+
+ $params = array(
+ 'start' => phpgw::get_var('start', 'int',
'REQUEST', 0),
+ 'results' => phpgw::get_var('length', 'int',
'REQUEST', 0),
+ 'query' => $search['value'],
+ 'sort' => $columns[$order[0]['column']]['data'],
+ 'dir' => $order[0]['dir'],
+ 'allrows' => phpgw::get_var('length', 'int') ==
-1,
+ );
+
+ foreach ($fields as $field => $_params)
+ {
+ if (!empty($_REQUEST["filter_$field"]))
+ {
+ $params['filters'][$field] =
phpgw::get_var("filter_$field", $_params['type']);
+ }
+ }
+
+ return $params;
+ }
+
+ public function populate($application)
+ {
+ $fields = $this->fields;
+
+ foreach ($fields as $field => $field_info)
+ {
+ if(($field_info['action'] & PHPGW_ACL_ADD) ||
($field_info['action'] & PHPGW_ACL_EDIT))
+ {
+ $application->set_field( $field,
phpgw::get_var($field, $field_info['type'] ) );
+ }
+ }
+ return $application;
+ }
+
+ }
\ No newline at end of file
Modified: trunk/rental/inc/class.uiapplication.inc.php
===================================================================
--- trunk/rental/inc/class.uiapplication.inc.php 2016-08-30 15:40:45 UTC
(rev 15548)
+++ trunk/rental/inc/class.uiapplication.inc.php 2016-08-30 17:08:17 UTC
(rev 15549)
@@ -34,8 +34,7 @@
class rental_uiapplication extends rental_uicommon
{
- public $public_functions = array
- (
+ public $public_functions = array(
'add' => true,
'index' => true,
'query' => true,
@@ -54,6 +53,7 @@
parent::__construct();
self::set_active_menu('rental::application');
$GLOBALS['phpgw_info']['flags']['app_header'] .= '::' .
lang('application');
+ $this->bo = createObject('rental.boapplication');
$this->acl = & $GLOBALS['phpgw']->acl;
$this->acl_location = '.application';
$this->acl_read =
$this->acl->check($this->acl_location, PHPGW_ACL_READ, 'rental');
@@ -244,20 +244,8 @@
}
else
{
- $application_id = phpgw::get_var('id', 'int');
-
- if (!empty($values['application_id']))
- {
- $application_id =
$values['application_id'];
- }
- if ($application_id)
- {
- $application =
rental_application::get($application_id);
- }
- else
- {
- $application = new rental_application();
- }
+ $application_id =
!empty($values['application_id']) ? $values['application_id'] :
phpgw::get_var('id', 'int');
+ $application =
$this->bo->read_single($application_id);
}
if (!$this->acl_edit)
@@ -361,11 +349,11 @@
'status_list' => array('options' =>
$this->get_status_options($application->status)),
'mode' => $mode,
'tabs' =>
phpgwapi_jquery::tabview_generate($tabs, $active_tab),
+ 'value_active_tab' => $active_tab
);
phpgwapi_jquery::formvalidator_generate(array('date',
'security', 'file'));
phpgwapi_jquery::load_widget('autocomplete');
self::add_javascript('rental', 'rental',
'application.edit.js');
-
self::render_template_xsl(array('application',
'datatable_inline'), array($mode => $data));
}
/*
@@ -389,22 +377,16 @@
{
phpgw::no_access();
}
-// _debug_array($_POST);
- $application_id = phpgw::get_var('id', 'int');
$active_tab = phpgw::get_var('active_tab', 'string',
'REQUEST', 'application');
- if ($application_id)
- {
- $application =
rental_soapplication::get_instance()->read_single($application_id, true);
- }
- else
- {
- $application = new rental_application();
- }
+ $application_id = phpgw::get_var('id', 'int');
+
+ $application = $this->bo->read_single($application_id,
true);
+
/*
* Overrides with incoming data from POST
*/
- $application = $this->_populate($application);
+ $application = $this->bo->populate($application);
if($application->validate())
{
@@ -430,75 +412,33 @@
}
}
- private function _populate($application)
- {
- $fields = $this->fields;
-
- foreach ($fields as $field => $field_info)
- {
- if(($field_info['action'] & PHPGW_ACL_ADD) ||
($field_info['action'] & PHPGW_ACL_EDIT))
- {
- $application->set_field( $field,
phpgw::get_var($field, $field_info['type'] ) );
- }
- }
- return $application;
- }
-
-
/**
* (non-PHPdoc)
* @see rental/inc/rental_uicommon#query()
*/
public function query()
{
- $params = $this->build_default_read_params();
- $applications =
rental_soapplication::get_instance()->read($params);
+ $params = $this->bo->build_default_read_params();
+ $applications = $this->bo->read($params);
$status_text = array(
rental_application::STATUS_REGISTERED =>
lang('registered'),
rental_application::STATUS_PENDING =>
lang('pending'),
rental_application::STATUS_REJECTED =>
lang('rejected'),
rental_application::STATUS_APPROVED =>
lang('approved')
);
-
+ $dateformat =
$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'];
foreach ($applications['results'] as &$application)
{
$application['status'] =
$status_text[$application['status']];
$application['composite_type'] =
$this->composite_types[$application['composite_type']];
- $application['entry_date'] =
$GLOBALS['phpgw']->common->show_date($application['entry_date'], $dateformat);
+ $application['entry_date'] =
$GLOBALS['phpgw']->common->show_date($application['entry_date']);
+ $application['assign_date_start'] =
$GLOBALS['phpgw']->common->show_date($application['assign_date_start'],
$dateformat);
+ $application['assign_date_end'] =
$GLOBALS['phpgw']->common->show_date($application['assign_date_end'],
$dateformat);
$application['executive_officer'] =
$application['executive_officer'] ?
$GLOBALS['phpgw']->accounts->get($application['executive_officer'])->__toString()
: '';
}
array_walk($applications["results"], array($this,
"_add_links"), "rental.uiapplication.edit");
return $this->jquery_results($applications);
}
-
- protected function build_default_read_params()
- {
- $fields = $this->fields;
-
- $search = phpgw::get_var('search');
- $order = phpgw::get_var('order');
- $draw = phpgw::get_var('draw', 'int');
- $columns = phpgw::get_var('columns');
-
- $params = array(
- 'start' => phpgw::get_var('start', 'int',
'REQUEST', 0),
- 'results' => phpgw::get_var('length', 'int',
'REQUEST', 0),
- 'query' => $search['value'],
- 'sort' => $columns[$order[0]['column']]['data'],
- 'dir' => $order[0]['dir'],
- 'allrows' => phpgw::get_var('length', 'int') ==
-1,
- );
-
- foreach ($fields as $field => $_params)
- {
- if (!empty($_REQUEST["filter_$field"]))
- {
- $params['filters'][$field] =
phpgw::get_var("filter_$field", $_params['type']);
- }
- }
-
- return $params;
- }
}
\ No newline at end of file
Modified: trunk/rental/inc/model/class.application.inc.php
===================================================================
--- trunk/rental/inc/model/class.application.inc.php 2016-08-30 15:40:45 UTC
(rev 15548)
+++ trunk/rental/inc/model/class.application.inc.php 2016-08-30 17:08:17 UTC
(rev 15549)
@@ -27,7 +27,7 @@
* @version $Id: $
*/
- phpgw::import_class('rental.soapplication');
+ phpgw::import_class('rental.boapplication');
include_class('rental', 'model', 'inc/model/');
@@ -249,12 +249,12 @@
public function store()
{
- return
rental_soapplication::get_instance()->store($this);
+ return
rental_boapplication::get_instance()->store($this);
}
- public function get($id)
+ public function read_single($id)
{
- return
rental_soapplication::get_instance()->read_single($id, true);
+ return
rental_boapplication::get_instance()->read_single($id, true);
}
}
\ No newline at end of file
Modified: trunk/rental/inc/model/class.model.inc.php
===================================================================
--- trunk/rental/inc/model/class.model.inc.php 2016-08-30 15:40:45 UTC (rev
15548)
+++ trunk/rental/inc/model/class.model.inc.php 2016-08-30 17:08:17 UTC (rev
15549)
@@ -263,7 +263,7 @@
}
- private function _validate( $entity, array &$errors,
$field_prefix = '' )
+ private function _validate( $entity, array &$errors )
{
$fields = $this->get_fields();
foreach ($fields as $field => $params)
@@ -318,7 +318,7 @@
$alternatives_ok = true;
}
}
- $error_key = empty($field_prefix) ? $field :
"{$field_prefix}[{$field}]";
+ $error_key = empty($params['label']) ? $field :
$params['label'];
if ($params['required'] && (!isset($value) ||
($value !== '0' && empty($value))) && !$alternatives_ok)
{
Modified: trunk/rental/templates/base/application.xsl
===================================================================
--- trunk/rental/templates/base/application.xsl 2016-08-30 15:40:45 UTC (rev
15548)
+++ trunk/rental/templates/base/application.xsl 2016-08-30 17:08:17 UTC (rev
15549)
@@ -33,7 +33,7 @@
<form id="form" name="form" method="post"
action="{$form_action}" class="pure-form pure-form-aligned">
<div id="tab-content">
<xsl:value-of disable-output-escaping="yes"
select="tabs"/>
- <input type="hidden" id="active_tab"
name="active_tab"/>
+ <input type="hidden" id="active_tab"
name="active_tab" value="{value_active_tab}"/>
<div id="application">
<fieldset>
<xsl:if test="application/id !=
''">
@@ -288,7 +288,7 @@
</label>
<input type="text"
name="email" id="email" value="{application/email}">
<xsl:attribute
name="data-validation">
-
<xsl:text>required</xsl:text>
+
<xsl:text>email</xsl:text>
</xsl:attribute>
</input>
<xsl:choose>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [15549] rental: more on application,
sigurdne <=