| @@ 191-234 (lines=44) @@ | ||
| 188 | * |
|
| 189 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 190 | */ |
|
| 191 | public function insert(XoopsObject $assessment_perguntas, $force = false) |
|
| 192 | { |
|
| 193 | global $xoopsConfig; |
|
| 194 | if (get_class($assessment_perguntas) != 'assessment_perguntas') { |
|
| 195 | return false; |
|
| 196 | } |
|
| 197 | if (!$assessment_perguntas->isDirty()) { |
|
| 198 | return true; |
|
| 199 | } |
|
| 200 | if (!$assessment_perguntas->cleanVars()) { |
|
| 201 | return false; |
|
| 202 | } |
|
| 203 | foreach ($assessment_perguntas->cleanVars as $k => $v) { |
|
| 204 | ${$k} = $v; |
|
| 205 | } |
|
| 206 | $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)'; |
|
| 207 | if ($assessment_perguntas->isNew()) { |
|
| 208 | // ajout/modification d'un assessment_perguntas |
|
| 209 | $assessment_perguntas = new assessment_perguntas(); |
|
| 210 | $format = 'INSERT INTO %s (cod_pergunta, cod_prova, titulo, data_criacao, data_update, uid_elaborador,ordem)'; |
|
| 211 | $format .= 'VALUES (%u, %u, %s, %s, %s, %s, %u)'; |
|
| 212 | $sql = sprintf($format, $this->db->prefix('assessment_perguntas'), $cod_pergunta, $cod_prova, $this->db->quoteString($titulo), $now, $now, $this->db->quoteString($uid_elaborador), $ordem); |
|
| 213 | $force = true; |
|
| 214 | } else { |
|
| 215 | $format = 'UPDATE %s SET '; |
|
| 216 | $format .= 'cod_pergunta=%u, cod_prova=%u, titulo=%s, data_criacao=%s, data_update=%s, uid_elaborador=%s, ordem=%u'; |
|
| 217 | $format .= ' WHERE cod_pergunta = %u'; |
|
| 218 | $sql = sprintf($format, $this->db->prefix('assessment_perguntas'), $cod_pergunta, $cod_prova, $this->db->quoteString($titulo), $now, $now, $this->db->quoteString($uid_elaborador), $ordem, $cod_pergunta); |
|
| 219 | } |
|
| 220 | if (false != $force) { |
|
| 221 | $result = $this->db->queryF($sql); |
|
| 222 | } else { |
|
| 223 | $result = $this->db->query($sql); |
|
| 224 | } |
|
| 225 | if (!$result) { |
|
| 226 | return false; |
|
| 227 | } |
|
| 228 | if (empty($cod_pergunta)) { |
|
| 229 | $cod_pergunta = $this->db->getInsertId(); |
|
| 230 | } |
|
| 231 | $assessment_perguntas->assignVar('cod_pergunta', $cod_pergunta); |
|
| 232 | ||
| 233 | return true; |
|
| 234 | } |
|
| 235 | ||
| 236 | /** |
|
| 237 | * delete a assessment_perguntas from the database |
|
| @@ 184-227 (lines=44) @@ | ||
| 181 | * |
|
| 182 | * @return bool FALSE if failed, TRUE if already present and unchanged or successful |
|
| 183 | */ |
|
| 184 | public function insert(XoopsObject $assessment_respostas, $force = false) |
|
| 185 | { |
|
| 186 | global $xoopsConfig; |
|
| 187 | if (get_class($assessment_respostas) != 'assessment_respostas') { |
|
| 188 | return false; |
|
| 189 | } |
|
| 190 | if (!$assessment_respostas->isDirty()) { |
|
| 191 | return true; |
|
| 192 | } |
|
| 193 | if (!$assessment_respostas->cleanVars()) { |
|
| 194 | return false; |
|
| 195 | } |
|
| 196 | foreach ($assessment_respostas->cleanVars as $k => $v) { |
|
| 197 | ${$k} = $v; |
|
| 198 | } |
|
| 199 | $now = 'date_add(now(), interval ' . $xoopsConfig['server_TZ'] . ' hour)'; |
|
| 200 | if ($assessment_respostas->isNew()) { |
|
| 201 | // ajout/modification d'un assessment_respostas |
|
| 202 | $assessment_respostas = new assessment_respostas(); |
|
| 203 | $format = 'INSERT INTO %s (cod_resposta, cod_pergunta, titulo, iscerta, data_criacao, data_update, uid_elaboradores, isativa)'; |
|
| 204 | $format .= 'VALUES (%u, %u, %s, %u, %s, %s, %s, %u)'; |
|
| 205 | $sql = sprintf($format, $this->db->prefix('assessment_respostas'), $cod_resposta, $cod_pergunta, $this->db->quoteString($titulo), $iscerta, $now, $now, $this->db->quoteString($uid_elaboradores), $isativa); |
|
| 206 | $force = true; |
|
| 207 | } else { |
|
| 208 | $format = 'UPDATE %s SET '; |
|
| 209 | $format .= 'cod_resposta=%u, cod_pergunta=%u, titulo=%s, iscerta=%u, data_criacao=%s, data_update=%s, uid_elaboradores=%s, isativa=%u'; |
|
| 210 | $format .= ' WHERE cod_resposta = %u'; |
|
| 211 | $sql = sprintf($format, $this->db->prefix('assessment_respostas'), $cod_resposta, $cod_pergunta, $this->db->quoteString($titulo), $iscerta, $now, $now, $this->db->quoteString($uid_elaboradores), $isativa, $cod_resposta); |
|
| 212 | } |
|
| 213 | if (false != $force) { |
|
| 214 | $result = $this->db->queryF($sql); |
|
| 215 | } else { |
|
| 216 | $result = $this->db->query($sql); |
|
| 217 | } |
|
| 218 | if (!$result) { |
|
| 219 | return false; |
|
| 220 | } |
|
| 221 | if (empty($cod_resposta)) { |
|
| 222 | $cod_resposta = $this->db->getInsertId(); |
|
| 223 | } |
|
| 224 | $assessment_respostas->assignVar('cod_resposta', $cod_resposta); |
|
| 225 | ||
| 226 | return true; |
|
| 227 | } |
|
| 228 | ||
| 229 | /** |
|
| 230 | * delete a assessment_respostas from the database |
|