HOR-1293 "Create PMFunction to Send Message to Group PMFSendMessageToGroup" SOLVED

Issue:
    Create PMFunction to Send Message to Group PMFSendMessageToGroup
Cause:
    Nuevo requerimiento de funcion
Solution:
    Se a implementado la nueva funcion:
        function PMFSendMessageToGroup(
            $groupId,
            $caseId,
            $from,
            $subject,
            $template,
            $arrayField = [],
            $arrayAttachment = [],
            $showMessage = true,
            $delIndex = 0,
            $config = [],
            $limit = 100
        )
This commit is contained in:
Victor Saisa Lopez
2016-07-21 10:07:00 -04:00
parent 7592f29485
commit 1fb08d42ba
4 changed files with 109 additions and 13 deletions

View File

@@ -333,7 +333,7 @@ class G
* @param string $key
* @return string
*/
public function decrypt ($string, $key)
public static function decrypt($string, $key)
{
// if ( defined ( 'ENABLE_ENCRYPT' ) && ENABLE_ENCRYPT == 'yes' ) {
//if (strpos($string, '|', 0) !== false) return $string;
@@ -1820,7 +1820,7 @@ class G
* @param type Array $aFields
* @return type String
*/
public function replaceDataGridField($sContent, $aFields, $nl2brRecursive = true)
public static function replaceDataGridField($sContent, $aFields, $nl2brRecursive = true)
{
$nrt = array("\n", "\r", "\t");
$nrthtml = array("(n /)", "(r /)", "(t /)");
@@ -2816,7 +2816,7 @@ class G
* @access public
* @return array
*/
public function array_merges ()
public static function array_merges()
{
$array = array ();
$arrays = & func_get_args();
@@ -2963,7 +2963,7 @@ class G
* Constants: SYS_*
* Sessions : USER_* , URS_*
*/
public function getSystemConstants($params = null)
public static function getSystemConstants($params = null)
{
$t1 = G::microtime_float();
$sysCon = array();
@@ -5704,7 +5704,7 @@ class G
*
* @return md5($string)
*/
public function encryptOld ($string)
public static function encryptOld($string)
{
return md5($string);
}

View File

@@ -3652,7 +3652,7 @@ function PMFCopyDocumentCase($appDocUid, $versionNumber, $targetCaseUid, $inputD
* @param string | $taskUid | Task Uid | The unique Id of the Task.
* @param string | $userGroupUid | Uid from User or Group | The unique Uid from User or Group.
*
* @return int Returns 1 when is assigned.
* @return int | $result | Result | Returns 1 when is assigned
*/
function PMFAddUserGroupToTask($taskUid, $userGroupUid)
@@ -3742,3 +3742,89 @@ function PMFRemoveUserGroupFromTask($taskUid, $userGroupUid)
return 1;
}
/**
* @method
*
* Sends emails to user's group using a template file
*
* @name PMFSendMessageToGroup
* @label PMF Send Message To Group
* @link http://wiki.processmaker.com/index.php/ProcessMaker_Functions#PMFSendMessageToGroup.28.29
*
* @param string(32) | $groupId | Group ID | Unique id of Group.
* @param string(32) | $caseId | Case ID | The UID (unique identification) for a case, which is a string of 32 hexadecimal characters to identify the case.
* @param string | $from | Sender | The email address of the person who sends out the email.
* @param string | $subject | Subject of the email | The subject (title) of the email.
* @param string | $template | Name of the template | The name of the template file in plain text or HTML format which will produce the body of the email.
* @param array | $arrayField = [] | Variables for email template | Optional parameter. An associative array where the keys are the variable names and the values are the variables' values.
* @param array | $arrayAttachment = [] | Attachment | An Optional arrray. An array of files (full paths) to be attached to the email.
* @param boolean | $showMessage = true | Show message | Optional parameter. Set to TRUE to show the message in the case's message history.
* @param int | $delIndex = 0 | Delegation index of the case | Optional parameter. The delegation index of the current task in the case.
* @param mixed | $config = [] | Email server configuration | An optional array: An array of parameters to be used in the Email sent (MESS_ENGINE, MESS_SERVER, MESS_PORT, MESS_FROM_MAIL, MESS_RAUTH, MESS_ACCOUNT, MESS_PASSWORD, and SMTPSecure) Or String: UID of Email server.
* @param int | $limit = 100 | Limit | Limit of mails to send in each bach.
*
* @return int | $result | Result | Returns 1 when is send message to group
*/
function PMFSendMessageToGroup(
$groupId,
$caseId,
$from,
$subject,
$template,
$arrayField = [],
$arrayAttachment = [],
$showMessage = true,
$delIndex = 0,
$config = [],
$limit = 100
) {
//Verify data and Set variables
$group = new \ProcessMaker\BusinessModel\Group();
$case = new \ProcessMaker\BusinessModel\Cases();
$group->throwExceptionIfNotExistsGroup($groupId, '$groupId');
$arrayApplicationData = $case->getApplicationRecordByPk($caseId, ['$applicationUid' => '$caseId'], true);
//Send mails
$criteriaGroupUser = $group->getUserCriteria($groupId, ['condition' => [[UsersPeer::USR_STATUS, 'ACTIVE', Criteria::EQUAL]]]);
$start = 0;
do {
$flagNextRecord = false;
$to = '';
$criteria = clone $criteriaGroupUser;
$criteria->setOffset($start);
$criteria->setLimit($limit);
$rsCriteria = GroupUserPeer::doSelectRS($criteria);
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
while ($rsCriteria->next()) {
$record = $rsCriteria->getRow();
$to .= (($to != '')? ', ' : '') . $record['USR_EMAIL'];
$flagNextRecord = true;
}
if ($flagNextRecord) {
$result = PMFSendMessage(
$caseId, $from, $to, null, null, $subject, $template, $arrayField, $arrayAttachment, $showMessage, $delIndex, $config
);
if ($result == 0) {
return 0;
}
}
$start += $limit;
} while ($flagNextRecord);
//Return
return 1;
}

View File

@@ -985,7 +985,7 @@ class System
return $aChanges;
}
public function getEmailConfiguration ()
public static function getEmailConfiguration()
{
$emailServer = new \ProcessMaker\BusinessModel\EmailServer();

View File

@@ -625,9 +625,13 @@ class Group
*
* return object
*/
public function getUserCriteria($groupUid, $arrayFilterData = null, $arrayUserUidExclude = null)
public function getUserCriteria($groupUid, array $arrayWhere = null, $arrayUserUidExclude = null)
{
try {
$flag = !is_null($arrayWhere) && is_array($arrayWhere);
$flagCondition = $flag && array_key_exists('condition', $arrayWhere);
$flagFilter = $flag && array_key_exists('filter', $arrayWhere);
$criteria = new \Criteria("workflow");
$criteria->addSelectColumn(\UsersPeer::USR_UID);
@@ -642,17 +646,23 @@ class Group
$criteria->add(\GroupUserPeer::GRP_UID, $groupUid, \Criteria::EQUAL);
}
$criteria->add(\UsersPeer::USR_STATUS, "CLOSED", \Criteria::NOT_EQUAL);
if ($flagCondition && !empty($arrayWhere['condition'])) {
foreach ($arrayWhere['condition'] as $value) {
$criteria->add($value[0], $value[1], $value[2]);
}
} else {
$criteria->add(\UsersPeer::USR_STATUS, 'CLOSED', \Criteria::NOT_EQUAL);
}
if (!is_null($arrayUserUidExclude) && is_array($arrayUserUidExclude)) {
$criteria->add(\UsersPeer::USR_UID, $arrayUserUidExclude, \Criteria::NOT_IN);
}
if (!is_null($arrayFilterData) && is_array($arrayFilterData) && isset($arrayFilterData["filter"]) && trim($arrayFilterData["filter"]) != "") {
if ($flagFilter && trim($arrayWhere['filter']) != '') {
$criteria->add(
$criteria->getNewCriterion(\UsersPeer::USR_USERNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
$criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)->addOr(
$criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, "%" . $arrayFilterData["filter"] . "%", \Criteria::LIKE)))
$criteria->getNewCriterion(\UsersPeer::USR_USERNAME, '%' . $arrayWhere['filter'] . '%', \Criteria::LIKE)->addOr(
$criteria->getNewCriterion(\UsersPeer::USR_FIRSTNAME, '%' . $arrayWhere['filter'] . '%', \Criteria::LIKE)->addOr(
$criteria->getNewCriterion(\UsersPeer::USR_LASTNAME, '%' . $arrayWhere['filter'] . '%', \Criteria::LIKE)))
);
}