[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [15326] activitycalendar: use socommon from rental, f
From: |
sigurdne |
Subject: |
[Fmsystem-commits] [15326] activitycalendar: use socommon from rental, fix sorting, fix show all |
Date: |
Thu, 23 Jun 2016 13:50:36 +0000 (UTC) |
Revision: 15326
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=15326
Author: sigurdne
Date: 2016-06-23 13:50:36 +0000 (Thu, 23 Jun 2016)
Log Message:
-----------
activitycalendar: use socommon from rental, fix sorting, fix show all
Modified Paths:
--------------
trunk/activitycalendar/inc/class.soactivity.inc.php
trunk/activitycalendar/inc/class.soarena.inc.php
trunk/activitycalendar/inc/class.socommon.inc.php
trunk/activitycalendar/inc/class.socontactperson.inc.php
trunk/activitycalendar/inc/class.sogroup.inc.php
trunk/activitycalendar/inc/class.soorganization.inc.php
trunk/activitycalendar/inc/class.uiactivities.inc.php
trunk/activitycalendar/inc/class.uiarena.inc.php
trunk/activitycalendar/inc/class.uiorganization.inc.php
Modified: trunk/activitycalendar/inc/class.soactivity.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.soactivity.inc.php 2016-06-23 12:34:51 UTC
(rev 15325)
+++ trunk/activitycalendar/inc/class.soactivity.inc.php 2016-06-23 13:50:36 UTC
(rev 15326)
@@ -107,6 +107,9 @@
//$order = "ORDER BY id $dir";
$order = "ORDER BY $sort_field $dir";
}
+
+ $this->sort_field = str_ireplace(" {$dir}", '',
$sort_field);
+
/* else
{
$dir = $ascending ? 'ASC' : 'DESC';
Modified: trunk/activitycalendar/inc/class.soarena.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.soarena.inc.php 2016-06-23 12:34:51 UTC
(rev 15325)
+++ trunk/activitycalendar/inc/class.soarena.inc.php 2016-06-23 13:50:36 UTC
(rev 15326)
@@ -41,10 +41,10 @@
//Add columns to this array to include them in the query
$columns = array();
+ $dir = $ascending ? 'ASC' : 'DESC';
if ($sort_field != null)
{
- $dir = $ascending ? 'ASC' : 'DESC';
if ($sort_field == 'arena_id')
{
$sort_field = 'id';
@@ -53,9 +53,10 @@
}
else if (!$return_count)
{
- $dir = $ascending ? 'ASC' : 'DESC';
- $order = "ORDER BY arena.arena_name $dir";
+ $sort_field = 'arena.arena_name';
+ $order = "ORDER BY $sort_field $dir";
}
+ $this->sort_field = str_ireplace(" {$dir}", '',
$sort_field);
if ($search_for)
{
Modified: trunk/activitycalendar/inc/class.socommon.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.socommon.inc.php 2016-06-23 12:34:51 UTC
(rev 15325)
+++ trunk/activitycalendar/inc/class.socommon.inc.php 2016-06-23 13:50:36 UTC
(rev 15326)
@@ -1,324 +1,14 @@
<?php
+ phpgw::import_class('rental.socommon');
- abstract class activitycalendar_socommon
+ abstract class activitycalendar_socommon extends rental_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;
+ parent::__construct();
}
-
- /**
- * 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 (bool)$value;
- }
- elseif ($type == 'int')
- {
- return (int)$value;
- }
- elseif ($value === null || $value == 'NULL')
- {
- return null;
- }
- 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(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")
- */
- 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 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 )
- {
- $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('',
false, $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 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 abstract function get_query( string $sort_field, bool
$ascending, string $search_for, string $search_type, array $filters, bool
$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;
- }
-
+
protected function generate_secret( $length = 10 )
{
return substr(base64_encode(rand(1000000000,
9999999999)), 0, $length);
Modified: trunk/activitycalendar/inc/class.socontactperson.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.socontactperson.inc.php 2016-06-23
12:34:51 UTC (rev 15325)
+++ trunk/activitycalendar/inc/class.socontactperson.inc.php 2016-06-23
13:50:36 UTC (rev 15326)
@@ -49,6 +49,8 @@
$order = "ORDER BY id $dir";
}
*/
+// $this->sort_field = str_ireplace(" {$dir}", '',
$sort_field);
+
if ($search_for)
{
$query = $this->marshal($search_for, 'string');
Modified: trunk/activitycalendar/inc/class.sogroup.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.sogroup.inc.php 2016-06-23 12:34:51 UTC
(rev 15325)
+++ trunk/activitycalendar/inc/class.sogroup.inc.php 2016-06-23 13:50:36 UTC
(rev 15326)
@@ -46,8 +46,11 @@
if ($sort_field != null)
{
$dir = $ascending ? 'ASC' : 'DESC';
- $order = "ORDER BY bb_group.id $dir";
+ $sort_field = 'bb_group.id';
+ $order = "ORDER BY $sort_field $dir";
}
+
+ $this->sort_field = str_ireplace(" {$dir}", '',
$sort_field);
if ($search_for)
{
$query = $this->marshal($search_for, 'string');
Modified: trunk/activitycalendar/inc/class.soorganization.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.soorganization.inc.php 2016-06-23
12:34:51 UTC (rev 15325)
+++ trunk/activitycalendar/inc/class.soorganization.inc.php 2016-06-23
13:50:36 UTC (rev 15326)
@@ -47,14 +47,19 @@
//Add columns to this array to include them in the query
$columns = array();
+ $dir = $ascending ? 'ASC' : 'DESC';
if ($sort_field != null && !$return_count)
{
- if ($sort_field == 'identifier')
+ if ($sort_field == 'identifier' )
{
$sort_field = 'org.id';
}
- $dir = $ascending ? 'ASC' : 'DESC';
+ else if ( $sort_field == 'organization_number')
+ {
+ $sort_field = 'org.orgno';
+ }
+
$order = "ORDER BY $sort_field $dir";
}
else if (!$return_count)
@@ -62,6 +67,9 @@
$dir = $ascending ? 'ASC' : 'DESC';
$order = "ORDER BY org.name $dir";
}
+
+ $this->sort_field = str_ireplace(" {$dir}", '',
$sort_field);
+
if ($search_for)
{
$query = $this->marshal($search_for, 'string');
Modified: trunk/activitycalendar/inc/class.uiactivities.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.uiactivities.inc.php 2016-06-23
12:34:51 UTC (rev 15325)
+++ trunk/activitycalendar/inc/class.uiactivities.inc.php 2016-06-23
13:50:36 UTC (rev 15326)
@@ -705,7 +705,6 @@
$columns = phpgw::get_var('columns');
$start_index = phpgw::get_var('start', 'int',
'REQUEST', 0);
- $num_of_objects = (phpgw::get_var('length', 'int') <=
0) ? $this->user_rows_per_page : phpgw::get_var('length', 'int');
$sort_field = ($columns[$order[0]['column']]['data']) ?
$columns[$order[0]['column']]['data'] : 'id';
$sort_ascending = ($order[0]['dir'] == 'desc') ? false
: true;
// Form variables
@@ -716,6 +715,10 @@
$result_objects = array();
$result_count = 0;
+ $length = phpgw::get_var('length', 'int');
+ $user_rows_per_page = $length > 0 ? $length :
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+ $num_of_objects = $length == -1 ? null :
$user_rows_per_page;
+
$export = phpgw::get_var('export', 'bool');
if ($export)
{
Modified: trunk/activitycalendar/inc/class.uiarena.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.uiarena.inc.php 2016-06-23 12:34:51 UTC
(rev 15325)
+++ trunk/activitycalendar/inc/class.uiarena.inc.php 2016-06-23 13:50:36 UTC
(rev 15326)
@@ -234,7 +234,6 @@
$columns = phpgw::get_var('columns');
$start_index = phpgw::get_var('start', 'int',
'REQUEST', 0);
- $num_of_objects = (phpgw::get_var('length', 'int') <=
0) ? $this->user_rows_per_page : phpgw::get_var('length', 'int');
$sort_field = ($columns[$order[0]['column']]['data']) ?
$columns[$order[0]['column']]['data'] : 'id';
$sort_ascending = ($order[0]['dir'] == 'desc') ? false
: true;
// Form variables
@@ -247,6 +246,10 @@
//Retrieve the type of query and perform type specific
logic
$query_type = phpgw::get_var('type');
+ $length = phpgw::get_var('length', 'int');
+ $user_rows_per_page = $length > 0 ? $length :
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+ $num_of_objects = $length == -1 ? null :
$user_rows_per_page;
+
$export = phpgw::get_var('export', 'bool');
if ($export)
{
Modified: trunk/activitycalendar/inc/class.uiorganization.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.uiorganization.inc.php 2016-06-23
12:34:51 UTC (rev 15325)
+++ trunk/activitycalendar/inc/class.uiorganization.inc.php 2016-06-23
13:50:36 UTC (rev 15326)
@@ -538,7 +538,6 @@
$columns = phpgw::get_var('columns');
$start_index = phpgw::get_var('start', 'int',
'REQUEST', 0);
- $num_of_objects = (phpgw::get_var('length', 'int') <=
0) ? $this->user_rows_per_page : phpgw::get_var('length', 'int');
$sort_field = ($columns[$order[0]['column']]['data']) ?
$columns[$order[0]['column']]['data'] : 'identifier';
$sort_ascending = ($order[0]['dir'] == 'desc') ? false
: true;
// Form variables
@@ -549,6 +548,10 @@
$result_objects = array();
$result_count = 0;
+ $length = phpgw::get_var('length', 'int');
+ $user_rows_per_page = $length > 0 ? $length :
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
+ $num_of_objects = $length == -1 ? null :
$user_rows_per_page;
+
$export = phpgw::get_var('export', 'bool');
if ($export)
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [15326] activitycalendar: use socommon from rental, fix sorting, fix show all,
sigurdne <=