Exemple #1
0
<?php

$page_title = __('Scheme parts');
$Crumbs->setRoot($page_title);
$Template->output('header', ['title' => $page_title, 'nav_active' => 'scheme_parts']);
$Template->output('page_controls', [['text' => __('New'), 'url' => 'scheme_parts/scheme_part']]);
$Template->output('validator/status');
$Cache->cacheOutput(function ($data) {
    extract($data);
    $scheme_parts_table = new Tables\SchemeParts();
    $scheme_parts = $scheme_parts_table->by('user_id', getUser()->id)->setOrderby('name ASC')->get();
    ?>
	<table class="overview amounts_overview">
		<?php 
    $Template->output('tables/food_table_thead');
    ?>
		<tbody>
			<?php 
    foreach ($scheme_parts as $scheme_part) {
        $carbs = $scheme_part->getCarbs();
        $proteins = $scheme_part->getProteins();
        $fats = $scheme_part->getFats();
        ?>
				<tr class="odf_href" data-href="scheme_parts/scheme_part?id=<?php 
        echo $scheme_part->id;
        ?>
">
					<td><?php 
        echo $scheme_part->name;
        ?>
</td>
Exemple #2
0
<?php

$validation_rules = ['id' => ['int', 'ID'], 'name' => ['presence', __('Name')]];
$Validator->validateArray($_POST, $validation_rules);
if ($errors = $Validator->getErrors()) {
    return $Javascript->setErrors($errors)->output();
}
$scheme_part_id = !empty($_POST['id']) ? (int) $_POST['id'] : null;
$update = !!$scheme_part_id;
$table = new \Tables\SchemeParts();
if ($update) {
    // May the current user edit this scheme part?
    $scheme_part = $table->by('user_id', getUser()->id)->get($scheme_part_id);
    if (!$scheme_part) {
        return $Javascript->setError(__('You are not authorized to edit this scheme part.'))->output();
    }
}
if ($update) {
    $table->update($_POST, $scheme_part_id);
} else {
    $data = $_POST;
    $data['user_id'] = getUser()->id;
    $scheme_part_id = $table->create($data);
}
# Update scheme part food table.
$table = new \Tables\SchemePartFoods();
if ($update) {
    // Delete existing scheme part foods.
    $table->by('scheme_part_id', $scheme_part_id)->delete();
}
// Add new scheme part foods.
Exemple #3
0
	<div id="scheme_scheme_parts_management" class="overviews_side_by_side">
		<div id="scheme_parts">
			<?php 
$Cache->cacheOutput(function ($args) {
    extract($args);
    $Template->output('tables/scheme_parts_overview', ['scheme_parts' => $scheme_parts, 'parent' => 'scheme', 'count_totals' => true, 'show_percentages_per_source' => true, 'include_scheme_part_id_inputs' => true]);
}, compact('Template', 'scheme_parts'), 'schemes', getDefaultUniqueCacheData(['scheme_id' => $scheme_id]));
?>
		</div>

		<div id="available_scheme_parts">
			<?php 
$Cache->cacheOutput(function ($args) {
    extract($args);
    $table = new Tables\SchemeParts();
    $available_scheme_parts = $table->by('user_id', getUser()->id)->setOrderBy('name ASC')->get();
    $Template->output('tables/scheme_parts_overview', ['scheme_parts' => $available_scheme_parts, 'parent' => 'scheme', 'show_percentages_per_source' => true]);
}, compact('Template'), 'scheme_parts', getDefaultUniqueCacheData());
?>
		</div>
	</div>

	<button type="submit"><?php 
echo __('Save');
?>
</button>
</form>

<?php 
$Template->output('footer');