Created
June 10, 2018 21:05
-
-
Save mentisy/6df9031b3027eb81f3c5dd2c83445a1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Shell; | |
use App\Mailer\ToolsStatusMailer; | |
use App\Model\Entity\User; | |
use App\Model\Table\ToolsStatusTable; | |
use App\Model\Table\UsersTable; | |
use Cake\Console\Shell; | |
/** | |
* Class ToolsShell | |
* @package App\Shell | |
* Loaned out tools reminder if not returned in given X days/weeks/months. | |
* | |
* @property ToolsStatusTable $ToolsStatus | |
* @property UsersTable $Users | |
*/ | |
class ToolsShell extends Shell { | |
/** | |
* Init | |
*/ | |
public function initialize() | |
{ | |
parent::initialize(); | |
$this->loadModel('ToolsStatus'); | |
} | |
/** | |
* Print out a list of users and their related tools with prolonged checkouts | |
* @return int | |
*/ | |
public function prolongedCheckouts() { | |
$this->out(print_r($this->_findProlongedCheckouts(), true)); | |
return 0; | |
} | |
/** | |
* Send email to all users with prolonged tool checkouts | |
*/ | |
public function prolongedCheckoutsSend() { | |
/** @var User[] $users */ | |
$users = $this->_findProlongedCheckouts(); | |
$toolsStatusMailer = new ToolsStatusMailer(); | |
foreach($users as $user) { | |
$this->out('Mail sent'); | |
$toolsStatusMailer->send('prolongedCheckouts', [$user]); | |
} | |
} | |
/** | |
* Collect all users with the related tools with prolonged checkouts | |
* @return array | |
*/ | |
protected function _findProlongedCheckouts() { | |
return $this->ToolsStatus->find('usersWithProlongedCheckouts')->toArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment