We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 30585
    • 833 Posts
    Hi guys,

    I've created a custom package via MIGXdb, attached a schema, parsed it and produced the corresponding database table. I'm trying to search the table with AdvSearch using custom query hooks, but I'm out of luck.

    The search isn't finding any results.

    I've named my package: bibleverses

    My schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="bibleverses" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    	<object class="bibleVerse" table="bible_verses" extends="xPDOSimpleObject">
    		<field key="book_id" dbtype="char" precision="3" phptype="integer" null="false" default="0"/>
    		<field key="resource_id" dbtype="char" precision="11" phptype="integer" null="false" default="0"/>
    		<field key="chapter" dbtype="mediumint" precision="3" phptype="integer" null="false" default="0"/>
    		<field key="verse" dbtype="mediumint" precision="3" phptype="integer" null="false" default="0"/>
    		<field key="lsg" dbtype="text" phptype="string" null="false" default="None"/>
    		<field key="darby" dbtype="text" phptype="string" null="false" default="None"/>
    		<field key="ostervald" dbtype="text" phptype="string" null="false" default="None"/>
    		<field key="martin" dbtype="text" phptype="string" null="false" default="None"/>	
    		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                    <column key="id" collation="A" null="false" />
            </index>		
    		<field key="is_promesse" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>		
            <aggregate alias="Resource" class="modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="Book" class="bibleBook" local="book_id" foreign="id" cardinality="one" owner="foreign" />        
    	</object>
    </model>
    


    i have a database table with the fields in the schema above.

    Here's my AdvSearch query hook:

    /**
     * AdvSearch
     *
     * Copyright 2012 by Coroico <[email protected]>
     *
     * Query hook for the Dvd shop demo 1
     *
     */
    
    /*
      Main class:
    
        package - The name of the schema Package to add. e.g: dvd
        packagePath - The path to the model/ directory where the package is located. Use {core_path} as generic variable.
        class - The class name of the table you want to search. e.g: dvd
    
    	and optionally (these parameters could be passed thru the snippet call):
    
        withFields - A comma-separated list of column names where to search.
    	fields - A comma-separated list of column names to display. 
    	ids - A comma-separated list of primary keys to filter where the search should occurs.
        where - criteria or Array of criteria. e.g: "studio IN ('20th Century Fox','DreamWorks Home Ent.','Warner Bros') "
    	sortby - csv list of couple 'columnName (ASC| DESC)'.
    */
    
    
    $main = array(
        'package' => 'bibleverses',
        'packagePath' => '{core_path}components/bibleverses/model/',
        'class' => 'bibleVerse',
        'ids' => 'id', 
        'fields' => 'book_id , chapter , verse , lsg', // displayed
        'withFields' => 'book_id , chapter , verse , lsg', // where we do the search
        'joinCriteria' => 'modx_bible_books.id = modx_bible_verses.book_id',
    	'sortby' => 'modx_bible_verses.book_id ASC, modx_bible_verses.chapter ASC, modx_bible_verses.verse ASC',
        'tablePrefix' => 'modx_'
    );
    
    
    // set the query hook declaration
    $qhDeclaration = array(
        'qhVersion' => '1.2',       // version of queryHook - to manage futures changes
    	'main' => $main,
        ‘joined’ => $joined
    );
    
    $hook->setQueryHook($qhDeclaration);
    
    return true;


    Finally my search call:

    [[!AdvSearchForm? &landing=`[[*id]]` &tpl=`AdvSearchForm`]]
    
    <h2>Results</h2>
    [[!AdvSearch? &queryHook=`bibleQHook` &tpl=`BibleSearchResult` &showExtract=`1:lsg`]]


    i Know the package was well set up because I can retrieve data with migxLoopCollection. But the search won't cooperate.

    I've already spent 3 hours on this. Please help!

    This question has been answered by treigh. See the first response.

    [ed. note: treigh last edited this post 10 years, 2 months ago.]
      A MODx Fanatic
    • Doesn't something have to join to a resource, in order to generate the search results link to a resource?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 30585
        • 833 Posts
        THanks for the follow-up Susan.

        According to the official docs, this seems to be all it takes for it to work. Maybe I'm missing something.

        Any idea how I may achieve the same thing with SimpleSearch or seomthing else if this one won't work?
          A MODx Fanatic
        • I'm pretty sure something is missing. You must have a resource for displaying the custom content normally; from what I was able to understand there would need to be a join to the resource ID which normally displays the custom content. The search results would be a link to that resource.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
          • The $joined is not set to anything above.

            I suggest you style it after: http://www.revo.wangba.fr/custom-package-dvd-shop-2/
            You can list the books, chapters, etc. in the drop down. My assumption is the field name in the form must match the database field.

            Also, your schema as presented is incomplete:
            <aggregate alias="Book" class="bibleBook" local="book_id" foreign="id" cardinality="one" owner="foreign" />  

            Points to as bibleBook table.

            I also notice you appear to be offering multiple translations:

            You might be better served with an Enum field

                   <field key="lsg" dbtype="text" phptype="string" null="false" default="None"/>
                    <field key="darby" dbtype="text" phptype="string" null="false" default="None"/>
                    <field key="ostervald" dbtype="text" phptype="string" null="false" default="None"/>
                    <field key="martin" dbtype="text" phptype="string" null="false" default="None"/>  


            May be simplified with:
            <field key="translation" dbtype="enum" precision="'lsg','darby','ostervald','martin'" phptype="string" null="false" default="lsg"
            			comment="The names of the versions which are allowed in the table" />



            A little lost on this one:
            <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true">
                            <column key="id" collation="A" null="false" />
                    </index>


            Should be causing you errors I suspect, as that index is created by the xPDOSimpleObject class upon creation - check under the reports menu.

            If this is supposed to be a boolean:
                    <field key="is_promesse" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/> 


            Try:
            		<field key="is_promesse" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="0" />


            I think rowboat may serve you better: http://rtfm.modx.com/extras/revo/rowboat/rowboat.rowboat - depends on what you are doing.

            Or something like:


            <?php
            
            $resourceObj = $modx->Resource;
            if ($resource instanceof modResource){
            
            $parentObj = $modx->Resource->Parent;
            
            if ($parentObj instanceof modResource){
            
            $bookObj = $modx->getObject('bibleBook', array('name' => $parentObj->get('pagetitle'));
            
            if ($bookObj instanceof bibleBook){
            $collection = $bookObj->getMany('Verses', array('chapter' => $resourceObj->get('pagetitle', 'translation'=> 'darby');
            
            if (count ($collection) > 0){
            
            /* create output here */
            }
            }
            }
            


            This is off my head and may contain errors. For it to work your site would have pages names after all of the books of the bible. Under them would have pages named after the chapter number.

            Genesis
                 1
                 2


            Drop my snippet in the chapter pages and it should drop the entire chapter in the page.


            This is quite rough, but should be doable. I am sorry I do not get to check these forums as often as I would like. I'm coming to the end of a project which is quite extensive
              Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

              Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
              • 30585
              • 833 Posts
              Thanks Susan and Shawn for your valu rd input.

              @Shawn, Ill definately Make thé suggestif changes. But I'm leaning towards Rowboat. I managed to get most of what I needed. I'll probably need some help with the filtering and of data. I'll post back in a bit.

              Thanks again!
                A MODx Fanatic
                • 30585
                • 833 Posts
                Shawn and Susan, thanks again for the help. I've played around with various scenarios suggested above and as it turns out, I might be better served with a combination of RowBoat, getPage and MIGx. At least with these options, I can search documents instead of database tables.

                Here are some of the few things that are making my quest for clarity a bit more interesting:

                1. The bible has 66 books
                2. The chapter count for each book varies somewhere between 3 and 150.
                3. I actually have two tables. modx_bible_books ha 3 fields :id, book, chap. My modx_bible_verses table handles all the verses and the fields are in the schema (which i've updated to reflect changes made).

                As suggested by Shawn, I'm thinking of creating 66 resources using Articles or something similar to house those 66 books. I'd use Rowboat to retrieve specific data for each book.

                Before diving into this expensive experiment, I just want to get some thoughts on whether this is an efficient way of doing it or not.

                Here's where I could really use some guidance:

                1. Will it make sense that I create those many chapters for each book page? For example: the book Psalms has 150 chapters. If I have to, I could use MIGX to create a grid of 150 chapters where each row would have a verse field, on which I would use a RowBoat call to pull the verse content from the table. I guess I'm wondering if creating those MIGX rows manually would make sense or if I could achieve it in a more automated/efficient way - say with MIGXdb? I've already created a CMP for each table and if an automation is possible, I'd like to get a few hints on how to achieve it.

                I hope this isn't very confusing and thanks already for all the great help.
                  A MODx Fanatic
                • I would use MIGXdb, as a TV attached to a single document and using resources for everything (i.e. only accessing the site_content table). MODX can easily handle that many resources. Use one template for book, one for chapter, and one for verse. That way you can easily restrict searches and listings by filtering on template, and even parent's template.

                  http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.manage-child-resources-in-a-grid-tv-with-help-of-migxdb
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 30585
                    • 833 Posts
                    Already on it. Thanks again Susan!
                      A MODx Fanatic
                      • 30585
                      • 833 Posts
                      Quote from: sottwell at Feb 24, 2014, 03:10 AM
                      I would use MIGXdb, as a TV attached to a single document and using resources for everything (i.e. only accessing the site_content table). MODX can easily handle that many resources. Use one template for book, one for chapter, and one for verse. That way you can easily restrict searches and listings by filtering on template, and even parent's template.

                      http://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.manage-child-resources-in-a-grid-tv-with-help-of-migxdb

                      Susan, one last question please.

                      Any idea how to change the template for child resources in the MIGXdb TV grid?
                      All other fields are visible and editable, except the template one. I can change the default template value from the CMP, but not when adding resources in the TV grid.

                      EDIT:

                      This is definitely a bug. I guess, I just need to use Batcher to bulk change the templates. [ed. note: treigh last edited this post 10 years, 2 months ago.]
                        A MODx Fanatic