2
0
forked from Wavyzz/dolibarr

Unified comment addition in OpenSurveySondage::addComment and removed duplicate code

This commit is contained in:
Marcos García de La Fuente
2014-01-03 16:38:02 +01:00
parent cf3ac246bf
commit 8727daeb77
3 changed files with 32 additions and 30 deletions

View File

@@ -44,6 +44,13 @@ if (GETPOST('id')) {
$object=new Opensurveysondage($db);
$result=$object->fetch(0, $numsondageadmin);
if ($result <= 0)
{
dol_print_error($db,$object->error);
exit;
}
$expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GETPOST('expireyear'));
@@ -74,12 +81,6 @@ if ($action == 'update')
$action = 'edit';
}
if (! $error)
{
$res=$object->fetch(0,$numsondageadmin);
if ($res < 0) dol_print_error($db,$object->error);
}
if (! $error)
{
$object->titre = GETPOST('nouveautitre');
@@ -120,10 +121,8 @@ if (GETPOST('ajoutcomment'))
$comment = GETPOST("comment");
$comment_user = GETPOST('commentuser');
$sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)";
$sql.= " VALUES ('".$db->escape($object->id_sondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')";
$resql = $db->query($sql);
dol_syslog("sql=".$sql);
$resql = $object->addComment($comment, $comment_user);
if (! $resql)
{
$err |= COMMENT_INSERT_FAILED;
@@ -146,13 +145,6 @@ if ($idcomment)
$form=new Form($db);
$result=$object->fetch(0, $numsondageadmin);
if ($result <= 0)
{
dol_print_error($db,$object->error);
exit;
}
$arrayofjs=array();
$arrayofcss=array('/opensurvey/css/style.css');
llxHeader('',$object->titre, 0, 0, 0, 0, $arrayofjs, $arrayofcss);

View File

@@ -542,5 +542,26 @@ class Opensurveysondage extends CommonObject
return $comments;
}
/**
* Adds a comment to the poll
*
* @param string $comment Comment content
* @param string $comment_user Comment author
* @return boolean False in case of the query fails, true if it was successful
*/
public function addComment($comment, $comment_user) {
$sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)";
$sql.= " VALUES ('".$this->db->escape($this->id_sondage)."','".$this->db->escape($comment)."','".$this->db->escape($comment_user)."')";
$resql = $this->db->query($sql);
dol_syslog("sql=".$sql);
if (!$resql) {
return false;
}
return true;
}
}
?>

View File

@@ -84,10 +84,8 @@ if (GETPOST('ajoutcomment'))
$comment = GETPOST("comment");
$comment_user = GETPOST('commentuser');
$sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment)";
$sql.= " VALUES ('".$db->escape($numsondage)."','".$db->escape($comment)."','".$db->escape($comment_user)."')";
$resql = $db->query($sql);
dol_syslog("sql=".$sql);
$resql = $object->addComment($comment, $comment_user);
if (! $resql) dol_print_error($db);
}
}
@@ -227,15 +225,6 @@ if ($idcomment)
*/
$form=new Form($db);
$object=new OpenSurveySondage($db);
$result=$object->fetch(0,$numsondage);
if ($result <= 0)
{
print $langs->trans("ErrorRecordNotFound");
llxFooterSurvey();
exit;
}
$arrayofjs=array();
$arrayofcss=array('/opensurvey/css/style.css');