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

    I have to list articles. Some are private documents but I want that a "public" user can see the summary even if he’s not logged. To do that I have used the &hidePrivate=`0` parameter and this chunk to display the private document in an other way :

    <div class="ditto_[+privateweb:is=`1`:then=`_private`+]">
    <h3>[+title+]</h3>
    <div class="ditto_info" >Par <strong>[+author+]</strong>, le [+date+]. <a  href="[~[+id+]~]#commentsAnchor">Commentaires
    ([!Jot?&docid=`[+id+]`&action=`count-comments`!])</a></div><div class="ditto_tags">Tags: [+tagLinks+]</div>
    [+summary+]
    [+privateweb:is=`0`:then=`<p class="ditto_link">[+link+]</p>`+]
    </div>
    


    Example here : http://v2.astroip.org/le-coin-de-la-technique.html

    That seems to work correctly. But I want to display the private documents in a "normal" way if the user is logged and has right access to the documents.

    How can I do that ?
      • 15114
      • 102 Posts
      I tried something with a snippet I wrote :

      <?php
      $id = (isset($id) ? $id : null);
      if($id == null) {
      	return 'private';
      }
      
      $tblsc = $modx->getFullTableName("site_content");
      $tbldg = $modx->getFullTableName("document_groups");
      
      if ($docgrp = $modx->getUserDocGroups()) {
      	$docgrp = implode(",", $docgrp);
      }
      
      $access= "sc.privateweb=0".(!$docgrp ? "" : " OR dg.document_group IN ($docgrp)");
      
      $sql = "SELECT sc.* FROM $tblsc sc
      		LEFT JOIN $tbldg dg ON dg.document = sc.id
      		WHERE sc.id = '" . $id . "' AND ($access) LIMIT 1;";
      
      $result = $modx->db->query($sql);
      $rowCount = $modx->recordCount($result);
      return ($rowCount < 1 ? 'private' : 'public');
      ?>
      


      and my ditto chunk

      <div class="ditto_[!AllowedToAccess? &id=[+id+] !]">
      <h3>[+title+]</h3>
      <div class="ditto_info" >Par <strong>[+author+]</strong>, le [+date+]. <a href="[~[+id+]~]#commentsAnchor">Commentaires
      ([!Jot?&docid=`[+id+]`&action=`count-comments`!])</a></div><div class="ditto_tags">Tags: [+tagLinks+]</div>
      [+summary+]
      <p class="ditto_link">[+link+]</p>
      </div>
      


      I don’t know if there is a better solution, but it works.