[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [11929] property: activate search on custom attribute
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [11929] property: activate search on custom attributes in tickets |
Date: |
Tue, 29 Apr 2014 12:33:25 +0000 |
Revision: 11929
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=11929
Author: sigurdne
Date: 2014-04-29 12:33:25 +0000 (Tue, 29 Apr 2014)
Log Message:
-----------
property: activate search on custom attributes in tickets
Modified Paths:
--------------
trunk/property/inc/class.custom_fields.inc.php
trunk/property/inc/class.sotts.inc.php
Modified: trunk/property/inc/class.custom_fields.inc.php
===================================================================
--- trunk/property/inc/class.custom_fields.inc.php 2014-04-29 10:33:33 UTC
(rev 11928)
+++ trunk/property/inc/class.custom_fields.inc.php 2014-04-29 12:33:25 UTC
(rev 11929)
@@ -816,4 +816,122 @@
}
return $ret;
}
+
+ /**
+ *
+ * @param integer $location_id
+ * @param string $entity_table
+ * @param string $criteria_id - if specified to datatypes
+ * @param string $query
+ * @return array
+ */
+ function get_custom_filter($location_id,$entity_table,
$criteria_id = '', $query = '')
+ {
+ $choice_table = 'phpgw_cust_choice';
+ $_querymethod = array();
+ $__querymethod = array();
+ $_joinmethod_datatype = array();
+
+ if($criteria_id)
+ {
+ $__querymethod = array("{$entity_table}.id =
-1"); // block query waiting for criteria
+ }
+
+ $this->_db->query("SELECT * FROM phpgw_cust_attribute
WHERE location_id = {$location_id} AND search='1'");
+
+ while ($this->_db->next_record())
+ {
+ switch ($this->_db->f('datatype'))
+ {
+ case 'V':
+ case 'email':
+ case 'T':
+ if(!$criteria_id)
+ {
+ $_querymethod[]=
"$entity_table." . $this->_db->f('column_name') . " {$this->_like}
'%{$query}%'";
+ $__querymethod =
array(); // remove block
+ }
+ break;
+ case 'CH':
+ if(!$criteria_id)
+ {
+ // from filter
+ $_querymethod[]=
"$entity_table." . $this->_db->f('column_name') . " {$this->_like}
'%,{$query},%'";
+ $__querymethod =
array(); // remove block
+
+ // from text-search
+ $_filter_choise =
"WHERE (phpgw_cust_choice.location_id =" . (int)$this->_db->f('location_id')
+ ." AND
phpgw_cust_choice.attrib_id =" . (int)$this->_db->f('id')
+ ." AND
phpgw_cust_choice.value {$this->_like} '%{$query}%')";
+
+
$this->_db2->query("SELECT phpgw_cust_choice.id FROM phpgw_cust_choice
{$_filter_choise}",__LINE__,__FILE__);
+ while
($this->_db2->next_record())
+ {
+
$_querymethod[]= "$entity_table." . $this->_db->f('column_name') . "
{$this->_like} '%,". $this->_db2->f('id') . ",%'";
+ }
+ }
+ break;
+ case 'R':
+ case 'LB':
+ if(!$criteria_id)
+ {
+ $_filter_choise =
"WHERE (phpgw_cust_choice.location_id =" . (int)$this->_db->f('location_id')
+ ." AND
phpgw_cust_choice.attrib_id =" . (int)$this->_db->f('id')
+ ." AND
phpgw_cust_choice.value {$this->_like} '%{$query}%')";
+
+
$this->_db2->query("SELECT phpgw_cust_choice.id FROM phpgw_cust_choice
{$_filter_choise}",__LINE__,__FILE__);
+ $__filter_choise =
array();
+ while
($this->_db2->next_record())
+ {
+
$__filter_choise[] = $this->_db2->f('id');
+ }
+
+ if($__filter_choise)
+ {
+
$_querymethod[]= "$entity_table." . $this->_db->f('column_name') . ' IN (' .
implode(',', $__filter_choise) . ')';
+ }
+
+ $__querymethod =
array(); // remove block
+ }
+ break;
+ case 'I':
+ if(ctype_digit($query) &&
!$criteria_id)
+ {
+ $_querymethod[]=
"$entity_table." . $this->_db->f('column_name') . " = " . (int)$query;
+ $__querymethod =
array(); // remove block
+ }
+ break;
+ case 'VENDOR':
+ if($criteria_id == 'vendor')
+ {
+ $_joinmethod_datatype[]
= "{$this->_join} fm_vendor ON ({$entity_table}." .
$this->_db->f('column_name') . " = fm_vendor.id AND fm_vendor.org_name
{$this->_like} '%{$query}%') ";
+ $__querymethod =
array(); // remove block
+ }
+ break;
+ case 'AB':
+ if($criteria_id == 'ab')
+ {
+ $_joinmethod_datatype[]
= "{$this->_join} phpgw_contact_person ON ({$entity_table}." .
$this->_db->f('column_name') . " = pphpgw_contact_person.person_id AND
(phpgw_contact_person.first_name {$this->_like} '%{$query}%' OR
phpgw_contact_person.last_name {$this->_like} '%{$query}%'))";
+ $__querymethod =
array(); // remove block
+ }
+ break;
+ case 'ABO':
+ if($criteria_id == 'abo')
+ {
+ $_joinmethod_datatype[]
= "{$this->_join} phpgw_contact_org ON ({$entity_table}." .
$this->_db->f('column_name') . " = phpgw_contact_org.org_id AND
phpgw_contact_org.name {$this->_like} '%{$query}%')";
+ $__querymethod =
array(); // remove block
+ }
+ break;
+ default:
+ if(!$criteria_id)
+ {
+ $_querymethod[]=
"$entity_table." . $this->_db->f('column_name') . " = '{$query}'";
+ $__querymethod =
array(); // remove block
+ }
+ }
+ }
+
+ $querymethod = array_merge($__querymethod,
$_querymethod);
+ return array('querymethod' => $querymethod,
'joinmethod_datatype' => $_joinmethod_datatype);
+ }
}
Modified: trunk/property/inc/class.sotts.inc.php
===================================================================
--- trunk/property/inc/class.sotts.inc.php 2014-04-29 10:33:33 UTC (rev
11928)
+++ trunk/property/inc/class.sotts.inc.php 2014-04-29 12:33:25 UTC (rev
11929)
@@ -404,6 +404,8 @@
$where= 'AND';
}
+ $location_id =
$GLOBALS['phpgw']->locations->get_id('property', '.ticket');
+
$querymethod = '';
if($query)
{
@@ -441,6 +443,17 @@
{
$querymethod .= ')';
}
+ $custom_filter =
$this->custom->get_custom_filter($location_id,'fm_tts_tickets', $criteria_id =
'', $query);
+
+ if ($custom_filter['querymethod'])
+ {
+ $_where = $where = 'AND' ? 'OR' :
'WHERE';
+ $querymethod .= " $_where (" . implode
(' OR ',$custom_filter['querymethod']) . ')';
+ }
+ else
if(isset($custom_filter['joinmethod_datatype']) &&
$custom_filter['joinmethod_datatype'])
+ {
+ $querymethod = '';
+ }
}
$return_fields =
"fm_tts_tickets.id,fm_tts_tickets.assignedto,fm_tts_tickets.status,fm_tts_tickets.user_id,"
@@ -460,18 +473,34 @@
. " {$this->left_join} fm_part_of_town ON
fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id"
. " {$this->left_join} fm_district ON
fm_district.id = fm_part_of_town.district_id"
. " {$order_join}"
- . " LEFT OUTER JOIN fm_tts_views ON
(fm_tts_tickets.id = fm_tts_views.id AND
fm_tts_views.account_id='{$this->account}')"
- . " {$filtermethod} {$querymethod}";
+ . " LEFT OUTER JOIN fm_tts_views ON
(fm_tts_tickets.id = fm_tts_views.id AND
fm_tts_views.account_id='{$this->account}')";
+ if(isset($custom_filter['joinmethod_datatype']) &&
$custom_filter['joinmethod_datatype'])
+ {
+ foreach($custom_filter['joinmethod_datatype']
as $_joinmethod)
+ {
+ $sql .= $_joinmethod;
+ }
+ }
+ $sql .= " {$filtermethod} {$querymethod}";
+
$sql_cnt = "SELECT DISTINCT fm_tts_tickets.budget
,fm_tts_tickets.actual_cost, fm_tts_tickets.id FROM fm_tts_tickets"
. " {$this->left_join} fm_location1 ON
fm_tts_tickets.loc1=fm_location1.loc1"
. " {$this->left_join} fm_part_of_town ON
fm_location1.part_of_town_id=fm_part_of_town.part_of_town_id"
. " {$this->left_join} fm_district ON
fm_district.id = fm_part_of_town.district_id"
. " $order_join"
- . " LEFT OUTER JOIN fm_tts_views ON
(fm_tts_tickets.id = fm_tts_views.id AND
fm_tts_views.account_id='{$this->account}')"
- . " $filtermethod $querymethod";
+ . " LEFT OUTER JOIN fm_tts_views ON
(fm_tts_tickets.id = fm_tts_views.id AND
fm_tts_views.account_id='{$this->account}')";
+ if(isset($custom_filter['joinmethod_datatype']) &&
$custom_filter['joinmethod_datatype'])
+ {
+ foreach($custom_filter['joinmethod_datatype']
as $_joinmethod)
+ {
+ $sql_cnt .= $_joinmethod;
+ }
+ }
+
+ $sql_cnt .= " {$filtermethod} {$querymethod}";
//_debug_array($sql);
$cache_info =
phpgwapi_cache::session_get('property','tts_listing_metadata');
@@ -523,7 +552,6 @@
$this->sum_actual_cost =
$cache_info['sum_actual_cost'];
$this->sum_difference = $cache_info['sum_difference'];
- $location_id =
$GLOBALS['phpgw']->locations->get_id('property', '.ticket');
$tickets = array();
if(!$dry_run)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [11929] property: activate search on custom attributes in tickets,
Sigurd Nes <=