public function listenerUpdateTabella() { $idTabella = $_POST['id-tabella']; foreach ($_POST as $key => $value) { if (strpos($key, 'cella') !== FALSE) { $temp = explode('-', $key); $row = $temp[1]; $col = $temp[2]; $prezzo = new Prezzo(); $prezzo->setIdTabella($idTabella); $prezzo->setValCol($col); $prezzo->setValRow($row); $prezzo->setPrezzo($value); if (!$this->tPrezzi->updatePrezzoArticolo($prezzo)) { echo '<p class="error">Errore!</p>'; } } } }
private function getArrayPrezzi($array) { $result = array(); foreach ($array as $item) { $prezzo = new Prezzo(); $prezzo->setIdTabella($item->id_tabella); $prezzo->setValRow($item->val_row); $prezzo->setValCol($item->val_col); $prezzo->setPrezzo($item->prezzo); array_push($result, $prezzo); } return $result; }
/** * Funzione che aggiorna il valore di un prezzo nelle tabelle * @param type $idTabella * @param Prezzo $prezzo * @return boolean */ public function updatePrezzo(Prezzo $prezzo) { try { $this->wpdb->update($this->table_prezzi, array('prezzo' => $prezzo->getPrezzo()), array('id_tabella' => $prezzo->getIdTabella(), 'val_row' => $prezzo->getValRow(), 'val_col' => $prezzo->getValCol()), array('%f'), array('%d', '%d', '%d')); return true; } catch (Exception $ex) { _e($ex); return false; } }