/** * Returns the schemes that are linked to this scheme. * * @return \TableRecords\SchemePart[] */ public function getSchemeParts() : array { if (!$this->scheme_parts) { $table = new \Tables\SchemeSchemeParts(); $linking_records = $table->by('scheme_id', $this->id)->get(); if (!$linking_records) { return []; } $scheme_part_ids = []; foreach ($linking_records as $record) { $scheme_part_ids[] = (int) $record->scheme_part_id; } $scheme_part_ids = array_filter($scheme_part_ids); if (!$scheme_part_ids) { return []; } $table = new \Tables\SchemeParts(); foreach ($scheme_part_ids as $scheme_part_id) { $this->scheme_parts[] = $table->get($scheme_part_id); } } return array_reverse($this->scheme_parts); // Reverse as newest is displayed first. }
<?php $scheme_part_id = !empty($_GET['id']) ? (int) $_GET['id'] : null; $page_title = __(sprintf('%s scheme part', $scheme_part_id ? 'Edit' : 'New')); $scheme_part_foods = []; $Crumbs->addCrumb($page_title); $page_controls = [['text' => __('Back'), 'url' => $Crumbs->getPreviousPageUrl()]]; // Handle edit instead of new: if ($scheme_part_id) { $scheme_parts_table = new Tables\SchemeParts(); $scheme_part = $scheme_parts_table->get($scheme_part_id); if (!$scheme_part) { return $Template->output('error', 404); } elseif ($scheme_part->user_id != getUser()->id) { return $Template->output('error', 403); } $page_controls[] = ['text' => __('Delete'), 'url' => 'action/scheme_parts/delete?id=' . $scheme_part_id, 'confirm_message' => true]; $scheme_part_foods = $scheme_part->getFoods(); } $Template->output('header', ['title' => $page_title, 'nav_active' => 'scheme_parts']); $Template->output('page_controls', $page_controls); $Template->output('validator/status'); ?> <script src="js/page_specific/scheme_parts/scheme_part.js"></script> <form id="form-save_scheme_part" action="ajaxa/scheme_parts/save" method="post" class="odf_ajax"> <input type="hidden" name="id" value="<?php echo $scheme_part_id; ?> ">