We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38371
    • 42 Posts
    This is a follow up question to the post "https://forums.modx.com/thread/84303/why-my-customusergetlistprocessor-retrieves-modusers-too".

    Description of Problem:
    As mentioned in the above post, we have created the class customUser which is an extension to the modUser class.

    As it turns out, the solution to the above post solves half of the problem. That is, the customUserGetListProcessor now correctly returns the "total". However, the "results" property of the response is empty.

    In other words, the customUserGetListProcessor counts the right amount of objects to be retrieved, but no object is actually retrieved.

    After some tests we have performed we have come to the conclusion that the problem lies in line 54 of the modUserGetListProcessor class. The code that causes our problem is highlighted below.

    public function prepareQueryAfterCount(xPDOQuery $c) {
        $c->select($this->modx->getSelectColumns('modUser','modUser'));
        ...
        
        return $c;
    }
    


    It is because a selection is made for the columns of the modUser class' table, that the customUsers are not returned.

    But this code is inside the modUserGetListProcessor class and, thus, it cannot (should not) be changed.

    So, our question is twofold:

    1. Is it indeed the above line to be blamed for the problem?
    2. If yes, is there a way to override its behavior, so as to avoid changing core code?

    Steps to Reproduce [1]:

    1. Add two new entries in the "users" table of the database.
    2. Set their "class_key" property to "customUser".
    3. Create a new instance of the customUserGetListProcessor class.
    4. Run the above processor (i.e., call its "run" method).
    5. Store the returned value to a variable (e.g., $response).

    Expected Outcome:
    Inside a PHPUnit test case, the assertions below should pass.
    $responseArray = $modx->fromJSON($response->response);
    
    $this->assertEquals(2, $response['total']);
    $this->assertNotEmpty($response['results']);
    


    However, only the first assertion passes [2], while the second one fails.


    • MODX Version: 2.2.7pl (Advanced)
    • PHP Version: 5.4.3
    • Database (MySQL, SQL Server, etc) Version: 5.5.24
    • Additional Server Info: Apache 2.2.22
    • Installed MODX Add-ons: None

    [1]: Of course the steps cannot be reproduced because you would need the customUser class. But the example of the section serves to make things clear as to what the problem is.

    [2]: This is the problem discussed in the post mentioned in the beginning of this post. [ed. note: leffyrant last edited this post 13 years, 5 months ago.]
      • 3749
      • 24,544 Posts
      getList processors typically return a JSON array, which it looks like you're not doing.

      You also have to create a PHP array containing the data fields, either with $object->toArray() or manually by using something like this:

      $fields['something'] = $object->get('fieldNAme');


      Here's code from a dummy getList processor I use in the Orphans extra (the second argument is the number of records):

      $fields = array(
          'id' => '',
          'name' => '',
          'category' => '',
          'description' => '',
      );
      
      /* @var $this modProcessor */
      return $this->outputArray($fields, count($fields));


        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