1 | <?php |
||
12 | class AdminDeleteCommForm extends FormModel |
||
13 | { |
||
14 | /** |
||
15 | * Constructor injects with DI container. |
||
16 | * |
||
17 | * @param Anax\DI\DIInterface $di a service container |
||
18 | */ |
||
19 | 2 | public function __construct(DIInterface $di) |
|
20 | { |
||
21 | 2 | parent::__construct($di); |
|
22 | 2 | $this->form->create( |
|
23 | [ |
||
24 | 2 | "id" => __CLASS__, |
|
25 | 2 | "legend" => "Alla inlägg:", |
|
26 | 2 | ], |
|
27 | [ |
||
28 | "select" => [ |
||
29 | 2 | "type" => "select", |
|
30 | 2 | "label" => "Poster:", |
|
31 | 2 | "options" => $this->getAllPosts(), |
|
32 | 2 | ], |
|
33 | |||
34 | "submit" => [ |
||
35 | 2 | "type" => "submit", |
|
36 | 2 | "value" => "Ta bort", |
|
37 | 2 | "callback" => [$this, "callbackSubmit"] |
|
38 | 2 | ], |
|
39 | ] |
||
40 | 2 | ); |
|
41 | 2 | } |
|
42 | |||
43 | |||
44 | |||
45 | /** |
||
46 | * Get all items as array suitable for display in select option dropdown. |
||
47 | * |
||
48 | * @return array with key value of all items. |
||
49 | */ |
||
50 | 2 | public function getAllPosts() |
|
51 | { |
||
52 | 2 | $comm = new Comm(); |
|
53 | 2 | $comm->setDb($this->di->get("db")); |
|
54 | |||
55 | 2 | $posts = ["-1" => "Välj en text..."]; |
|
56 | 2 | foreach ($comm->findAll() as $obj) { |
|
57 | 2 | $posts[$obj->id] = "{$obj->title} ({$obj->id})"; |
|
58 | 2 | } |
|
59 | |||
60 | 2 | return $posts; |
|
61 | } |
||
62 | |||
63 | |||
64 | |||
65 | /** |
||
66 | * Callback for submit-button which should return true if it could |
||
67 | * carry out its work and false if something failed. |
||
68 | * |
||
69 | * @return boolean true if okey, false if something went wrong. |
||
70 | */ |
||
71 | public function callbackSubmit() |
||
97 | } |
||
98 |