We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37286
    • 160 Posts
    Something that would be nice to have would be a method to use getCollectionGraph to grab a collection using the modObjectGetListProcessor. I have to add a getData function to my getlist to add one line to use the getCollectionGraph. See example below:
        public function getData() {
            $data = array();
            $limit = intval($this->getProperty('limit'));
            $start = intval($this->getProperty('start'));
    
            /* query for chunks */
            $c = $this->modx->newQuery($this->classKey);
            $c = $this->prepareQueryBeforeCount($c);
            $data['total'] = $this->modx->getCount($this->classKey,$c);
            $c = $this->prepareQueryAfterCount($c);
    
            $sortClassKey = $this->getSortClassKey();
            $sortKey = $this->modx->getSelectColumns($sortClassKey,$this->getProperty('sortAlias',$sortClassKey),'',array($this->getProperty('sort')));
            if (empty($sortKey)) $sortKey = $this->getProperty('sort');
            $c->sortby($sortKey,$this->getProperty('dir'));
            if ($limit > 0) {
                $c->limit($limit,$start);
            }
            
            //$data['results'] = $this->modx->getCollection($this->classKey,$c);
            // modified this line from original modprocessor in my addon so I can use the getCollectionGraph
            $data['results'] = $this->modx->getCollectionGraph($this->classKey, '{ "firstTable":{}, "secondTable":{ "subTable":{} } }',$c);
            return $data;
        }
    


    Which works great, but it would just be nice to have something in the getData function in the core that said something like:
            if($this->collectionGraph > ''){
                    $data['results'] = $this->modx->getCollectionGraph($this->classKey,$this->collectionGraph,$c);
            }else{
                    $data['results'] = $this->modx->getCollection($this->classKey,$c);
            }
            return $data;
    


    Where in the custom addon we can call the collection graph by just supplying the string we wish to use:
    class customGetListProcessor extends modObjectGetListProcessor {
        public $classKey = 'primaryTable';
        public $collectionGraph =  '{ "firstTable":{}, "secondTable":{ "subTable":{} } }';
        ....
    


    And then we can modify the row data with the prepareRow function already available to display the data in the grid:
        public function prepareRow(xPDOObject $object) {
            $ta = $object->toArray('', false, true, true);
            $ta['updated'] = $object->secondTable->subTable->updated;
            $ta['logged_date'] = $object->firstTable->logged_date;
            $ta['item_title'] = $object->secondTable->item_title;
            return $ta;
        }
    


    While I'm sure this isn't something that would be used often, it sure would be nice to have for a summation screen before delving into the data maintenance in the manager.
      • 4172
      • 5,888 Posts
      MIGXdb does stuff like this nearly automatically.

      In the MIGXdb - configuration (for MIGXdb-TVs or MIGXdb-CMPs) you need just to add into the joins-field something like that:

      [{"alias":"secondClass"},{"alias":"ThirdClass"}]


      and you are ready to use this fields in the MIGX-columns-configuration:
      secondClass_item_title, ThirdClass_updated


      they are also availiable automatically in the MIGXdb - update - window

      if you haven't defined a relation in your schema, its also possible to add classname, on, selectfields to the joins - json:

      [{"alias":"Resource","classname":"modResource","on":"Resource.id=myClass.resource_id","selectfields":"pagetitle"}]




        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 37286
        • 160 Posts
        I will have to look into that for quick stand-alone projects. I was sort of thinking this core change would be nice for contributors to modx. For example, I already require several additional extras for my sekusergalleries and I hate to keep adding more prerequisites just to use usergalleries.

        Thanks for the info.