'int' ]; } public function get_site_template_name() : string { return 'manage_messages'; } public function remove(messages_mapper $mapper) : void { if (!$this->is_validated('id')) { $this->error_toast('ID of the message is wrong.'); } $message = new message($this->get_validated('id')); try { $mapper->remove($message); $this->success_toast('Removed success.'); } catch (\exception $exception) { $this->error_toast($exception->getMessage()); } } private function load_groups() : \cx_appengine\string_builder { $mapper = new groups_mapper( $this->get_database(), $this->get_tables() ); $default = new group(); $default->name = 'ALL'; $groups = $mapper->load_all(); $list = new \cx_appengine\string_builder(); array_push($groups, $default); foreach ($groups as $group) { $options = []; $options['group_name'] = $group->name; if ($group->has_id()) { $options['group_id'] = $group->get_id(); } else { $options['group_id'] = 'NULL'; $options['selected'] = 'selected'; } $list->push( $this ->get_templates() ->prepare('single_group_option') ->render($options) ); } return $list; } public function process() : self { $converter = new messages_converter(); $messages = new \cx_appengine\string_builder(); $mapper = new messages_mapper( $this->get_database(), $this->get_tables() ); if ($this->is_received('remove')) { $this->remove($mapper); } $groups = $this->load_groups(); foreach ($mapper->load_all() as $message) { $options = $converter->load_object($message)->get_array(); $options['groups'] = $groups; $messages->push( $this ->get_templates() ->prepare('manage_messages_single_message') ->render($options) ); } $this->set('messages_place', $messages); return $this; } }