Results 1 to 3 of 3

Thread: custom module: related field listview/search

  1. #1
    etalley is offline Sugar Community Member
    Join Date
    Aug 2007
    Posts
    17

    Exclamation custom module: related field listview/search

    Quick Synopsis:
    I have 2 modules
    Property
    | 1:N
    ----- Image
    When viewing Image: ListVIew I want to be able to do 3 things:
    1. view the related Property Name
    2. Filter/Search by Propety Name
    3. Select images by related Property Name for post-processing.

    I have overridden the default view with view.list in the Images module.

    I put this in vardefs:
    Code:
    '**_property_property_name' => array(
        'name'         => '**_property_property_name',
        'type'         => 'relate',
        'source'       => 'non-db',
        'vname'        => 'LBL_**_IMAGE_PROPERTIES_FROM_**_PROPERTY_TITLE',
        'save' => true,
        'id_name' => '**_imag825droperty_idb',
        'link' => '**_imagepas_property_c',
        'table' => '**_property',
      	'module' => '**_Property',
     	'rname' => 'name',
      	'unified_search'  => true,
        
        ),
    Rebuild
    Symptoms:
    1. Studio shows the field but cannot modify layout (the fields pop back into the hidden list after save deploy
    2. the field is not populated, capturing the query shows that the property table has not been joined.

    Questions:
    1. Am I going about this in the right manner? In my mind its either a configuration issue in the vardef or some missing piece in the cache folder.

    Other info of note: I would be ok with just search functionality, I tried a subquery in the searchFields:
    Code:
    'property'=> array(
                            'query_type' => 'default',
    						'vname' => 'LBL_PROPERTY_SEARCH',
                            'operator' => 'subquery',
                            'subquery' => array(
                                    'OR' => 'SELECT a.id FROM **_image a JOIN **_imagepas_property_c b ON ( a.id = b.**_imagb0aes_image_ida )  JOIN **_property c ON ( b.**_imag825droperty_idb = c.id ) WHERE a.deleted =0 AND c.name LIKE',
                            ),
                            'db_field' => array(
                                    'id',
                            )
                    ),
    to no avail, Sugar doesnt pick it up. I tried custom/modules/**/metadata/SearchFields.php and modules/...
    side note:
    II don't track the state of the cache and if I feel like there are odd things happening I tend to delete the whole project and reload a fresh copy from subversion and rebuild.

    Any insight would be appreciated. I've spent 2 days on the issue with no progress.

  2. #2
    etalley is offline Sugar Community Member
    Join Date
    Aug 2007
    Posts
    17

    Default Re: custom module: related field listview/search

    After banging away for a while I was able to successfully
    A) set vardefs
    B) add the code to the SearchFields.php with the custom query
    C) populate the related field in listview by customizing the (Bean?) by overriding get_list_view_data:
    Code:
    function get_list_view_data()
    		{
    		$list_fields = $this->get_list_view_array();
    		$query = "select name from **_property a join **_imagepas_property_c b on a.id = b.**_imag825droperty_idb  where b.**_imagb0aes_image_ida='".$this->id."'";
    		$result = $this->db->query($query);
    		if ( $row = $this->db->fetchByAssoc($result) )
    		{
    		$list_fields["**_PROPERTY_PROPERTY_NAME"] = $row['name'];
    		}
    		
    		return $list_fields;
    		}
    I then ran into an issue with linking field being completely wrong. I ran a cachegrind to figure out where the query was being generated which brought me to SearchForm->generateSearchWhere() where I *think* i might have found a bug.

    the code retrieves the link element of the vardef array, and then alternatively treats it like a nested array and then a string throughout the next couple lines of code.(I am using examples found in the net that define link=> as a string not an array()). PHP silently truncates the string and it gets passed along to query (that blows my mind, even python isn't that loose).

    I have made a patch that modifies SearchForm2.php that seems to work in my case.

    Code:
    Index: include/SearchForm/SearchForm2.php
    ===================================================================
    --- include/SearchForm/SearchForm2.php	(revision 39)
    +++ include/SearchForm/SearchForm2.php	(working copy)
    @@ -611,7 +611,7 @@
    $db_field = $this->seed->field_name_map[$field]['name'];
    } else {
    	//Best Guess for table name
    	-     $db_field = strtolower($link['module']) . '.' . $db_field; // $link is a string!!!
    	+    $db_field = strtolower($module) . '.' . $db_field;
    }
    }
         else if ($type == 'parent') {
    Last edited by etalley; 2010-06-14 at 01:19 AM.

  3. #3
    etalley is offline Sugar Community Member
    Join Date
    Aug 2007
    Posts
    17

    Default Re: custom module: related field listview/search

    any insight into whether I am complete off base with the patch I posted (or any unwanted side effects) is greatly appreciated

    A side question: do professional accounts have access to better developer documentation? A lot of energy I expend seems more related to lack of thorough documentation than anything else.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Field missing from ListView (custom module)
    By Sparrowhawk in forum Help
    Replies: 2
    Last Post: 2011-06-29, 11:20 PM
  2. Can't create required related field for custom module
    By jwesley in forum General Discussion
    Replies: 1
    Last Post: 2010-06-08, 05:21 PM
  3. Replies: 3
    Last Post: 2010-05-11, 10:30 AM
  4. Replies: 1
    Last Post: 2010-04-28, 11:03 PM
  5. Related field to custom module
    By Billwobo in forum Help
    Replies: 2
    Last Post: 2008-07-03, 12:05 PM

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
  •