We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 16430
    • 217 Posts
    Hi, I am trying to list resources (like getresources) of uncommented resources created by certain user.
    After login user can create new resource and also should post comment. For that reason I need to have page showing list of resources that are not commented by the author of resource. What I manage to create is this: (which in not very optimal as you can see)


    [[!getPage?   &elementClass=`modSnippet`  &element=`getResources`  &parents=`-1`  &resources=`[[!GetUserProducts? &depth=`3` &count=`0` &parent=`2`  &commentList=`[[!QuipCount?  &type=`user` &user=`active` &listId=`1`]]`]]`  &limit=`20`  &pageVarKey=`page` &tpl=`kategorie-tpl` ]]


    QuipCount is original snippet for Quip modified to list resource ID instead of number of resource, posted by logged user.
    GetUserProducts returns list of IDs from parent 2 created by logged user and exclude those in commentList.
    Getpage is only for creating template for resources....

    GetUserProducts snippet:

    <?php
    /*
    * $parent - where to look
    * $depth - how deep
    * $commentList - list of comment by logged user
    */
    
    
    $ids = $modx->getChildIds($parent,$depth,array('context' => 'web'));
    $c = $modx->newQuery('modResource');
    $c->leftJoin('modUser','Author','modResource.createdby = Author.id');
    $user = $modx->user->get('id');
    $commentList = explode(",",$commentList); 
    $c->where(array(
        'id:IN' => $ids,
        'id:NOT IN' => $commentList,
        'isfolder' => '0',
        'published' => 1,
        'deleted' => 0,
        'Author.id' => $user,
    
    ));
    
    if ($count) {
      return $modx->getCount('modResource',$c); //return only count
      }
    $docs = $modx->getCollection('modResource',$c);
    foreach ($docs as $doc) {
        $output .= $doc->get('id') . ',';   
    }
    return substr($output, 0, -1) ; //remove last comma
    
    


    Problem is that I dont know how to combine all snippets together and make it optimized....

    This question has been answered by kudykam. See the first response.

      • 4172
      • 5,888 Posts
      what about a counter-TV, which updates on each comment-add/remove.
      Than its easy to filter/sort by comment-counts
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 16430
        • 217 Posts
        Do you mean each time the author add comment to his resource snippet would save id of this resource to his profile?
        So except using quipcount snippet I would just get ids form extended fields....
        Do you think this would speed things up?
        • discuss.answer
          • 16430
          • 217 Posts
          Problem solved this way:
          I have extended field for each user with id of each commented page...
          So I modified GetUserProducts snippet to just deduct these resources from final output...
          <?php
          /*
          * $parent - where to look
          * $depth - how deep
          * $count - 1- return number, 0-return list of id
          */
          
          
          $user = $modx->user->get('id');
          if (empty($user)) return "Not logged in!";
          $ids = $modx->getChildIds($parent,$depth,array('context' => 'web'));
          $c = $modx->newQuery('modResource');
          $c->leftJoin('modUser','Author','modResource.createdby = Author.id');
          
          $profile = $modx->user->getOne('Profile');
          $fields = $profile->get('extended');
          $commentList = explode(",",$fields['Quip']); // get id of all commented resources
          $c->where(array(
              'id:IN' => $ids,  
              'id:NOT IN' => $commentList, 
              'isfolder' => '0',
          	'published' => 1,
              'deleted' => 0,
              'Author.id' => $user,
          
          ));
          
          if ($count) {
            return $modx->getCount('modResource',$c); 
          
            }
          $docs = $modx->getCollection('modResource',$c);
          
          
          foreach ($docs as $doc) {
              $output .= $doc->get('id') . ',';  
          
          }
          return substr($output, 0, -1) ;