We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50593
    • 19 Posts
    in your nested grid, do you have StaffMemberCategories or StaffCategory as the classname?

    If I understand your question right, currently I'm using staff_categories grid and StaffCategroy class.

    you also should have

    "use_as_fallback":"1",

    Yes. That did the trick. Now I see checkboxes, though I can't turn them on. May be, that's because my I haven't written the processor yet.

    what is your getlist.php - code currently?

    I can see many 'getlist.php' files in my MODX directory. Which of them do you need? (Sorry, for the silly answer but I'm very new to MODX). [ed. note: marshwiggle last edited this post 11 years, 4 months ago.]
      • 4172
      • 5,888 Posts
      I was talking about this one

      core/components/{packagename}/processors/mgr/{processorspath}/getlist.php

      but seems you aren't that far and you haven't created your customized processors yet.

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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 50593
        • 19 Posts
        No, not yet. I'm trying to grasp this: https://github.com/Bruno17/migxResourceCategories/blob/master/core/components/migxresourcecategories/processors/mgr/default/handlecolumnswitch.php

        It's not clear for me, where do you take object_id from? There is no such field in your schema... And why do I need getlist.php at all? Now I can see my staff_categories as a nested grid, so isn't it enough just to write handlecolumnswitch.php?

        Should getlist.php return the content of the staff_categories grid?

        Addendum. I've studied getlist.php of several MODX extras. It seems, they just return the classname of the DB to load, while your getlist from here https://github.com/Bruno17/migxResourceCategories/blob/master/core/components/migxresourcecategories/processors/mgr/resourcecategories/getlist.php is rather complicated. In our example we have 3 tables, so what should we do: to make 3 copies of getlist or return classname using conditional statement? [ed. note: marshwiggle last edited this post 11 years, 4 months ago.]
          • 4172
          • 5,888 Posts
          usually, you don't need any custom-processor in a MIGXdb - CMP and everything, what you need, is done within the default MIGX - getlist-processor.

          But in this case, you need to have a way to add the joined field with a value of 1 or 0, if there is a connected item in the join-table.

          This is what I add in the lines 167 - 193 https://github.com/Bruno17/migxResourceCategories/blob/master/core/components/migxresourcecategories/processors/mgr/resourcecategories/getlist.php#L167

          There is also a possible way without a custom processor but with a join and an additional getlist-where.

          I was to lazy to think about the join, so I just did a copy of the default processor and added this lines.





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

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 50593
            • 19 Posts
            This is what I add in the lines 167 - 193

            So I have to change these lines with the following, right?

            $staffCategories = array();
            $c2 = $modx->newQuery('StaffMemberCategories');
            $c2->where(array('staff_id'=>$resource_id));
            if ($staffCategoryCollection = $modx->getCollection('StaffMemberCategories',$c2)){
                foreach ($staffCategoryCollection as $staffCategoryObject){
                    $staffCategories[] = $staffCategoryObject->get('category_id');
                }
            }
            //print_r($resCategories);
            //$c->sortby($sort,$dir);
            //$c->prepare();echo $c->toSql();
            $rows = array();
            if ($collection = $xpdo->getCollection($classname, $c)) {
                $pk = $xpdo->getPK($classname);
                foreach ($collection as $object) {
                    $row = $object->toArray();
                    $row['id'] = !isset($row['id']) ? $row[$pk] : $row['id'];
                    $row['joined'] = in_array($row['id'],$staffCategories) ? '1' : '0';
                    $rows[] = $row;
                }
            }
            


            I was talking about this one

            core/components/{packagename}/processors/mgr/{processorspath}/getlist.php

            What {processorspath} should I use? staffmembercategories? staffcategory? staffmember? [ed. note: marshwiggle last edited this post 11 years, 4 months ago.]
              • 4172
              • 5,888 Posts
              your code is looking good to me.

              the name of the processorspath is up to you.
              I would give it the same name like your MIGX-config.
              Don't forget to fill the field 'processorspath' in the MIGX - config with that folder-name.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 50593
                • 19 Posts
                Yes! It's working! Hooraay!

                Thank you, thank you, thank you!!!

                What now? This is my handlecolumnswitch.php:

                <?php
                $config = $modx->migx->customconfigs;
                $prefix = $modx->getOption('prefix', $config, null);
                $packageName = $config['packageName'];
                $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
                $modelpath = $packagepath . 'model/';
                $modx->addPackage($packageName, $modelpath, $prefix);
                $classname = $config['classname'];
                $joinclass = 'StaffMemberCategories';
                $resource_id = $modx->getOption('resource_id', $scriptProperties, 0);
                $object_id = $modx->getOption('object_id', $scriptProperties, 0);
                
                switch ($scriptProperties['idx']) {
                    case '1':
                        $joinobject = $modx->newObject($joinclass);
                        $joinobject->set('staff_id', $resource_id);
                        $joinobject->set('category_id', $object_id);
                        $joinobject->save();
                        break;
                    case '0':
                        if ($joinobject = $modx->getObject($joinclass, array('staff_id' => $resource_id, 'category_id' => $object_id))) {
                            $joinobject->remove();
                            
                        }
                        break;
                    default:
                        break;
                }
                
                return $modx->error->success()


                There is a bug in it, so it doesn't work for the moment.

                [ed. note: marshwiggle last edited this post 11 years, 4 months ago.]
                  • 4172
                  • 5,888 Posts
                  yes, change the joinclass and if you do not need that position-handling, remove that stuff.
                  And change all 'resource_id' to 'staff_id'

                  and

                  $resource_id = $modx->getOption('resource_id', $scriptProperties, 0);


                  to

                  $staff_id = $modx->getOption('co_id', $scriptProperties, 0);


                  co_id is the id of the parent-object, in this case the StaffMember
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 50593
                    • 19 Posts
                    Still doesn't work:

                    <?php
                    $config = $modx->migx->customconfigs;
                    $prefix = $modx->getOption('prefix', $config, null);
                    $packageName = $config['packageName'];
                    $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
                    $modelpath = $packagepath . 'model/';
                    $modx->addPackage($packageName, $modelpath, $prefix);
                    $classname = $config['classname'];
                    $joinclass = 'StaffMemberCategories';
                    $staff_id = $modx->getOption('co_id', $scriptProperties, 0);
                    $object_id = $modx->getOption('object_id', $scriptProperties, 0);
                    
                    switch ($scriptProperties['idx']) {
                        case '1':
                            $joinobject = $modx->newObject($joinclass);
                            $joinobject->set('staff_id', $staff_id);
                            $joinobject->set('category_id', $object_id);
                            $joinobject->save();
                            break;
                        case '0':
                            if ($joinobject = $modx->getObject($joinclass, array('staff_id' => $staff_id, 'category_id' => $object_id))) {
                                $joinobject->remove();
                                
                            }
                            break;
                        default:
                            break;
                    }
                    
                    return $modx->error->success()
                      • 4172
                      • 5,888 Posts
                      what is your whole configuration for that nested grid now?
                      Can you post an export of it?

                      And in which folder did you create that file?

                      You should also check, if the object doesn't exist, before adding a new one:

                      switch ($scriptProperties['idx']) {
                          case '1':
                              if ($joinobject = $modx->getObject($joinclass, array('staff_id' => $staff_id, 'category_id' => $object_id))) {
                                  //do nothing in that case
                              } else {
                                  $joinobject = $modx->newObject($joinclass);
                                  $joinobject->set('staff_id', $staff_id);
                                  $joinobject->set('category_id', $object_id);
                                  $joinobject->save();
                              }
                              break;
                          case '0':
                              if ($joinobject = $modx->getObject($joinclass, array('staff_id' => $staff_id, 'category_id' => $object_id))) {
                                  $joinobject->remove();
                              }
                              break;
                          default:
                              break;
                      }
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!