2015-09-07 18:13:08 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace ProcessMaker\BusinessModel\Light;
|
|
|
|
|
|
2016-04-01 19:23:28 -04:00
|
|
|
use \ProcessMaker\Services\Api;
|
2015-09-07 18:13:08 -04:00
|
|
|
use G;
|
|
|
|
|
|
|
|
|
|
class NotificationDevice
|
|
|
|
|
{
|
2016-04-05 11:34:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public function checkMobileNotifications()
|
|
|
|
|
{
|
|
|
|
|
$conf = \System::getSystemConfiguration('', '', SYS_SYS);
|
|
|
|
|
$activeNotifications = true;
|
|
|
|
|
if (isset($conf['mobileNotifications'])) {
|
|
|
|
|
$activeNotifications = $conf['mobileNotifications'] == 1 ? true : false;
|
|
|
|
|
}
|
|
|
|
|
return $activeNotifications;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 18:13:08 -04:00
|
|
|
/**
|
|
|
|
|
* Post Create register device with userUid
|
|
|
|
|
*
|
|
|
|
|
* @param array $request_data
|
|
|
|
|
* @param string $use_uid
|
|
|
|
|
* @author Ronald Quenta <ronald.quenta@processmaker.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function saveDevice($use_uid, $request_data)
|
|
|
|
|
{
|
|
|
|
|
$arrayData = array();
|
|
|
|
|
$arrayData['USR_UID'] = $use_uid;
|
|
|
|
|
$arrayData['DEV_REG_ID'] = $request_data['deviceIdToken'];
|
|
|
|
|
$arrayData['SYS_LANG'] = $request_data['sysLanguage'];
|
|
|
|
|
$arrayData['DEV_TYPE'] = $request_data['deviceType'];
|
|
|
|
|
$arrayData['DEV_STATUS'] = 'active';
|
|
|
|
|
|
|
|
|
|
$oNoti = new \NotificationDevice();
|
|
|
|
|
$devices = $oNoti->loadByDeviceId($request_data['deviceIdToken']);
|
|
|
|
|
$response = array();
|
|
|
|
|
if (!$devices){
|
|
|
|
|
if($oNoti->create($arrayData)){
|
|
|
|
|
$response["devUid"] = $oNoti->getDevUid();
|
|
|
|
|
$response["message"] = G:: LoadTranslation("ID_RECORD_SAVED_SUCCESFULLY");
|
|
|
|
|
G::auditLog("Create", "Device Save: Device ID (".$oNoti->getDevUid().") ");
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-10-08 09:31:09 -04:00
|
|
|
if($oNoti->remove($devices[0]['DEV_UID'],$devices[0]['USR_UID'])){
|
|
|
|
|
$arrayData['USR_UID'] = $use_uid;
|
|
|
|
|
$arrayData['DEV_REG_ID'] = $devices[0]['DEV_REG_ID'];
|
|
|
|
|
$arrayData['SYS_LANG'] = $devices[0]['SYS_LANG'];
|
|
|
|
|
$arrayData['DEV_TYPE'] = $devices[0]['DEV_TYPE'];
|
|
|
|
|
$arrayData['DEV_STATUS'] = 'active';
|
|
|
|
|
|
|
|
|
|
if($devUid = $oNoti->createOrUpdate($arrayData)){
|
|
|
|
|
$response["devUid"] = $devUid;
|
|
|
|
|
$response["message"] = G:: LoadTranslation("ID_RECORD_SAVED_SUCCESFULLY");
|
|
|
|
|
G::auditLog("Create", "Device Save: Device ID (".$oNoti->getDevUid().") ");
|
|
|
|
|
} else {
|
|
|
|
|
throw new \Exception(G::LoadTranslation("ID_RECORD_CANNOT_BE_CREATED"));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
throw new \Exception(G::LoadTranslation("ID_RECORD_DOES_NOT_EXIST"));
|
|
|
|
|
}
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update register device with userUid
|
|
|
|
|
*
|
|
|
|
|
* @param array $request_data
|
|
|
|
|
* @param string $dev_uid
|
|
|
|
|
* @param string $use_uid
|
|
|
|
|
* @author Ronald Quenta <ronald.quenta@processmaker.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function updateDevice($dev_uid, $use_uid, $request_data)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$arrayData = array();
|
|
|
|
|
$arrayData['USR_UID'] = $use_uid;
|
|
|
|
|
$arrayData['DEV_UID'] = $dev_uid;
|
|
|
|
|
if(isset($request_data['deviceIdToken'])){
|
|
|
|
|
$arrayData['DEV_REG_ID'] = $request_data['deviceIdToken'];
|
|
|
|
|
}
|
|
|
|
|
if(isset($request_data['sysLanguage'])) {
|
|
|
|
|
$arrayData['SYS_LANG'] = $request_data['sysLanguage'];
|
|
|
|
|
}
|
|
|
|
|
if(isset($request_data['deviceType'])) {
|
|
|
|
|
$arrayData['DEV_TYPE'] = $request_data['deviceType'];
|
|
|
|
|
}
|
|
|
|
|
$oNoti = new \NotificationDevice();
|
|
|
|
|
$response = array();
|
|
|
|
|
if($oNoti->update($arrayData)){
|
|
|
|
|
$response["message"] = G:: LoadTranslation("ID_RECORD_SAVED_SUCCESFULLY");
|
2015-10-08 09:31:09 -04:00
|
|
|
G::auditLog("Update", "Device Save: Device ID (".$oNoti->getDevUid().") ");
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|
|
|
|
|
return $response;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send Message each user id
|
|
|
|
|
*
|
|
|
|
|
* @param array $request_data
|
|
|
|
|
* @author Ronald Quenta <ronald.quenta@processmaker.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public function sendMessage($userIds, $message, $data = null)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$oNoti = new \NotificationDevice();
|
|
|
|
|
$devices = array();
|
|
|
|
|
if (is_array($userIds)){
|
|
|
|
|
foreach ($userIds as $id) {
|
|
|
|
|
$deviceUser = $oNoti->loadByUsersId($id);
|
|
|
|
|
$devices = array_merge($devices, $deviceUser);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$devices = $oNoti->loadByUsersId($userIds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$devicesAndroidIds = array();
|
|
|
|
|
$devicesAppleIds = array();
|
|
|
|
|
foreach ($devices as $dev) {
|
|
|
|
|
switch ($dev['DEV_TYPE']) {
|
|
|
|
|
case "apple":
|
|
|
|
|
$devicesAppleIds[] = $dev['DEV_REG_ID'];
|
|
|
|
|
break;
|
|
|
|
|
case "android":
|
|
|
|
|
$devicesAndroidIds[] = $dev['DEV_REG_ID'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (count($devicesAppleIds) > 0) {
|
|
|
|
|
$oNotification = new PushMessageIOS();
|
|
|
|
|
$oNotification->setSettingNotification();
|
|
|
|
|
$oNotification->setDevices($devicesAppleIds);
|
|
|
|
|
$response['android'] = $oNotification->send($message, $data);
|
|
|
|
|
}
|
|
|
|
|
if (count($devicesAndroidIds) > 0) {
|
|
|
|
|
$oNotification = new PushMessageAndroid();
|
|
|
|
|
$oNotification->setSettingNotification();
|
|
|
|
|
$oNotification->setDevices($devicesAndroidIds);
|
|
|
|
|
$response['apple'] = $oNotification->send($message, $data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
2016-04-04 10:33:51 -04:00
|
|
|
throw new \Exception($e->getMessage(), Api::STAT_APP_EXCEPTION);
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2016-06-27 12:10:04 -04:00
|
|
|
* @param $appFields
|
|
|
|
|
* @param $nextDel
|
|
|
|
|
* @param $iNewDelIndex
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws \Exception
|
2015-09-07 18:13:08 -04:00
|
|
|
*/
|
2016-06-27 12:10:04 -04:00
|
|
|
public function routeCaseNotificationDevice($appFields, $nextDel, $iNewDelIndex)
|
2015-09-07 18:13:08 -04:00
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$response = array();
|
2016-01-26 15:35:38 -04:00
|
|
|
$typeList = 'todo';
|
2016-06-27 12:10:04 -04:00
|
|
|
$arrayTaskUser = array();
|
|
|
|
|
switch ($nextDel["TAS_ASSIGN_TYPE"]) {
|
|
|
|
|
case "SELF_SERVICE":
|
|
|
|
|
$arrayTaskUser = $this->getTaskUserSelfService($nextDel["TAS_UID"], $appFields);
|
|
|
|
|
$typeList = 'unassigned';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (isset($nextDel["USR_UID"]) && !empty($nextDel["USR_UID"])) {
|
|
|
|
|
$arrayTaskUser = $nextDel["USR_UID"];
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|
2016-06-27 12:10:04 -04:00
|
|
|
break;
|
|
|
|
|
}
|
2015-09-07 18:13:08 -04:00
|
|
|
|
2016-06-27 12:10:04 -04:00
|
|
|
$userIds = $arrayTaskUser;
|
|
|
|
|
$message = '#' . $appFields['APP_NUMBER'] . ' : ' . $appFields['APP_TITLE'];
|
|
|
|
|
$data = array(
|
|
|
|
|
'processId' => $appFields['PRO_UID'],
|
|
|
|
|
'taskId' => $nextDel["TAS_UID"],
|
|
|
|
|
'caseId' => $appFields['APP_UID'],
|
|
|
|
|
'caseTitle' => $appFields['APP_TITLE'],
|
|
|
|
|
'delIndex' => $iNewDelIndex,
|
|
|
|
|
'typeList' => $typeList
|
|
|
|
|
);
|
2015-09-07 18:13:08 -04:00
|
|
|
|
2016-06-27 12:10:04 -04:00
|
|
|
if ($userIds) {
|
|
|
|
|
$oNoti = new \NotificationDevice();
|
|
|
|
|
if (is_array($userIds)) {
|
|
|
|
|
$devices = $oNoti->loadUsersArrayId($userIds);
|
|
|
|
|
} else {
|
|
|
|
|
$devices = $oNoti->loadByUsersId($userIds);
|
|
|
|
|
$lists = new \ProcessMaker\BusinessModel\Lists();
|
|
|
|
|
$counter = $lists->getCounters($userIds);
|
|
|
|
|
$light = new \ProcessMaker\Services\Api\Light();
|
|
|
|
|
$result = $light->parserCountersCases($counter);
|
|
|
|
|
$data['counters'] = $result;
|
|
|
|
|
}
|
2015-09-07 18:13:08 -04:00
|
|
|
|
2016-06-27 12:10:04 -04:00
|
|
|
$devicesAndroidIds = array();
|
|
|
|
|
$devicesAppleIds = array();
|
|
|
|
|
foreach ($devices as $dev) {
|
|
|
|
|
switch ($dev['DEV_TYPE']) {
|
|
|
|
|
case "apple":
|
|
|
|
|
$devicesAppleIds[] = $dev['DEV_REG_ID'];
|
|
|
|
|
break;
|
|
|
|
|
case "android":
|
|
|
|
|
$devicesAndroidIds[] = $dev['DEV_REG_ID'];
|
|
|
|
|
break;
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|
|
|
|
|
}
|
2016-06-27 12:10:04 -04:00
|
|
|
if (count($devicesAppleIds) > 0) {
|
|
|
|
|
$arrayData = array();
|
|
|
|
|
$arrayData['NOT_FROM'] = $appFields['APP_CUR_USER'];
|
|
|
|
|
$arrayData['DEV_TYPE'] = 'apple';
|
|
|
|
|
$arrayData['DEV_UID'] = serialize($devicesAppleIds);
|
|
|
|
|
$arrayData['NOT_MSG'] = $message;
|
|
|
|
|
$arrayData['NOT_DATA'] = serialize($data);
|
|
|
|
|
$arrayData['NOT_STATUS'] = "pending";
|
|
|
|
|
$notQueue = new \NotificationQueue();
|
|
|
|
|
$notQueue->create($arrayData);
|
|
|
|
|
}
|
|
|
|
|
if (count($devicesAndroidIds) > 0) {
|
|
|
|
|
$arrayData = array();
|
|
|
|
|
$arrayData['NOT_FROM'] = $appFields['APP_CUR_USER'];
|
|
|
|
|
$arrayData['DEV_TYPE'] = 'android';
|
|
|
|
|
$arrayData['DEV_UID'] = serialize($devicesAndroidIds);
|
|
|
|
|
$arrayData['NOT_MSG'] = $message;
|
|
|
|
|
$arrayData['NOT_DATA'] = serialize($data);
|
|
|
|
|
$arrayData['NOT_STATUS'] = "pending";
|
|
|
|
|
$notQueue = new \NotificationQueue();
|
|
|
|
|
$notQueue->create($arrayData);
|
|
|
|
|
}
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|
|
|
|
|
} catch (\Exception $e) {
|
2016-04-04 10:33:51 -04:00
|
|
|
throw new \Exception($e->getMessage(), Api::STAT_APP_EXCEPTION);
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-05 11:34:35 -04:00
|
|
|
public function getTaskUserSelfService($tas_uid, $appFields)
|
|
|
|
|
{
|
|
|
|
|
$oTask = new \Tasks();
|
|
|
|
|
$oGroup = new \Groups();
|
|
|
|
|
$taskNextDel = \TaskPeer::retrieveByPK($tas_uid);
|
|
|
|
|
$arrayTaskUser = array();
|
|
|
|
|
|
|
|
|
|
if ($taskNextDel->getTasAssignType() == "SELF_SERVICE" && trim($taskNextDel->getTasGroupVariable()) != "") {
|
|
|
|
|
// Self Service Value Based Assignment
|
|
|
|
|
$nextTaskGroupVariable = trim($taskNextDel->getTasGroupVariable(), " @#");
|
|
|
|
|
if (isset($appFields["APP_DATA"][$nextTaskGroupVariable])) {
|
|
|
|
|
$dataGroupVariable = $appFields["APP_DATA"][$nextTaskGroupVariable];
|
|
|
|
|
$dataGroupVariable = (is_array($dataGroupVariable))? $dataGroupVariable : trim($dataGroupVariable);
|
|
|
|
|
if (!empty($dataGroupVariable) && is_array($dataGroupVariable)){
|
|
|
|
|
$arrayTaskUser[] = $dataGroupVariable;
|
|
|
|
|
} elseif(!empty($dataGroupVariable)) {
|
|
|
|
|
$arrayUsersOfGroup = $oGroup->getUsersOfGroup($dataGroupVariable);
|
|
|
|
|
foreach ($arrayUsersOfGroup as $arrayUser) {
|
|
|
|
|
$arrayTaskUser[] = $arrayUser["USR_UID"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else { // Self Service
|
|
|
|
|
$arrayGroupsOfTask = $oTask->getGroupsOfTask($tas_uid, 1);
|
|
|
|
|
foreach ($arrayGroupsOfTask as $arrayGroup) {
|
|
|
|
|
$arrayUsersOfGroup = $oGroup->getUsersOfGroup($arrayGroup["GRP_UID"]);
|
|
|
|
|
foreach ($arrayUsersOfGroup as $arrayUser) {
|
|
|
|
|
$arrayTaskUser[] = $arrayUser["USR_UID"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$arrayUsersOfTask = $oTask->getUsersOfTask($tas_uid, 1);
|
|
|
|
|
foreach ($arrayUsersOfTask as $arrayUser) {
|
|
|
|
|
$arrayTaskUser[] = $arrayUser["USR_UID"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $arrayTaskUser;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-07 18:13:08 -04:00
|
|
|
}
|