Exemplo n.º 1
0
 function informUsersForState($oState, $aInformed, $oDocument, $oUser, $sComments)
 {
     // say no to duplicates.
     KTWorkflowNotification::clearNotificationsForDocument($oDocument);
     $aUsers = array();
     $aGroups = array();
     $aRoles = array();
     foreach (KTUtil::arrayGet($aInformed, 'user', array()) as $iUserId) {
         $oU = User::get($iUserId);
         if (PEAR::isError($oU) || $oU == false) {
             continue;
         } else {
             $aUsers[$oU->getId()] = $oU;
         }
     }
     foreach (KTUtil::arrayGet($aInformed, 'group', array()) as $iGroupId) {
         $oG = Group::get($iGroupId);
         if (PEAR::isError($oG) || $oG == false) {
             continue;
         } else {
             $aGroups[$oG->getId()] = $oG;
         }
     }
     foreach (KTUtil::arrayGet($aInformed, 'role', array()) as $iRoleId) {
         $oR = Role::get($iRoleId);
         if (PEAR::isError($oR) || $oR == false) {
             continue;
         } else {
             $aRoles[] = $oR;
         }
     }
     // FIXME extract this into a util - I see us using this again and again.
     // start with roles ... roles _only_ ever contain groups.
     foreach ($aRoles as $oRole) {
         // do NOT alert anonymous or Everyone roles - that would be very scary.
         $iRoleId = KTUtil::getId($oRole);
         if ($iRoleId == -3 || $iRoleId == -4) {
             continue;
         }
         // first try on the document, then the folder above it.
         $oRoleAllocation = DocumentRoleAllocation::getAllocationsForDocumentAndRole($oDocument->getId(), $iRoleId);
         if (is_null($oRoleAllocation)) {
             // if we don't get a document role, try folder role.
             $oRoleAllocation = RoleAllocation::getAllocationsForFolderAndRole($oDocument->getFolderID(), $oRole->getId());
         }
         if (is_null($oRoleAllocation) || PEAR::isError($oRoleAllocation)) {
             continue;
         }
         $aRoleUsers = $oRoleAllocation->getUsers();
         $aRoleGroups = $oRoleAllocation->getGroups();
         foreach ($aRoleUsers as $id => $oU) {
             $aUsers[$id] = $oU;
         }
         foreach ($aRoleGroups as $id => $oGroup) {
             $aGroups[$id] = $oGroup;
         }
     }
     // we now have a (potentially overlapping) set of groups, which may
     // have subgroups.
     //
     // what we need to do _now_ is build a canonical set of groups, and then
     // generate the singular user-base.
     $aGroupMembershipSet = GroupUtil::buildGroupArray();
     $aAllIds = array_keys($aGroups);
     foreach ($aGroups as $id => $oGroup) {
         $aAllIds = kt_array_merge($aGroupMembershipSet[$id], $aAllIds);
     }
     foreach ($aAllIds as $id) {
         if (!array_key_exists($id, $aGroups)) {
             $aGroups[$id] = Group::get($id);
         }
     }
     // now, merge this (again) into the user-set.
     foreach ($aGroups as $oGroup) {
         $aNewUsers = $oGroup->getMembers();
         foreach ($aNewUsers as $oU) {
             $id = $oU->getId();
             if (!array_key_exists($id, $aUsers)) {
                 $aUsers[$id] = $oU;
             }
         }
     }
     // and done.
     foreach ($aUsers as $oU) {
         if (!PEAR::isError($oU)) {
             KTWorkflowNotification::newNotificationForDocument($oDocument, $oU, $oState, $oUser, $sComments);
         }
     }
 }
Exemplo n.º 2
0
 function &newNotificationForDocument($oDocument, $oUser, $oState, $oActor, $sComments)
 {
     $aInfo = array();
     $aInfo['sData1'] = $oState->getName();
     $aInfo['sData2'] = $sComments;
     $aInfo['iData1'] = $oDocument->getId();
     $aInfo['iData2'] = $oActor->getId();
     $aInfo['sType'] = 'ktcore/workflow';
     $aInfo['dCreationDate'] = getCurrentDateTime();
     $aInfo['iUserId'] = $oUser->getId();
     $aInfo['sLabel'] = $oDocument->getName();
     $oNotification = KTNotification::createFromArray($aInfo);
     $handler = new KTWorkflowNotification();
     if ($oUser->getEmailNotification() && strlen($oUser->getEmail()) > 0) {
         $emailContent = $handler->handleNotification($oNotification);
         $emailSubject = sprintf(_kt('Workflow Notification: %s'), $oDocument->getName());
         $oEmail = new EmailAlert($oUser->getEmail(), $emailSubject, $emailContent);
         $oEmail->send();
     }
     return $oNotification;
 }