Results 1 to 10 of 10

Thread: where is db query from base modules?

  1. #1
    Holusa is offline Junior Member
    Join Date
    Jan 2009
    Posts
    3

    Default where is db query from base modules?

    Hallo,

    where is queryies definition for accounts, contacts, etc...?

    I need insert custom where prarameter to basic query...for ex.: select * from accounts where name like '%a%'.

    thanks,

    @mh

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: where is db query from base modules?

    Hi Holusa

    You meed to:
    1. Create a new script containing a class which extends the module class: custom/modules/<ModuleName>/ModuleNameListView.php
    This class will extends the default module class and implement the method create_new_list_query()

    2. Create a custom controller for these modules: custom/modules/<ModuleName>/controller.php
    Implement the method action_listview() where you will override the $bean->list for the ListView:

    PHP Code:
        function action_listview() {
            require_once(
    'custom/modules/<ModuleName>/<ModuleName>ListView.php');

            
    $this->bean = new <ClassName>ListView();
        } 
    3. Override the $ret_array inside the create_new_list_query according to your needs.
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    Holusa is offline Junior Member
    Join Date
    Jan 2009
    Posts
    3

    Default Re: where is db query from base modules?

    Hi Andopes,

    thx for your quick reply. But im testing this two days and nothitg.
    Any tutorial or help?

    What i need?
    Filter data in base list in accounts module.
    SELECT * FROM accounts WHERE account.name LIKE '%a%';

    and use this query as base for extending with searches.

    Thank you.




    Quote Originally Posted by andopes View Post
    Hi Holusa

    You meed to:
    1. Create a new script containing a class which extends the module class: custom/modules/<ModuleName>/ModuleNameListView.php
    This class will extends the default module class and implement the method create_new_list_query()

    2. Create a custom controller for these modules: custom/modules/<ModuleName>/controller.php
    Implement the method action_listview() where you will override the $bean->list for the ListView:

    PHP Code:
        function action_listview() {
            require_once(
    'custom/modules/<ModuleName>/<ModuleName>ListView.php');

            
    $this->bean = new <ClassName>ListView();
        } 
    3. Override the $ret_array inside the create_new_list_query according to your needs.

  4. #4
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: where is db query from base modules?

    Hi Holusa

    custom/modules/<ModuleName>/controller.php

    PHP Code:
    <?PHP
    require_once('include/MVC/Controller/SugarController.php');
    require_once(
    'modules/Opportunities/OpportunityListView.php');

    class 
    OpportunitiesController extends SugarController {
        function 
    action_listview() {
            
    $this->view 'list';
            
    $GLOBALS['view'] = $this->view;
            
    $this->bean = new OpportunityListView();
            
    $this->view_object_map['bean'] = $this->bean;
        }
    }
    ?>
    custom/modules/OpportunityListView

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    OportunityListView extends Opportunity {
        function 
    OpportunityListView() {
            
    parent::Opportunity();
        }
        
        function 
    create_new_list_query($order_by$where,$filter=array(),$params=array(), $show_deleted 0,$join_type=''$return_array false,$parentbean$singleSelect false){

            
    $ret_array parent::create_new_list_query($order_by$where,$filter,$params$show_deleted,$join_type$return_array,$parentbean$singleSelect);
            
            
    $ret_array['select'] .= " , up2_insertionorders.department_id, up2_insertionorders.advertiser_id, up2_insertionorders.publisher_id ";
            
            
    $ret_array['from'] .= " INNER JOIN up2_insertionorders ON up2_placements.up2_insertionorders_id = up2_insertionorders.id ";
            
            
    $ret_array['where'] = str_replace('up2_placements.department_id''up2_insertionorders.department_id'$ret_array['where']);
            
            
    $ret_array['where'] = str_replace("up2_placements.advertiser_name like '" $_POST['advertiser_name_basic'] . "%'""up2_insertionorders.advertiser_id in (SELECT id FROM `accounts` WHERE name LIKE '" $_POST['advertiser_name_basic'] . "')"$ret_array['where']);
            
            
    $ret_array['where'] = str_replace("up2_placements.publisher_name like '" $_POST['publisher_name_basic'] . "%'""up2_insertionorders.publisher_id in (SELECT id FROM `accounts` WHERE name LIKE '" $_POST['publisher_name_basic'] . "')"$ret_array['where']);
            
            
    $ret_array['where'] = str_replace("up2_placements.io_order_number_name"'up2_insertionorders.name'$ret_array['where']);
            
            
    $date_modified_basicFormatted $_POST['date_modified_basic'];
            
            
    $date_modified_basicFormatted date("Y-m-d"strtotime($date_modified_basicFormatted));
            
            
    $ret_array['where'] = str_replace("up2_placements.date_modified like '" $_POST['date_modified_basic'] . "%'""up2_placements.date_modified LIKE '" $date_modified_basicFormatted "%' "$ret_array['where']);
            
            
    $ret_array['where'] .= " AND up2_insertionorders.status = 'booked' ";

            return 
    $ret_array;
        }
    }
    ?>
    Obviously you need to modify the class name, function name and other stuffs to accomplish your needs.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  5. #5
    Holusa is offline Junior Member
    Join Date
    Jan 2009
    Posts
    3

    Default Re: where is db query from base modules?

    Hi Andopes,

    If i use your solution, Sugar wrote "Call to a member function setup() on a non-object in D:\xampp\htdocs\sugar\include\MVC\Controller\Contr ollerFactory.php on line 59"

    What is this? How i setup this setup()?

    @mh




    Quote Originally Posted by andopes View Post
    Hi Holusa

    custom/modules/<ModuleName>/controller.php

    PHP Code:
    <?PHP
    require_once('include/MVC/Controller/SugarController.php');
    require_once(
    'modules/Opportunities/OpportunityListView.php');

    class 
    OpportunitiesController extends SugarController {
        function 
    action_listview() {
            
    $this->view 'list';
            
    $GLOBALS['view'] = $this->view;
            
    $this->bean = new OpportunityListView();
            
    $this->view_object_map['bean'] = $this->bean;
        }
    }
    ?>
    custom/modules/OpportunityListView

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    class 
    OportunityListView extends Opportunity {
        function 
    OpportunityListView() {
            
    parent::Opportunity();
        }
        
        function 
    create_new_list_query($order_by$where,$filter=array(),$params=array(), $show_deleted 0,$join_type=''$return_array false,$parentbean$singleSelect false){

            
    $ret_array parent::create_new_list_query($order_by$where,$filter,$params$show_deleted,$join_type$return_array,$parentbean$singleSelect);
            
            
    $ret_array['select'] .= " , up2_insertionorders.department_id, up2_insertionorders.advertiser_id, up2_insertionorders.publisher_id ";
            
            
    $ret_array['from'] .= " INNER JOIN up2_insertionorders ON up2_placements.up2_insertionorders_id = up2_insertionorders.id ";
            
            
    $ret_array['where'] = str_replace('up2_placements.department_id''up2_insertionorders.department_id'$ret_array['where']);
            
            
    $ret_array['where'] = str_replace("up2_placements.advertiser_name like '" $_POST['advertiser_name_basic'] . "%'""up2_insertionorders.advertiser_id in (SELECT id FROM `accounts` WHERE name LIKE '" $_POST['advertiser_name_basic'] . "')"$ret_array['where']);
            
            
    $ret_array['where'] = str_replace("up2_placements.publisher_name like '" $_POST['publisher_name_basic'] . "%'""up2_insertionorders.publisher_id in (SELECT id FROM `accounts` WHERE name LIKE '" $_POST['publisher_name_basic'] . "')"$ret_array['where']);
            
            
    $ret_array['where'] = str_replace("up2_placements.io_order_number_name"'up2_insertionorders.name'$ret_array['where']);
            
            
    $date_modified_basicFormatted $_POST['date_modified_basic'];
            
            
    $date_modified_basicFormatted date("Y-m-d"strtotime($date_modified_basicFormatted));
            
            
    $ret_array['where'] = str_replace("up2_placements.date_modified like '" $_POST['date_modified_basic'] . "%'""up2_placements.date_modified LIKE '" $date_modified_basicFormatted "%' "$ret_array['where']);
            
            
    $ret_array['where'] .= " AND up2_insertionorders.status = 'booked' ";

            return 
    $ret_array;
        }
    }
    ?>
    Obviously you need to modify the class name, function name and other stuffs to accomplish your needs.

    Cheers

  6. #6
    vishwasrao's Avatar
    vishwasrao is offline A Prolific Poster
    Join Date
    Sep 2008
    Location
    Pune,Maharashtra,India
    Posts
    385

    Smile Re: where is db query from base modules?

    Hi andopes,

    It worked for me.

    I done acoording to ur instructions.but there is one problem .

    In listview when i click on record there is error

    Error retrieving record. This record may be deleted or you may not be authorized to view it.
    you know reason behind it
    Vishwasrao Salunkhe
    vishwasrao.salunkhe@gmail.com
    Fan Of Sachin Tendulkar
    Operating System :- Windows XP
    PHP Version:- 5.3
    Apache :-2.2.11
    MYSQL :-5.1.36

  7. #7
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: where is db query from base modules?

    Hi guys

    Let me know the script you had wrote based on my example.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  8. #8
    mel0 is offline Junior Member
    Join Date
    Dec 2009
    Posts
    4

    Default Re: where is db query from base modules?

    Hi Andopes,

    If i use your solution, Sugar wrote: "Notice: Undefined index: phone_mobile in D:\wamp\www\Sugar\modules\imob_Cerere\imob_CerereL istView.php on line 15"

    PHP Code:
    <?PHP
    require_once('include/MVC/Controller/SugarController.php');
    require_once(
    'modules/imob_Cerere/imob_CerereListView.php');

    class 
    imob_CerereController extends SugarController {
    function 
    action_listview() {
            
    $this->view 'list';
            
    $GLOBALS['view'] = $this->view;
            
    $this->bean = new imob_CerereListView();
            
    $this->view_object_map['bean'] = $this->bean;
        }
    }
    ?>

    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once(
    'modules/imob_Cerere/imob_Cerere.php');
    class 
    imob_CerereListView extends imob_Cerere {
        function 
    imob_CerereListView(){
        
    parent::imob_Cerere();
        }
    function 
    create_new_list_query$order_by$where$filter = array(), $params = array(), $show_deleted 0$join_type 'inner'$return_array false$parentbean$singleSelect false)
          {
           
    $ret_array parent::create_new_list_query($order_by$where,$filter,$params$show_deleted,$join_type$return_array,$parentbean$singleSelect);
            
    $ret_array['select'] .= ' ,phone_mobile as phone_mobilel ';
            
    $ret_array['from'] = ' inner join Contacts Contacts.id=imob_cerere.contact_id_c ';
            
    $ret_array['where'] .= " AND Contacts.phone_mobile like '"$_POST['phone_mobile'] ."%' "//line 15
            
    $ret_array['order_by'] .= ' ';
                          
            return 
    $ret_array;
        }
       }
    ?>
    The problem is $_POST['phone_mobile'] ...how can I write?

    Thank you.

  9. #9
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: where is db query from base modules?

    That means it's not being passed. Are you entering the mobile phone #? If so, try the $_REQUEST var instead.

    Here's an alternate implementation:
    PHP Code:
    <?php
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    require_once(
    'modules/imob_Cerere/imob_Cerere.php');
    class 
    imob_CerereListView extends imob_Cerere {
        function 
    imob_CerereListView(){
        
    parent::imob_Cerere();
        }
    function 
    create_new_list_query$order_by$where$filter = array(), $params = array(), $show_deleted 0$join_type 'inner'$return_array false$parentbean$singleSelect false)
          {
           
    $ret_array parent::create_new_list_query($order_by$where,$filter,$params$show_deleted,$join_type$return_array,$parentbean$singleSelect);
            
    $ret_array['select'] .= ' ,phone_mobile as phone_mobilel ';
            
    $ret_array['from'] = ' inner join Contacts Contacts.id=imob_cerere.contact_id_c ';
            if(!empty(
    $_REQUEST['phone_mobile'] )) $ret_array['where'] .= " AND Contacts.phone_mobile like '"$_REQUEST['phone_mobile'] ."%' "//line 15
            
    $ret_array['order_by'] .= ' ';
                          
            return 
    $ret_array;
        }
       }
    ?>

  10. #10
    mel0 is offline Junior Member
    Join Date
    Dec 2009
    Posts
    4

    Default Re: where is db query from base modules?

    Hi eggsurplus,

    thx for your quick reply. I'im testing this and nothitg, we have another solution? I need search phone_mobile but this is in Contacts module.

    Thank you.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Code base for core modules
    By salesagility in forum General Discussion
    Replies: 6
    Last Post: 2008-11-24, 12:38 AM
  2. where to write query for module builder modules..?
    By maniram2202 in forum Developer Help
    Replies: 2
    Last Post: 2008-09-18, 01:10 PM
  3. Remove/disable search form in modules
    By swalk in forum Help
    Replies: 2
    Last Post: 2008-05-24, 04:36 AM
  4. Modules, file's and data driven form fields
    By Jimbobway in forum Developer Help
    Replies: 0
    Last Post: 2008-01-11, 06:46 PM
  5. Replies: 2
    Last Post: 2006-10-20, 12:00 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •