We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43302
    • 18 Posts
    I'm having a weird issue with my CMP. I have a grid of events, that returns shows information about different events and also a count of how many attendees each event has registered. Therein lies the problem.

    I have several classes and the attendee data differs between event types. For this I specify a controller, to load the appropriate attendee class depending on event type. The schema for these looks as follows:

    <object class="harbourEventAttendee" table="harbour_attendees_event" extends="xPDOSimpleObject">
            <field key="userid" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true"/>
            <field key="eventid" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false"/>
            <field key="boatid" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true"/>
            <field key="additional" dbtype="text" phptype="string" null="true"/>
    
            <index alias="userid" name="userid" primary="false" unique="false" type="BTREE">
                <column key="userid" collation="A" null="false"/>
            </index>
            <index alias="eventid" name="eventid" primary="false" unique="false" type="BTREE">
                <column key="eventid" collation="A" null="false"/>
            </index>
    
            <aggregate alias="Account" class="harbourAccount" local="userid" foreign="id" cardinality="one" owner="foreign"/>
            <aggregate alias="Event" class="harbourEvent" local="eventid" foreign="id" cardinality="one" owner="foreign"/>
            <aggregate alias="Boat" class="harbourBoat" local="boatid" foreign="id" cardinality="one" owner="foreign"/>
        </object>
    
        <object class="harbourContestAttendee" table="harbour_attendees_contest" extends="harbourEventAttendee">
            <field key="spinnaker" dbtype="tinyint" precision="1" phptype="boolean" null="false" default="0"/>
            <field key="skipper_name" dbtype="varchar" precision="50" phptype="string" null="false"/>
            <field key="skipper_phone" dbtype="varchar" precision="24" phptype="string" null="false"/>
            <field key="skipper_email" dbtype="varchar" precision="50" phptype="string" null="false"/>
            <field key="deckhands" dbtype="text" phptype="string" null="true"/>
        </object>
    
        <object class="harbourCourseAttendee" table="harbour_attendees_course" extends="harbourEventAttendee">
            <field key="fullname" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            <field key="email" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            <field key="phone" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            <field key="address" dbtype="text" phptype="string" null="false" default="" />
            <field key="zip" dbtype="varchar" precision="25" phptype="string" null="false" default="" />
            <field key="city" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
            <field key="country" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
            <field key="birthdate" dbtype="date" phptype="datetime" null="true"/>
            <field key="guardian_name" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
            <field key="guardian_phone" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
            <field key="guardian_email" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
        </object>


    As you can see there's one main class that stores generic data, and specialized classes for the extra data. These work perfectly everywhere else, except to count the attendees in my events grid.

    In the getList processor I run this to get the attendee count:
    public function prepareRow(xPDOObject $object) {
            $controller = $object->get('controller');
            $attendeeClass = 'harbour'.ucfirst($controller).'Attendee';
            $attendeeCount = $this->modx->getCount($attendeeClass,array(
                'eventid' => $object->get('id')
            ));
    
            $eventArray = $object->toArray();
            $eventArray['attendees'] = $attendeeCount;
            return $eventArray;
        }


    Now here's where it gets even weirder: This works perfectly fine when a filter is used to only return events of one type. When returning all types it counts attendees correctly for all classes that extend harbourEventAttendee, except for the main class itself. When it tried to do this I get the following in the error log:

    [2014-05-07 13:11:52] (ERROR @ /assets/components/harbour/connector.php) harbourEventAttendee::getSelectColumns() is not a valid static method.


    And the getCount returns 0.

    I've tried using loadClass before the getCount to load it explicitly beforehand, but this makes no difference. harbourEventAttendee extends xPDOSimpleObject. Why can harbourEventAttendee not use getSelectColumns in getCount, while the classes that extend it can??

    Any help is appreciated, I'm completely lost on this issue!
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      has this been resolved, yet?
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 3749
        • 24,544 Posts
        IIRC, I had a similar problem that I solved by doing something like this before calling getCount():

        $c = $modx->newQuery('className');
        $c->where(array('eventid' => $object->get->'id'));
        $c->prepare();
        


        Calling prepare() was the key.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 43302
          • 18 Posts
          I completely forgot about this post. The issue has been resolved, sadly I don't know what did it. Between my mucking around in the code and testing, I must have solved it somehow. For a while it was working only on my dev platform, and even though I had copied all the files to the production server as well, it didn't want to work there. Upon properly updating the package on the production server however, it started working, so I'm guessing it must've been some schema change I had done that caused it.