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

    while I was coding today I stumbled upon something I don’t really understand. I wanted to use getMany and filter for all the non-deleted photos. But it doesn’t work!
    <?php
    data($photo->getMany('Childs', array('deleted' => false)), $data);


    I’ve developed this workaround which does exactly the same but it’s not as sleek as the code above. But it DOES work.

    <?php
    $c = $modx->newQuery('ggPhoto');  
    $c->where(array(
        'parent' => $photo->get('id'),
        'deleted' => false,
    ));
    data($modx->getCollection('ggPhoto', $c), $data);


    Why can’t I apply a criteria to getMany? Am I doing something wrong?

    Whole Code:
    <?php
    if (!$modx->hasPermission('edit_document')) return $modx->error->failure($modx->lexicon('access_denied'));
    
    include_once ($modx->getOption('core_path') . "components/gallerygear/gallerygear.class.php");
    $gg = new GalleryGear();
    
    function data($photos, & $data = array('count' => 0, 'photos' => array())) {
        global $modx;
        foreach($photos as $photo) {
            $data['photos'][] = array(
                'name' => $photo->get('name'),
                'previewImgUrl' => $photo->setResizedPhoto('crop', 80, 80)->getWebUrl()
            );
            $data['count']++;
            
            $c = $modx->newQuery('ggPhoto');  
            $c->where(array(
                'parent' => $photo->get('id'),
                'deleted' => false,
            ));
            data($modx->getCollection('ggPhoto', $c), $data);
            
            data($photo->getMany('Childs', array('deleted' => false)), $data);
        }
        return $data;
    }
    
    return $modx->error->success('yes', data($modx->getCollection('ggPhoto', array('deleted' => true))));



    JB