<?php
defined('C5_EXECUTE') or die("Access Denied.");
namespace Application\Concrete\Workflow;
use Concrete\Core\Permission\AssignableObjectInterface;
use Concrete\Core\Permission\AssignableObjectTrait;
use Concrete\Core\Permission\Key\Key;
use Concrete\Core\Workflow\HistoryEntry\BasicHistoryEntry as BasicWorkflowHistoryEntry;
use Concrete\Core\Workflow\Progress\Action\ApprovalAction as WorkflowProgressApprovalAction;
use Concrete\Core\Workflow\Progress\Action\CancelAction as WorkflowProgressCancelAction;
use Concrete\Core\Workflow\Progress\BasicData as BasicWorkflowProgressData;
use Concrete\Core\Workflow\Progress\Progress as WorkflowProgress;
use Core;
use Concrete\Core\Permission\Access\Access as PermissionAccess;
use PermissionKey;
use User;
use UserInfo;
use Group;
use Concrete\Core\Localization\Localization;
class BasicWorkflow extends \Concrete\Core\Workflow\BasicWorkflow
{
protected function notify(
WorkflowProgress $wp,
$message,
$permission = 'notify_on_basic_workflow_entry',
$parameters = []
) {
$nk = PermissionKey::getByHandle($permission);
$nk->setPermissionObject($this);
$users = $nk->getCurrentlyActiveUsers($wp);
$loc = Localization::getInstance();
$loc->pushActiveContext('email');
$dt = $wp->getWorkflowProgressDateAdded();
$dh = Core::make('helper/date');
//ワークフローの情報を取得
$req = $wp->getWorkflowRequestObject();
//ここでワークフローに送信したユーザーのIDを取得
$requID = $req->getRequesterUserID();
//ここでワークフローに送信したユーザー情報も取得
$requi = UserInfo::getByID($requID);
//対象グループのユーザーに総当たりでアクセス開始
foreach ($users as $ui) {
// Get user object of the receiver and set locale to their language
$user = $ui->getUserObject();
$lan = $user->getUserLanguageToDisplay();
$loc->setLocale($lan);
$mh = Core::make('helper/mail');
$mh->addParameter('uName', $ui->getUserName());
$mh->to($ui->getUserEmail());
$adminUser = UserInfo::getByID(USER_SUPER_ID);
$mh->from($adminUser->getUserEmail(), t('Basic Workflow'));
$date = $dh->formatDateTime($dt, true); // Call here to translate datetime into users language
$translatedMessage = $this->getTranslatedMessage($message, $date);
$mh->addParameter('message', $translatedMessage);
foreach ($parameters as $key => $value) {
$mh->addParameter($key, $value);
}
$mh->addParameter('siteName', \Core::make('site')->getSite()->getSiteName());
//メール文面を変更したい時はここでテンプレート変更できるよ
$mh->load('basic_workflow_notification');
//通知送信対象のユーザー情報を取得
$u = User::getByUserID($ui->getUserID());
//リクエストしたユーザーと名前を比較して一致すれば通知を送信
if($ui->getUserName() == $requi->getUserName()){
$mh->sendMail();
}
unset($mh);
}
$loc->popActiveContext();
}
}