Skip to content

Instantly share code, notes, and snippets.

@kanetei
Created May 24, 2017 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanetei/d42c52f7b8f403dd2f0fb7695a161eac to your computer and use it in GitHub Desktop.
Save kanetei/d42c52f7b8f403dd2f0fb7695a161eac to your computer and use it in GitHub Desktop.
<?php
namespace Application\Src\Workflow;
use Concrete\Core\Workflow\HistoryEntry\BasicHistoryEntry as BasicWorkflowHistoryEntry;
use Concrete\Core\Workflow\Progress\Progress as WorkflowProgress;
use Concrete\Core\Workflow\Progress\BasicData as BasicWorkflowProgressData;
use Loader;
use Core;
use PermissionKey;
use User;
use UserInfo;
use Group;
class BasicWorkflow extends \Concrete\Core\Workflow\BasicWorkflow
{
protected function notify(
WorkflowProgress $wp,
$message,
$permission = 'notify_on_basic_workflow_entry',
$parameters = array()
)
{
$nk = PermissionKey::getByHandle($permission);
$nk->setPermissionObject($this);
$users = $nk->getCurrentlyActiveUsers($wp);
foreach ($users as $ui) {
$mh = Core::make('helper/mail');
$mh->addParameter('uName', $ui->getUserName());
$mh->to($ui->getUserEmail());
$mh->from('test@example.com', t('Basic Workflow'));
$mh->addParameter('message', $message);
foreach ($parameters as $key => $value) {
$mh->addParameter($key, $value);
}
$mh->addParameter('siteName', Core::make('config')->get('concrete.site'));
$mh->load('basic_workflow_notification');
$mh->sendMail();
unset($mh);
}
}
public function start(WorkflowProgress $wp)
{
// lets save the basic data associated with this workflow.
$req = $wp->getWorkflowRequestObject();
$db = Loader::db();
$db->Execute(
'INSERT INTO BasicWorkflowProgressData (wpID, uIDStarted) VALUES (?, ?)',
array($wp->getWorkflowProgressID(), $req->getRequesterUserID()));
if ($this->canApproveWorkflow()) {
// Then that means we have the ability to approve the workflow we just started.
// In that case, we transparently approve it, and skip the entry notification step.
$wpr = $req->approve($wp);
$wp->delete();
} else {
$ui = UserInfo::getByID($req->getRequesterUserID());
$ids = array_keys($ui->getUserObject()->getUserGroups());
$groupName = '';
foreach($ids as $id) {
$group = Group::getByID($id);
if($group->getGroupDisplayName() === '登録者' || $group->getGroupDisplayName() === '企業ページ作成者')
$groupName .= $group->getGroupDisplayName();
}
// let's get all the people who are set to be notified on entry
$message =
Core::make('helper/date')->formatDateTime($wp->getWorkflowProgressDateAdded(), true) .
' に ' .
$ui->getUserName() .
' さん(グループ ' .
$groupName .
')が次のリクエストを申請しました:\n\n' .
$req->getWorkflowRequestDescriptionObject()->getEmailDescription();
$this->notify($wp, $message, 'notify_on_basic_workflow_entry');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment