We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34162
    • 1 Posts
    I just wanted to be notified as soon as I get a new comment. But since I didn’t have web users activated there was no chance for me to get notified.

    So I changed Jot slightly. Here is how I changed "doNotifyModerators":

    // Moderator Notification
    	function doNotifyModerators($commentid=0) {
    		global $modx;
    		if ($this->config["moderation"]["notify"]) {
    
    		  // Get comment fields
    			$cObj = $this->provider;
    			$cObj->Comment($commentid);
    			$comment = $cObj->getFields();
    			unset($cObj);
    					
    			$moderators = $this->getMembersOfWebGroup($this->config["permissions"]["moderate"]);
    			foreach ($moderators as $moderator){
    				$user = $modx->getWebUserInfo($moderator);
    				$tpl = new CChunkie($this->templates["notifymoderator"]);
    				$tpl->AddVar('jot',$this->config);
    				$tpl->AddVar('comment',$comment);
    				$tpl->AddVar('siteurl',"http://".$_SERVER["SERVER_NAME"]);
    				$tpl->AddVar('recipient',$user);
    				$message = $tpl->Render();
    				mail($user["email"], $this->config["subject"]["moderate"], $message, "From: ".$modx->config['emailsender']."\r\n"."X-Mailer: Content Manager - PHP/".phpversion());
    			}
    			if(sizeof($moderators) == 0) {
    				$adminRole = $this->getAdministratorRole();
    
    				if($adminRole == -1) {
    					return;
    				}
    				
    				$managers = $this->getManagerUsers();
    				foreach ($managers as $manager){
    					$user = $modx->getUserInfo($manager);
    					if($user["role"] != $adminRole) {
    						continue;
    					}
    					$tpl = new CChunkie($this->templates["notifymoderator"]);
    					$tpl->AddVar('jot',$this->config);
    					$tpl->AddVar('comment',$comment);
    					$tpl->AddVar('siteurl',"http://".$_SERVER["SERVER_NAME"]);
    					$tpl->AddVar('recipient',$user);
    					$message = $tpl->Render();
    					mail($user["email"], $this->config["subject"]["moderate"], $message, "From: ".$modx->config['emailsender']."\r\n"."X-Mailer: Content Manager - PHP/".phpversion());
    				}
    			}
    		}
    	}


    OK, there could be some refactoring wink

    And here are the two new methods I’m using:

    // Returns an array containing manager users
    	function getManagerUsers() {
    		global $modx;
    		$usrIDs = array();
    		$usrRows = $modx->db->select("id", $modx->getFullTableName("manager_users"));
    		
    		$users = array();
    		while ($usrRow = $modx->db->getRow($usrRows)) {
    			$users[] = $usrRow['id'];
    		}
    			
    		return $users;
    	}
    	
    	//Returns ID of the Administrator role
    	function getAdministratorRole() {
    		global $modx;
    		$usrRoles = $modx->db->select("id,name", $modx->getFullTableName("user_roles"));
    		while ($usrRole = $modx->db->getRow($usrRoles)) {
    			if($usrRole['name'] == "Administrator") {
    				return intval($usrRole['id']);
    			}
    		}
    		
    		return -1;
    	}


    I think this modification is also useful in that case that you enabled notifications, but the given web groups couldn’t be found.
      • 26178
      • 32 Posts
      Well done! Thanks. Just what I need wink
        • 34162
        • 1 Posts
        Quote from: sara at Jan 12, 2008, 10:55 PM

        Well done! Thanks. Just what I need wink

        That’s what makes it worth to spend time in developing. Somewhere is someone who needs something you’ve done.

        Thanks ...
          • 16430
          • 217 Posts
          Good work, but I always get only notification to administrator email. Is it possible to modify the code to send notification to multiple emails (accounts)??