[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [14845] booking: fix join in filter
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [14845] booking: fix join in filter |
Date: |
Wed, 16 Mar 2016 14:08:23 +0000 |
Revision: 14845
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=14845
Author: sigurdne
Date: 2016-03-16 14:08:23 +0000 (Wed, 16 Mar 2016)
Log Message:
-----------
booking: fix join in filter
Modified Paths:
--------------
trunk/booking/inc/class.boapplication.inc.php
trunk/booking/inc/class.uiapplication.inc.php
Modified: trunk/booking/inc/class.boapplication.inc.php
===================================================================
--- trunk/booking/inc/class.boapplication.inc.php 2016-03-16 11:57:29 UTC
(rev 14844)
+++ trunk/booking/inc/class.boapplication.inc.php 2016-03-16 14:08:23 UTC
(rev 14845)
@@ -215,20 +215,34 @@
* which the given user has access to
*
* @param int $user_id
+ * @param int $building_id
*/
- public function accessable_applications( $user_id )
+ public function accessable_applications( $user_id, $building_id
)
{
$applications = array();
$this->db = & $GLOBALS['phpgw']->db;
- $sql = "SELECT DISTINCT ap.id
- FROM bb_application ap
- INNER JOIN bb_application_resource ar
ON ar.application_id = ap.id
- INNER JOIN bb_resource re ON re.id =
ar.resource_id
- INNER JOIN bb_building_resource br ON
re.id = br.resource_id
- INNER JOIN bb_building bu ON bu.id =
br.resource_id
- INNER JOIN bb_permission pe ON
pe.object_id = bu.id and pe.object_type = 'building'
- WHERE pe.subject_id = " . $user_id;
+ $filtermethod = array();
+
+ $filtermethod[] = '1=1';
+
+ if($user_id)
+ {
+ $filtermethod[] = "pe.subject_id = {$user_id}";
+ }
+ if($building_id)
+ {
+ $filtermethod[] = "bu.id = {$building_id}";
+ }
+
+ $sql = "SELECT DISTINCT ap.id"
+ . " FROM bb_application ap"
+ . " INNER JOIN bb_application_resource ar ON
ar.application_id = ap.id"
+ . " INNER JOIN bb_building_resource br ON
br.resource_id = ar.resource_id"
+ . " INNER JOIN bb_building bu ON bu.id =
br.building_id"
+ . " INNER JOIN bb_permission pe ON pe.object_id
= bu.id and pe.object_type = 'building'"
+ . " WHERE " . implode(' AND ', $filtermethod);
+
$this->db->query($sql);
$result = $this->db->resultSet;
Modified: trunk/booking/inc/class.uiapplication.inc.php
===================================================================
--- trunk/booking/inc/class.uiapplication.inc.php 2016-03-16 11:57:29 UTC
(rev 14844)
+++ trunk/booking/inc/class.uiapplication.inc.php 2016-03-16 14:08:23 UTC
(rev 14845)
@@ -248,6 +248,7 @@
{
return $this->query();
}
+ phpgwapi_jquery::load_widget('autocomplete');
$data = array(
'datatable_name' => lang('application'),
@@ -281,21 +282,29 @@
)
)
),
- array('type' =>
'filter',
+/* array('type' =>
'filter',
'name' =>
'buildings',
'text' =>
lang('Building') . ':',
'list' =>
$this->bo->so->get_buildings(),
),
+*/
+ array('type' =>
'autocomplete',
+ 'name' =>
'building',
+ 'ui' =>
'building',
+ 'text' =>
lang('Building') . ':',
+ 'onItemSelect'
=> 'updateBuildingFilter',
+
'onClearSelection' => 'clearBuildingFilter'
+ ),
array('type' =>
'filter',
'name' =>
'activities',
'text' =>
lang('Activity') . ':',
'list' =>
$this->bo->so->get_activities_main_level(),
),
- array(
+ /* array(
'type' =>
'link',
'value' =>
$_SESSION['showall'] ? lang('Show only active') : lang('Show all'),
'href' =>
self::link(array('menuaction' => $this->url_prefix . '.toggle_show_inactive'))
- ),
+ ),*/
),
),
),
@@ -360,36 +369,31 @@
public function query()
{
-
+ $building_id = phpgw::get_var('filter_building_id',
'int', 'REQUEST', null);
// users with the booking role admin should have access
to all buildings
// admin users should have access to all buildings
- if
(!isset($GLOBALS['phpgw_info']['user']['apps']['admin']) &&
-
!$this->bo->has_role(booking_sopermission::ROLE_MANAGER))
+ if
(!isset($GLOBALS['phpgw_info']['user']['apps']['admin']) &&
!$this->bo->has_role(booking_sopermission::ROLE_MANAGER))
{
- $filters['id'] =
$this->bo->accessable_applications($GLOBALS['phpgw_info']['user']['id']);
+ $filters['id'] =
$this->bo->accessable_applications($GLOBALS['phpgw_info']['user']['id'],
$building_id);
}
+ else if($building_id)
+ {
+ $filters['id'] =
$this->bo->accessable_applications(null, $building_id);
+ }
+
+ $activity_id = phpgw::get_var('activities', 'int',
'REQUEST', null);
+ if ($activity_id)
+ {
+ $filters['activity_id'] =
$this->bo->so->get_activities($activity_id);
+ }
+ else
+ {
+ unset($filters['activity_id']);
+ }
$filters['status'] = 'NEW';
if (isset($_SESSION['showall']))
{
$filters['status'] = array('NEW', 'PENDING',
'REJECTED', 'ACCEPTED');
- $testdata = phpgw::get_var('buildings', 'int',
'REQUEST', null);
- if ($testdata != 0)
- {
- $filters['building_name'] =
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['building_name']);
- }
- $testdata2 = phpgw::get_var('activities',
'int', 'REQUEST', null);
- if ($testdata2 != 0)
- {
- $filters['activity_id'] =
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['activity_id']);
- }
}
else
{
@@ -400,30 +404,12 @@
}
elseif (isset($test))
{
- $filters['status'] =
phpgw::get_var('status');
+ $filters['status'] = $test;
}
else
{
$filters['status'] = 'NEW';
}
- $testdata = phpgw::get_var('buildings', 'int',
'REQUEST', null);
- if ($testdata != 0)
- {
- $filters['building_name'] =
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['building_name']);
- }
- $testdata2 = phpgw::get_var('activities',
'int', 'REQUEST', null);
- if ($testdata2 != 0)
- {
- $filters['activity_id'] =
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['activity_id']);
- }
}
$search = phpgw::get_var('search');
@@ -483,123 +469,6 @@
return $this->jquery_results($applications);
}
- public function index_json()
- {
- // users with the booking role admin should have access
to all buildings
- // admin users should have access to all buildings
- if
(!isset($GLOBALS['phpgw_info']['user']['apps']['admin']) &&
-
!$this->bo->has_role(booking_sopermission::ROLE_MANAGER))
- {
- $filters['id'] =
$this->bo->accessable_applications($GLOBALS['phpgw_info']['user']['id']);
- }
- $filters['status'] = 'NEW';
- if (isset($_SESSION['showall']))
- {
- $filters['status'] = array('NEW', 'PENDING',
'REJECTED', 'ACCEPTED');
- $testdata = phpgw::get_var('buildings', 'int',
'REQUEST', null);
- if ($testdata != 0)
- {
- $filters['building_name'] =
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['building_name']);
- }
- $testdata2 = phpgw::get_var('activities',
'int', 'REQUEST', null);
- if ($testdata2 != 0)
- {
- $filters['activity_id'] =
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['activity_id']);
- }
- }
- else
- {
- $test = phpgw::get_var('status', 'string',
'REQUEST', null);
- if (phpgw::get_var('status') == 'none')
- {
- $filters['status'] = array('NEW',
'PENDING', 'REJECTED', 'ACCEPTED');
- }
- elseif (isset($test))
- {
- $filters['status'] =
phpgw::get_var('status');
- }
- else
- {
- $filters['status'] = 'NEW';
- }
- $testdata = phpgw::get_var('buildings', 'int',
'REQUEST', null);
- if ($testdata != 0)
- {
- $filters['building_name'] =
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['building_name']);
- }
- $testdata2 = phpgw::get_var('activities',
'int', 'REQUEST', null);
- if ($testdata2 != 0)
- {
- $filters['activity_id'] =
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST',
null));
- }
- else
- {
- unset($filters['activity_id']);
- }
- }
-
- $params = array(
- 'start' => phpgw::get_var('startIndex', 'int',
'REQUEST', 0),
- 'results' => phpgw::get_var('results', 'int',
'REQUEST', null),
- 'query' => phpgw::get_var('query'),
- 'sort' => phpgw::get_var('sort'),
- 'dir' => phpgw::get_var('dir'),
- 'filters' => $filters
- );
-
- $applications = $this->bo->so->read($params);
-
- foreach ($applications['results'] as &$application)
- {
- if (strstr($application['building_name'], "%"))
- {
- $search = array('%2C', '%C3%85',
'%C3%A5', '%C3%98', '%C3%B8', '%C3%86',
- '%C3%A6');
- $replace = array(',', 'Å', 'å', 'Ø',
'ø', 'Æ', 'æ');
- $application['building_name'] =
str_replace($search, $replace, $application['building_name']);
- }
-
- $dates = array();
- foreach ($application['dates'] as $data)
- {
- $dates[] = $data['from_'];
- break;
- }
- $fromdate = implode(',', $dates);
- $application['from_'] =
pretty_timestamp($fromdate);
- $application['status'] =
lang($application['status']);
- $application['created'] =
pretty_timestamp($application['created']);
- $application['modified'] =
pretty_timestamp($application['modified']);
- $application['frontend_modified'] =
pretty_timestamp($application['frontend_modified']);
- $application['resources'] =
$this->resource_bo->so->read(array('filters' => array(
- 'id' =>
$application['resources'])));
- $application['resources'] =
$application['resources']['results'];
- if ($application['resources'])
- {
- $names = array();
- foreach ($application['resources'] as
$res)
- {
- $names[] = $res['name'];
- }
- $application['what'] =
$application['resources'][0]['building_name'] . ' (' . join(', ', $names) . ')';
- }
- }
- array_walk($applications["results"], array($this,
"_add_links"), "booking.uiapplication.show");
- return $this->yui_results($applications);
- }
-
public function associated()
{
$associations = $this->assoc_bo->read();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [14845] booking: fix join in filter,
Sigurd Nes <=