@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | public function __construct(\DoliDB $db, $tableName) |
| 24 | 24 | { |
| 25 | 25 | $this->db = $db; |
| 26 | - $this->tableName = strpos($tableName, MAIN_DB_PREFIX) === 0 ? $tableName : MAIN_DB_PREFIX.$tableName; |
|
| 26 | + $this->tableName = strpos($tableName, MAIN_DB_PREFIX) === 0 ? $tableName : MAIN_DB_PREFIX . $tableName; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @throws \Exception |
| 35 | 35 | */ |
| 36 | - protected function write(array $elements){ |
|
| 36 | + protected function write(array $elements) { |
|
| 37 | 37 | $columns = join(',', array_keys($elements)); |
| 38 | 38 | $values = join(',', array_map([$this, 'escape'], array_values($elements))); |
| 39 | 39 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $lasterror = $this->db->lasterror(); |
| 45 | 45 | dol_syslog(__METHOD__ . ' ' . $lasterror, LOG_ERR); |
| 46 | 46 | $this->db->rollback(); |
| 47 | - throw new \Exception("Repository error - ".$lasterror); |
|
| 47 | + throw new \Exception("Repository error - " . $lasterror); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $id = $this->db->last_insert_id($this->tableName); |
@@ -57,16 +57,16 @@ discard block |
||
| 57 | 57 | * |
| 58 | 58 | * @return int|string|null |
| 59 | 59 | */ |
| 60 | - private function escape($value){ |
|
| 61 | - if(is_null($value)){ |
|
| 60 | + private function escape($value) { |
|
| 61 | + if (is_null($value)) { |
|
| 62 | 62 | return null; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - if(is_bool($value)){ |
|
| 66 | - return (int)$value; |
|
| 65 | + if (is_bool($value)) { |
|
| 66 | + return (int) $value; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - return is_string($value) ? $this->db->escape($value) : $value ; |
|
| 69 | + return is_string($value) ? $this->db->escape($value) : $value; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -79,18 +79,18 @@ discard block |
||
| 79 | 79 | { |
| 80 | 80 | $sqlModifications = []; |
| 81 | 81 | |
| 82 | - foreach($elements as $field => $value){ |
|
| 82 | + foreach ($elements as $field => $value) { |
|
| 83 | 83 | $sqlModifications[] = sprintf('%s=%s', $field, $this->escape($value)); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | $this->db->begin(); |
| 87 | - $resql = $this->db->query(sprintf('UPDATE %s SET %s WHERE rowid = %s ', $this->tableName, join(',',$sqlModifications), $id)); |
|
| 87 | + $resql = $this->db->query(sprintf('UPDATE %s SET %s WHERE rowid = %s ', $this->tableName, join(',', $sqlModifications), $id)); |
|
| 88 | 88 | |
| 89 | 89 | if (!$resql) { |
| 90 | 90 | $lasterror = $this->db->lasterror(); |
| 91 | 91 | dol_syslog(__METHOD__ . ' ' . $lasterror, LOG_ERR); |
| 92 | 92 | $this->db->rollback(); |
| 93 | - throw new \Exception("Repository error - ".$lasterror); |
|
| 93 | + throw new \Exception("Repository error - " . $lasterror); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | $this->db->commit(); |
@@ -103,8 +103,8 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return array|null |
| 105 | 105 | */ |
| 106 | - protected function get($id){ |
|
| 107 | - $sql = sprintf('SELECT * FROM %s WHERE rowid = %s', $this->tableName, $id ); |
|
| 106 | + protected function get($id) { |
|
| 107 | + $sql = sprintf('SELECT * FROM %s WHERE rowid = %s', $this->tableName, $id); |
|
| 108 | 108 | |
| 109 | 109 | $resql = $this->db->query($sql); |
| 110 | 110 | if (!$resql) { |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | return null; |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - for($i = 0; $i < $num ; $i++) { |
|
| 119 | + for ($i = 0; $i < $num; $i++) { |
|
| 120 | 120 | return $this->db->fetch_array($resql); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -31,15 +31,15 @@ |
||
| 31 | 31 | public function __invoke($flightId) |
| 32 | 32 | { |
| 33 | 33 | $sql = 'SELECT damage.rowid as id, damage.amount, author.login as author_name, damage.billed as invoiced'; |
| 34 | - $sql.=' FROM '.MAIN_DB_PREFIX.'bbc_flight_damages as damage'; |
|
| 35 | - $sql.=' INNER JOIN '.MAIN_DB_PREFIX.'user as author ON author.rowid = damage.author_id'; |
|
| 36 | - $sql.=' WHERE damage.flight_id = '.$this->db->escape($flightId); |
|
| 34 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'bbc_flight_damages as damage'; |
|
| 35 | + $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'user as author ON author.rowid = damage.author_id'; |
|
| 36 | + $sql .= ' WHERE damage.flight_id = ' . $this->db->escape($flightId); |
|
| 37 | 37 | |
| 38 | 38 | $resql = $this->db->query($sql); |
| 39 | 39 | if ($resql) { |
| 40 | 40 | $num = $this->db->num_rows($resql); |
| 41 | 41 | if ($num) { |
| 42 | - for($i = 0; $i < $num ; $i++) { |
|
| 42 | + for ($i = 0; $i < $num; $i++) { |
|
| 43 | 43 | $properties = $this->db->fetch_array($resql); |
| 44 | 44 | yield Damage::fromArray($properties); |
| 45 | 45 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | 'author_id' => $flightDamage->getAuthor()->getId() |
| 36 | 36 | ]; |
| 37 | 37 | |
| 38 | - if($flightDamage->getId()){ |
|
| 38 | + if ($flightDamage->getId()) { |
|
| 39 | 39 | $this->update($flightDamage->getId()->getId(), $fields); |
| 40 | 40 | return; |
| 41 | 41 | } |
@@ -50,10 +50,10 @@ discard block |
||
| 50 | 50 | * |
| 51 | 51 | * @throws \Exception |
| 52 | 52 | */ |
| 53 | - public function getById(DamageId $id){ |
|
| 53 | + public function getById(DamageId $id) { |
|
| 54 | 54 | $damage = $this->get($id->getId()); |
| 55 | 55 | |
| 56 | - if(null === $damage){ |
|
| 56 | + if (null === $damage) { |
|
| 57 | 57 | throw new \Exception('Damage not found'); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -39,11 +39,11 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | private function __construct(FlightId $flightId, DamageAmount $amount, $billed, AuthorId $authorId, DamageId $id = null) |
| 41 | 41 | { |
| 42 | - $this->flight = $flightId; |
|
| 43 | - $this->amount = $amount; |
|
| 44 | - $this->billed = $billed; |
|
| 45 | - $this->author = $authorId; |
|
| 46 | - $this->id = $id; |
|
| 42 | + $this->flight = $flightId; |
|
| 43 | + $this->amount = $amount; |
|
| 44 | + $this->billed = $billed; |
|
| 45 | + $this->author = $authorId; |
|
| 46 | + $this->id = $id; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @return FlightDamage |
| 57 | 57 | */ |
| 58 | - public static function load(FlightId $flightId, DamageAmount $amount, $billed, AuthorId $authorId, DamageId $id = null){ |
|
| 58 | + public static function load(FlightId $flightId, DamageAmount $amount, $billed, AuthorId $authorId, DamageId $id = null) { |
|
| 59 | 59 | return new self($flightId, $amount, $billed, $authorId, $id); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @return FlightDamage |
| 68 | 68 | */ |
| 69 | - public static function damage(FlightId $flightId, DamageAmount $amount, AuthorId $authorId){ |
|
| 69 | + public static function damage(FlightId $flightId, DamageAmount $amount, AuthorId $authorId) { |
|
| 70 | 70 | return new self($flightId, $amount, false, $authorId); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | /** |
| 82 | 82 | * @return FlightId |
| 83 | 83 | */ |
| 84 | - public function getFlightId(){ |
|
| 84 | + public function getFlightId() { |
|
| 85 | 85 | return $this->flight; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
| 89 | 89 | * @return DamageAmount |
| 90 | 90 | */ |
| 91 | - public function amount(){ |
|
| 91 | + public function amount() { |
|
| 92 | 92 | return $this->amount; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | * |
| 106 | 106 | * @return FlightDamage |
| 107 | 107 | */ |
| 108 | - public function invoice(){ |
|
| 108 | + public function invoice() { |
|
| 109 | 109 | return new self($this->flight, $this->amount, true, $this->author, $this->id); |
| 110 | 110 | } |
| 111 | 111 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | $url = sprintf('%s/flightlog/card_tab_damage.php?id=%s&damage=%s', DOL_URL_ROOT, $flightId, $currentDamageId); |
| 59 | 59 | |
| 60 | - $html = $form->formconfirm($url, 'êtes-vous sure de vouloir marquer ce dégât comme facturé?', '','confirm_bill_damage'); |
|
| 60 | + $html = $form->formconfirm($url, 'êtes-vous sure de vouloir marquer ce dégât comme facturé?', '', 'confirm_bill_damage'); |
|
| 61 | 61 | |
| 62 | 62 | $this->renderHtml($html); |
| 63 | 63 | } |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | $currentDamageId = $this->request->getParam('damage'); |
| 69 | 69 | $confirmation = $this->request->getParam('confirm'); |
| 70 | 70 | |
| 71 | - if(!$this->request->isPost() || $confirmation === 'no'){ |
|
| 72 | - $this->redirect($_SERVER["PHP_SELF"].'?id='.$flightId); |
|
| 71 | + if (!$this->request->isPost() || $confirmation === 'no') { |
|
| 72 | + $this->redirect($_SERVER["PHP_SELF"] . '?id=' . $flightId); |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | $this->getInvoiceDamageCommandHandler()->__invoke(new InvoiceDamageCommand($currentDamageId)); |
| 77 | - $this->redirect($_SERVER["PHP_SELF"].'?id='.$flightId); |
|
| 77 | + $this->redirect($_SERVER["PHP_SELF"] . '?id=' . $flightId); |
|
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | \ No newline at end of file |
@@ -24,19 +24,19 @@ |
||
| 24 | 24 | $this->request = new Request(); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | - protected function render($template, array $variables = []){ |
|
| 27 | + protected function render($template, array $variables = []) { |
|
| 28 | 28 | |
| 29 | - foreach($variables as $variableName => $variableValue){ |
|
| 29 | + foreach ($variables as $variableName => $variableValue) { |
|
| 30 | 30 | $GLOBALS[$variableName] = $variableValue; |
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - return include __DIR__.'/../templates/'.$template; |
|
| 33 | + return include __DIR__ . '/../templates/' . $template; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @param string $html |
| 38 | 38 | */ |
| 39 | - protected function renderHtml($html){ |
|
| 39 | + protected function renderHtml($html) { |
|
| 40 | 40 | print $html; |
| 41 | 41 | } |
| 42 | 42 | |
@@ -14,21 +14,21 @@ |
||
| 14 | 14 | <td>Montant</td> |
| 15 | 15 | </tr> |
| 16 | 16 | <?php $total = 0; ?> |
| 17 | - <?php foreach($damages as $currentDamage):?> |
|
| 17 | + <?php foreach ($damages as $currentDamage):?> |
|
| 18 | 18 | <?php $total += $currentDamage->getAmount(); ?> |
| 19 | 19 | <tr> |
| 20 | - <td><?php echo $currentDamage->getAuthorName();?></td> |
|
| 21 | - <td><?php echo $currentDamage->getAmount();?>€</td> |
|
| 20 | + <td><?php echo $currentDamage->getAuthorName(); ?></td> |
|
| 21 | + <td><?php echo $currentDamage->getAmount(); ?>€</td> |
|
| 22 | 22 | <td> |
| 23 | - <?php if($currentDamage->isInvoiced()): ?> |
|
| 23 | + <?php if ($currentDamage->isInvoiced()): ?> |
|
| 24 | 24 | <i class="fas fa-check"></i> |
| 25 | 25 | <?php else: ?> |
| 26 | 26 | <i class="fas fa-times"></i> |
| 27 | 27 | <?php endif; ?> |
| 28 | 28 | </td> |
| 29 | 29 | <td> |
| 30 | - <?php if(!$currentDamage->isInvoiced()): ?> |
|
| 31 | - <a href="<?php print sprintf('%s/flightlog/card_tab_damage.php?id=%s&action=%s&damage=%s', DOL_URL_ROOT, $flightId, 'bill_damage', $currentDamage->getId());?>"><i class="fas fa-file-invoice"></i></a> |
|
| 30 | + <?php if (!$currentDamage->isInvoiced()): ?> |
|
| 31 | + <a href="<?php print sprintf('%s/flightlog/card_tab_damage.php?id=%s&action=%s&damage=%s', DOL_URL_ROOT, $flightId, 'bill_damage', $currentDamage->getId()); ?>"><i class="fas fa-file-invoice"></i></a> |
|
| 32 | 32 | <?php endif; ?> |
| 33 | 33 | </td> |
| 34 | 34 | </tr> |
@@ -22,9 +22,12 @@ |
||
| 22 | 22 | <td> |
| 23 | 23 | <?php if($currentDamage->isInvoiced()): ?> |
| 24 | 24 | <i class="fas fa-check"></i> |
| 25 | - <?php else: ?> |
|
| 25 | + <?php else { |
|
| 26 | + : ?> |
|
| 26 | 27 | <i class="fas fa-times"></i> |
| 27 | - <?php endif; ?> |
|
| 28 | + <?php endif; |
|
| 29 | +} |
|
| 30 | +?> |
|
| 28 | 31 | </td> |
| 29 | 32 | <td> |
| 30 | 33 | <?php if(!$currentDamage->isInvoiced()): ?> |