|
2 | 2 |
|
3 | 3 | namespace BNETDocs\Templates\Packet; |
4 | 4 |
|
5 | | -use \BNETDocs\Libraries\Product; |
6 | | - |
7 | 5 | use \CarlBennett\MVC\Libraries\Common; |
8 | 6 | use \CarlBennett\MVC\Libraries\Pair; |
9 | 7 |
|
@@ -85,21 +83,29 @@ require('./header.inc.phtml'); |
85 | 83 | ?></textarea> |
86 | 84 | </section> |
87 | 85 | <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> |
103 | 109 | </section> |
104 | 110 | <section> |
105 | 111 | <label for="remarks">Remarks:</label> |
|
0 commit comments