/** * Enregistrement des données d'un DAO * * @param array $data * @param array $allowedFields Les champs à considérer (prend le pas sur la méthode getAllowedFields()) * @param bool $debug * @return int */ public function save(array $data, array $allowedFields = null, $debug = false) { if ($debug) { echo 'Données envoyées:'; echo '<pre>'; print_r($data); echo '</pre>'; if ($allowedFields) { echo 'Champs autorisés:'; echo '<pre>'; print_r($allowedFields); echo '</pre>'; } } // filter $data against the allowed fields array if ($allowedFields && is_array($allowedFields) && count($allowedFields) > 0) { $allowedFields = array_intersect($allowedFields, $this->getAllowedFields()); } else { $allowedFields = $this->getAllowedFields(); } $filtered_data = array_intersect_key($data, array_flip($allowedFields)); if (isset($filtered_data['id']) && !$filtered_data['id']) { unset($filtered_data['id']); } if ($debug) { echo 'Données filtrées:'; echo '<pre>'; print_r($filtered_data); echo '</pre>'; } // Check if there is still some data to save... if (array_key_exists('id', $filtered_data) && count($filtered_data) > 1 || !array_key_exists('id', $filtered_data) && count($filtered_data) > 0) { return $this->query->save($this->t(), $filtered_data, $debug); } return true; }