Skip to content

Commit 357dbd8

Browse files
committed
Fix used by table in packet edit template
1 parent fb1de7d commit 357dbd8

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

src/controllers/Packet/Edit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function &run(Router &$router, View &$view, array &$args) {
3737
$model->name = null;
3838
$model->packet = null;
3939
$model->packet_id = (isset($data["id"]) ? $data["id"] : null);
40+
$model->products = Product::getAllProducts();
4041
$model->published = null;
4142
$model->remarks = null;
4243
$model->used_by = null;

src/models/Packet/Edit.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class Edit extends Model {
1616
public $name;
1717
public $packet;
1818
public $packet_id;
19+
public $products;
1920
public $published;
2021
public $remarks;
2122
public $used_by;

src/templates/Packet/Edit.phtml

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace BNETDocs\Templates\Packet;
44

5-
use \BNETDocs\Libraries\Product;
6-
75
use \CarlBennett\MVC\Libraries\Common;
86
use \CarlBennett\MVC\Libraries\Pair;
97

@@ -85,21 +83,29 @@ require('./header.inc.phtml');
8583
?></textarea>
8684
</section>
8785
<section>
88-
<label for="usedby">Used by:</label>
89-
<table><?php
90-
$all_products = Product::getAllProducts();
91-
$used_by = $this->getContext()->used_by;
92-
$j = count($all_products);
93-
for ($i = 0; $i < $j; ++$i) { ?>
94-
<tr><td><input type="checkbox" name="used_by[]" value="<?php
95-
echo $all_products[$i]->getBnetProductId() . "\"" . ($used_by !== null && in_array($all_products[$i], $used_by) ? " checked> " : "> ") . filter_var($all_products[$i]->getLabel(), FILTER_SANITIZE_STRING) . "</td><td>";
96-
if ($i + 1 < $j) {
97-
++$i;
98-
?><input type="checkbox" name="used_by[]" value="<?php
99-
echo $all_products[$i]->getBnetProductId() . "\"" . ($used_by !== null && in_array($all_products[$i], $used_by) ? " checked> " : "> ") . filter_var($all_products[$i]->getLabel(), FILTER_SANITIZE_STRING); ?></td></tr>
100-
<?php }
101-
} ?>
102-
</table>
86+
<label for="usedby">Used by:</label>
87+
<table>
88+
<thead></thead><tbody>
89+
<?php function add_product_checkbox( $id, $name, $checked ) { ?>
90+
<td><input type="checkbox" id="<?php echo $id; ?>" name="used_by[]" value="<?php echo $id; ?>"<?php if ( $checked ) { ?> checked="checked"<?php } ?>/><label for="<?php echo $id; ?>"><?php echo $name; ?></label></td>
91+
<?php }
92+
$product_ubound = count( $this->getContext()->products );
93+
for ( $product_i = 0; $product_i < $product_ubound; ++$product_i ) {
94+
$p = $this->getContext()->products[ $product_i ];
95+
?>
96+
<tr>
97+
<?php
98+
$checked = isset( $this->getContext()->used_by[ $p->getBnetProductId() ]);
99+
add_product_checkbox( $p->getBnetProductId(), $p->getLabel(), $checked );
100+
if ( $product_i + 1 < $product_ubound ) {
101+
$p = $this->getContext()->products[ ++$product_i ];
102+
$checked = isset( $this->getContext()->used_by[ $p->getBnetProductId() ]);
103+
add_product_checkbox( $p->getBnetProductId(), $p->getLabel(), $checked );
104+
} ?>
105+
</tr>
106+
<?php } ?>
107+
</tbody>
108+
</table>
103109
</section>
104110
<section>
105111
<label for="remarks">Remarks:</label>

0 commit comments

Comments
 (0)