We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18373 ☆ A M B ☆
    • 3,141 Posts
    I want to give comments made by Moderators (manager users, &canmoderate) a different css class. By default comments are given jot-row or jot-row-alt. Also, if you (the one viewing) made a comment it’s been given jot-row-me, and if the comment was made by the same user that created the page/news item it gets the class jot-row-author.

    I’ve been sniffing about in the jot.class.inc file on where to add that, and found this function:

    // Templating
    	function getChunkRowClass($count,$userid) {
    		$rowstyle = ($count%2) ? "jot-row-alt" : "";
    		if ( $this->config["user"]["id"] == $userid && ($userid != 0)) {
    			$rowstyle .= " jot-row-me";
    		} elseif ( $this->config["authorid"] == $userid && ($userid != 0) ) {
    			$rowstyle .= " jot-row-author";
    		} 
    		return $rowstyle;
    	}


    So now I want it to set $rowstyle to jot-row-mod... but I’m still new at the whole PHP thing, and I can’t think of how to add the elseif for it... I’m pretty sure I’ll also have to add a new line for jot-row-mod in this part of the run function:
    		// CSS Settings (basic)
    		$this->config["css"]["include"] = !is_null($this->Get("css")) ? intval($this->Get("css")) : 1;
    		$this->config["css"]["file"] = !is_null($this->Get("cssFile")) ? $this->Get("cssFile") : "assets/snippets/jot/templates/jot.css";
    		$this->config["css"]["rowalt"] = !is_null($this->Get("cssRowAlt")) ? $this->Get("cssAltRow") : "jot-row-alt";
    		$this->config["css"]["rowme"] = !is_null($this->Get("cssRowMe")) ? $this->Get("cssRowMe") : "jot-row-me";
    		$this->config["css"]["rowauthor"] = !is_null($this->Get("cssRowAuthor")) ? $this->Get("cssRowAuthor") : "jot-row-author";

    My guess would be adding the following would settle that part:
    $this->config["css"]["rowmod"] = !is_null($this->Get("cssRowMod")) ? $this->Get("cssRowMod") : "jot-row-mod";

    (Even I can copy/paste and edit a few references shocked)


    I found this in the Run function also:
    		$this->config["permissions"]["moderate"] = !is_null($this->Get("canmoderate")) ? explode(",",$this->Get("canmoderate")):array();

    so my thought was I could use that for the elseif to determine if someone’s a moderator, yes or no.

    I’d need to find if the users name exists in the groups that can moderate.... Found another function that reads the names/ids of a group:
    	function getMembersOfWebGroup($groupNames=array()) {
    		global $modx;
    		$usrIDs = array();
    		$tbl = $modx->getFullTableName("webgroup_names");
    		$tbl2 = $modx->getFullTableName("web_groups");
    		$sql = "SELECT distinct wg.webuser
    						FROM $tbl wgn
    						INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wgn.name IN ('" . implode("','",$groupNames) . "')";
    		$usrRows = $modx->db->getColumn("webuser", $sql);
    		foreach ($usrRows as $k => $v) $usrIDs[] = intval($v);
    		return $usrIDs;
    	}	


    So this is what I came up with to be added in the first code I quoted in this post:
    <....>
    $modsareinhere = $this->getMembersOfWebGroup($this->Get("canmoderate"));
    elseif (strpos($modsareinhere,$userid) && ($userid != 0)) { 
    $rowstyle .= " jot-row-mod";
    }
    <...>



    Can you help me get this right? I admit I didn’t test this yet... but with my knowledge of PHP I doubt I can get it right in one go anyway ^_^
    Any general or specific feedback is much appreciated!
      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • 4172
      • 5,888 Posts
      I think there is no need to hack jot for this.
      All Information you need you can get with the placeholders
      [+jot.permissions.moderate.0+] and [+comment.createdby+] in the comment-template.
      you can put this Infos to a snippet or PHx-modifier which returns then the class jot-row-mod if the user [+comment.createdby+] is in the usergroup: [+jot.permissions.moderate.0+].
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 18373 ☆ A M B ☆
        • 3,141 Posts
        Could you show how that’d work?


        Markiee
          Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

          Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
          • 4172
          • 5,888 Posts
          Ok, you can try this one:
          create a new snippet,
          name it for example ’isMemberOfWebgroup’
          <?php
          $groupNames=(isset($groupNames))?explode(',',$groupNames):array();
          //print_r($groupNames);
          		$usrID=$usrID*(-1);
          		$class='';
          		$usrIDs = array();
          		$tbl = $modx->getFullTableName("webgroup_names");
          		$tbl2 = $modx->getFullTableName("web_groups");
          		$sql = "SELECT distinct wg.webuser
          						FROM $tbl wgn
          						INNER JOIN $tbl2 wg ON wg.webgroup=wgn.id AND wgn.name IN ('" . implode("','",$groupNames) . "')";
          		$usrRows = $modx->db->getColumn("webuser", $sql);
                         //print_r($usrRows);
          		foreach ($usrRows as $k => $v) $usrIDs[] = intval($v);
          		if (in_array($usrID,$usrIDs)){
          			$class='jot-row-mod';
          		}
          		
          		return $class;
          ?>


          in your comment chunk call it like this:

          [[isMemberOfWebgroup? &groupNames=`moderatoren,editoren` &usrID=`[+comment.createdby+]`]]

          or
          [[isMemberOfWebgroup? &groupNames=`[+jot.permissions.moderate.0+],[+jot.permissions.moderate.1+]` &usrID=`[+comment.createdby+]`]] 


          hope it will work

          Bruno
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 33992 ☆ A M B ☆
            • 455 Posts
            You can use PHx instead hacking codes

            <div class="[+comment.createdby:lt=`0`:then=`moderatorsClass`:gt=`0`:then=`managerClass`:else=`rowClass`+]">
                  each comment tpl
            </div>


            you can also specify author of current document by PHx.
              God loves me. 【ツ】


              MODX.ir (Persian Support)

              Boplo.ir/modx/ (Persian)
              • 33992 ☆ A M B ☆
              • 455 Posts
              If current user is moderator of current snippet call, $Jot->config[’moderation’][’enabled’] will be 1
              So you can recognize moderators of current Jot call and extend previous PHx i told:

              <div ... class=" ... [+jot.moderation.enabled:is=`1`:then=`moderatorsClass`:else=`
                       [+comment.createdby:lt=`0`:then=`webUsersClass`:gt=`0`:then=`managerClass`:else=`rowClass`+]
              `+] ... " ... >
                    each comment tpl
              </div>
                God loves me. 【ツ】


                MODX.ir (Persian Support)

                Boplo.ir/modx/ (Persian)