I have a search collection that includes a callback that should not be triggered unless its checkbox is selected on my search form. Here is the code for the checkbox:
<?php echo $this->Form->control('mgr_sign', ['label' => 'Signed by manager', 'type' => 'checkbox'], ['empty' => ['' => '']]); ?>
Here is the callback in my search collection.
$this->add('mgr_sign', 'Search.Callback', [
'callback' => function (\Cake\ORM\Query $query, array $args, \Search\Model\Filter\Base $filter) {
// Return all work authorizations signed by a manager
$query->where("Noncons.id IN(SELECT noncons.id FROM noncons WHERE app_manager_id != 0 AND deleted_record = 0)");
}
]);
The problem is that this callback executes even when the checkbox is not selected, and my search results are inaccurate. I need to ensure that this callback only executes if the user checks the box. Debugging the query shows that it executes as an AND statement.