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
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.