1 <?php
2
3 /*
4 * This file is part of the Icybee package.
5 *
6 * (c) Olivier Laviale <olivier.laviale@gmail.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Icybee\Element;
13
14 use ICanBoogie\Event;
15 use ICanBoogie\Operation;
16
17 class Form extends \Brickrouge\Form
18 {
19 /**
20 * Tries to load the form associated with the operation.
21 *
22 * Booleans that were found in the form when it was stored are initialized to "0" and merged
23 * with the request params.
24 *
25 * This function is a callback for the `ICanBoogie\Operation::get_form` event. The event chain
26 * is stoped if the form is found.
27 *
28 * @param \ICanBoogie\Operation\GetFormEvent $event
29 * @param Operation $operation
30 */
31 static public function on_operation_get_form(\ICanBoogie\Operation\GetFormEvent $event, Operation $operation)
32 {
33 $request = $event->request;
34
35 if (!$request[self::STORED_KEY_NAME])
36 {
37 return;
38 }
39
40 try
41 {
42 $form = self::load($request->params);
43 }
44 catch (\Exception $e)
45 {
46 throw new \ICanBoogie\Operation\FormHasExpired($e->getMessage());
47 }
48
49 if ($form)
50 {
51 if ($form->booleans)
52 {
53 $qs = implode('=0&', array_keys($form->booleans)) . '=0';
54
55 parse_str($qs, $q);
56
57 $request->params = \ICanBoogie\exact_array_merge_recursive($q, $request->params);
58 }
59
60 $event->form = $form;
61 $event->stop();
62 }
63 }
64 }
65