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 | |
declare(strict_types=1); | |
namespace App\Controller; | |
use Cake\Event\EventInterface; | |
use CakeDC\Todo\Controller\TodosController; | |
/** | |
* Applications Controller | |
* | |
* @property \App\Model\Table\BondsTable $Bonds | |
* @property \App\Model\Table\BondTypesTable $BondTypes | |
* @property \SuretyApi\Controller\Component\TaskStorageComponent $TaskStorage | |
*/ | |
class AppTodosController extends TodosController | |
{ | |
/** | |
* initialize | |
* | |
* @return void | |
*/ | |
public function initialize(): void | |
{ | |
parent::initialize(); | |
$this->Todos = $this->fetchTable('CakeDC.Todos'); | |
$this->FollowUps = $this->fetchTable('FollowUps'); | |
} | |
/** | |
* beforeFilter | |
* | |
* @param mixed $event event | |
* @return void | |
*/ | |
public function beforeFilter(EventInterface $event) | |
{ | |
parent::beforeFilter($event); | |
$this->FormProtection->setConfig('unlockedActions', [ | |
'disableFollowUp', | |
]); | |
} | |
/** | |
* disableFollowUpAjax | |
* | |
* @param mixed $followUpId follow up id | |
* @return void | |
*/ | |
public function disableFollowUpAjax($followUpId) | |
{ | |
$this->disableFollowUp($followUpId); | |
if (!$this->getRequest()->is('ajax')) { | |
return $this->redirect($this->getRequest()->referer(true)); | |
} | |
} | |
/** | |
* disableFollowUp | |
* | |
* @param mixed $followUpId | |
* @param mixed $fromController if request is sent from controller | |
* @return void | |
*/ | |
private function disableFollowUp($followUpId, $fromController = false) | |
{ | |
if ($this->getRequest()->is('post') || $fromController) { | |
$jsonResponse = ['success' => 'true']; | |
$error = false; | |
$followUp = $this->FollowUps->find()->where(['id' => $followUpId])->first(); | |
if (!$followUp || $followUp->enabled == 0) { | |
$error = true; | |
} else { | |
$followUp->enabled = 0; | |
} | |
if ($error || !$this->FollowUps->save($followUp)) { | |
$jsonResponse['success'] = 'false'; | |
} else { | |
$jsonResponse['followUp'] = $followUp; | |
} | |
$this->set('jsonResponse', $jsonResponse); | |
$this->viewBuilder()->setOption('serialize', ['jsonResponse']); | |
} | |
} | |
/** | |
* edit | |
* | |
* @param mixed $id todo id | |
* @return void | |
*/ | |
public function edit($id = null) | |
{ | |
$this->disableFollowUp($id, true); | |
} | |
/** | |
* add | |
* | |
* @param mixed $model todo model | |
* @param mixed $foreignKey foreign key | |
* @return void | |
*/ | |
public function add(string $model, string $foreignKey) | |
{ | |
$this->disableFollowUp($foreignKey, true); | |
} | |
/** | |
* delete | |
* | |
* @param mixed $id todo id | |
* @return void | |
*/ | |
public function delete($id = null) | |
{ | |
$this->disableFollowUp($id, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment