SS/Sugar

Add a search field2

onesixx 2013. 4. 24. 17:20
반응형

나의 담당 My Items

 

1. 검색필드 정의 (search field definition)

          /modules/Opportunities/metadata/SearchFields.php

custom/modules/Opportunities/metadata/SearchFields.php

'current_user_only'=> array(
    'query_type'=>'default',
    'db_field'=>array( 'assigned_user_id' ),
    'type' => 'bool'

    'my_items'=>true,
    'vname' => 'LBL_CURRENT_USER_FILTER',
),


'open_only' => array(
    'query_type'=>'default',
    'db_field'=>array('sales_stage'),
    'type'=>'bool',

    'operator'=>'not in',
    'closed_values' => array('Closed Won', 'Closed Lost'),
),


2.  검색폼에 정의한검색필드 배치

          /modules/Opportunities/metadata/searchdefs.php

custom/modules/Opportunities/metadata/searchdefs.php

$searchdefs['Opportunities'] = array(
    'templateMeta' => array (
        'maxColumns' => '3',
        'maxColumnsBasic' => '4',
        'widths' =>     array (
            'label' => '10',
            'field' => '30',
        ),
    ),
    'layout' => array (
        'basic_search' => array (
            'name' =>
                array (
                    'name' => 'name',
                    'default' => true,
                    'width' => '10%',
                ),
            'current_user_only' =>
                array (
                    'name' => 'current_user_only',
                    'label' => 'LBL_CURRENT_USER_FILTER',
                    'type' => 'bool',
                    'default' => true,
                    'width' => '10%',
                ),
                array (
                    'name' => 'open_only',
                    'label' => 'LBL_OPEN_ITEMS',
                   'type' => 'bool',
                    'default' => false,
                    'width' => '10%'
                ),
        ),

 

===================================================================

3. Dropdown 대신에 Checkbox

<참조>http://forums.sugarcrm.com/f6/checkbox-instead-dropdown-49260/
SearchView.tpl 로 인해 변경되고, SugarFieldBool.php는 수정함.

include\SugarFields\Fields\Bool\SugarFieldBool.php

 

 

C:\xampp\htdocs\s6\include\SearchForm

           /include/SearchForm/SearchForm2.php

custom/include/SearchForm/SearchForm2.php

==================================================================

['query_type']=='case_insensitive'

('query_type' => 'default',

['query_type'] == 'format'

'query_type'=>'application'

==================================================================

'operator'=>'not in',

operator'=>'in'),

'between';

if(in_array($parms['operator'], array('=', 'between', "not_equal", 'less_than', 'greater_than', 'less_than_equals', 'greater_than_equals')))

'operator'=>'=')

==========

C:\xampp\htdocs\sce1\include\SugarObjects\templates\company\metadata\SearchFields.php:
   59          'email'=> array(
   60              'query_type' => 'default',
   61:             'operator' => 'subquery',
   62              'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
   63              'db_field' => array(

C:\xampp\htdocs\sce1\include\SugarObjects\templates\person\vardefs.php:
  145              'query_type' => 'default',
  146              'source' => 'non-db',
  147:             'operator' => 'subquery',
  148              'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
  149              'db_field' => array(

=======================================================

현재 사용자 정보 얻기

global $current_user;
    echo $current_user->id;
    echo $current_user->user_name;

Write only this two lines of code to get the current user id :
global $current_user;
          $dude_id = $current_user->id;

You can catch it looking at session variable :
$_SESSION['authenticated_user_id'])

====================================================

<?php

global $current_user;

$id = $current_user->id;

 

// created: 2013-04-23 19:01:33

$searchFields['Opportunities'] = array (

  'sixx_only' =>  array (

'query_type' => 'default',

'db_field' => array ( 0 => 'assigned_user_id',),

//'field_value' => $id

    'operator' => 'subquery',

    'subquery' => 'select id

                     from users

                    WHERE deleted=0

                      AND users.reports_to_id = "'.$id.'" and 1 =',

'type' => 'bool',

  ),

=================
<?php
 
$searchdefs ['Opportunities'] =
array (
  'layout' =>
  array (
'basic_search' =>
array (
'sixx_only' =>
array (
'name' => 'sixx_only',
'label' => 'LBL_sixx',
'type' => 'bool',
'default' => true,
'width' => '10%',
),
===========================
 
C:\sugar\apps\sugarcrm\htdocs\include\SearchForm\SearchForm.php      SearchForm2.php
 
 
 
quote($val)
 
isset함수
http://pokute.tistory.com/18
http://habony.tistory.com/166
http://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=tipntech&wr_id=72596&sca=%B9%AE%B9%FD
=========================================================================
========================================================
 
SELECT distinct assigned_user_id
FROM `opportunities`
where assigned_user_id in (select id from users where reports_to_id ='seed_will_id')
 
 
  'sixx_only' =>
  array (
'query_type' => 'default',
'db_field' =>
array (
0 => 'assigned_user_id',
),
'operator' => 'subquery',
   'subquery'=>
        'select id from users where reports_to_id =$id',
'type' => 'bool',
  ),
==================================================================================
 
  'sales_stage' =>
  array (
'query_type' => 'default',
'operator' => '=',
'options' => 'sales_stage_dom',
'template_var' => 'SALES_STAGE_OPTIONS',
'options_add_blank' => true,
  ),
 
  'is_admin'=> array(
  'query_type'=>'default',
  'operator'=>'=',
 
  'input_type' => 'checkbox'),
=========================================================================
'email'=> array(
'query_type' => 'default',
'operator' => 'subquery',
'subquery' => 'SELECT eabr.bean_id
              FROM email_addr_bean_rel eabr
              JOIN email_addresses ea
              ON (ea.id = eabr.email_address_id)
              WHERE eabr.deleted=0 AND ea.email_address LIKE',
'db_field' => array( 'id', ),
'vname' =>'LBL_ANY_EMAIL',
),
==========
'filename' => array(
       'query_type' => 'format',
       'operator' => 'subquery',
       'subquery' => 'SELECT document_revisions.id FROM document_revisions
          WHERE document_revisions.deleted=0
  AND document_revisions.filename LIKE \'{0}\'',
             'db_field' => array(0 => 'document_revision_id')
      ),
 
============
        'phone'=> array(
            'query_type' => 'default',
            'operator' => 'subquery',
            'subquery' => array('SELECT id FROM users where phone_home LIKE ',
                'SELECT id FROM users where phone_fax LIKE',
                'SELECT id FROM users where phone_other LIKE',
                'SELECT id FROM users where phone_work LIKE',
                'SELECT id FROM users where phone_mobile LIKE',
                'OR' =>true
            ),
            'db_field' => array(
                'id',
            )
        ),
 
 
the custom/modules/Opportunities/metadata/SearchFields.php
 
'my_options'=>    array(
    'query_type'=>'default',
    'db_field'=>array(
        'id',
    ),
    'operator'=>'subquery',
    'subquery'=>
        'SELECT id
        FROM  `opportunities`
        WHERE deleted=0
        AND name LIKE',
 
),
 
===>
 
(calls.id IN (SELECT id
            FROM  `opportunities`
            WHERE deleted=0
            AND name LIKE')
 
)
==============================================
select id
from users
where reports_to_id in (select id from `users` where deleted=0 and ) '8da1e644-dcab-a3c5-68ad-50f269ca7b4a'
 
 
select id
from users
where reports_to_id = $current_user-->id
 
 
'my_options'=>    array(
    'query_type'=>'default',
    'db_field'=>array(
        'reports_to_id',
    ),
    'operator'=>'=',
    'subquery'=>
        'SELECT id
        FROM  `opportunities`
        WHERE deleted=0
        AND name LIKE',
 
),
 
=======================================
 
  'open_only' =>
  array (
'query_type' => 'default',
'db_field' =>
array (
0 => 'sales_stage',
),
'operator' => 'not in',
'closed_values' =>
array (
0 => 'Closed Won',
1 => 'Closed Lost',
),
'type' => 'bool',
  ),
반응형

'SS > Sugar' 카테고리의 다른 글

sugar error  (0) 2013.10.16
Angel's Blog: SugarCRM: SOAP API Performance  (0) 2013.10.09
CONNECT BY LEVEL  (0) 2013.05.07
How to: Create an own chart Dashlet in 5.0.0c in 9 Steps  (0) 2013.01.20
dropdown by role  (0) 2012.08.20
campaign tracker  (0) 2012.07.16