Skip to content

Instantly share code, notes, and snippets.

@mentisy
Created June 10, 2018 21:05
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 mentisy/6df9031b3027eb81f3c5dd2c83445a1e to your computer and use it in GitHub Desktop.
Save mentisy/6df9031b3027eb81f3c5dd2c83445a1e to your computer and use it in GitHub Desktop.
<?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