Source for file class.comment.php
Documentation is available at class.comment.php
* @package linea21.modules
* @author Simon Georget <simon@linea21.com>
* @license http://opensource.org/licenses/gpl-3.0.html
private $params = array();
public function __call($method, $arguments)
$event = $this->dispatcher->notifyUntil(new sfEvent($this, 'comment.extensible_function', array(
'arguments' => $arguments
if (!$event->isProcessed())
throw new Exception(sprintf('Call to undefined method %s::%s.', get_class($this), $method));
return $event->getReturnValue();
* comment::checkDataIntegrity()
* Vérification intégrité des données
* si verifié, sinon string 'message d'erreur'
$event = new sfEvent($this, 'comment.before_data_check');
$a = $event->getReturnValue();
if(!isset ($_COOKIE['linea21']['login'])) {
if (strlen($a['name']) < 3) return _t('comment','no_name');
if (strlen($a['email']) < 3) return _t('comment','no_email');
$result = $this->_checkEmailValidity($a['email']);
if (strlen($a['body']) < 3) return _t('comment','no_body');
$event = new sfEvent($this, 'comment.after_data_check', array('data' => $a));
* comment::_checkEmailValidity()
* return 1 si valide sinon message d'erreur (string)
function _checkEmailValidity($email)
return sprintf(_t('contact','email_error'), $email);
public function add($a, $sql_object) {
$a= $sql_object->DBescape($a);
if(COMMENT_MODERATION == 1) {
// if user is logged-in, do we moderate or not?
if(!empty($a['user_id']) && COMMENT_MODERATE_REGISTERED == 0) $a['status']= 'P';
$q = "INSERT INTO " . T_COMM . " (comment_module, comment_module_id, comment_user_id, comment_name, comment_email, comment_url, comment_body, comment_notification, comment_status, comment_date_crea) VALUES('" . $a['module'] . "', '" . $a['module_id'] . "', '" . $a['user_id'] . "', '" . $a['name'] . "', '" . $a['email'] . "', '" . $a['url'] . "', '" . $a['body'] . "', '" . $a['notification'] . "', '" . $a['status']. "', now());";
$last_id = $sql_object->DBInsert ($q, 1);
public function get($options, $sql_object) {
// we ensure there is no duplicate emails
if(!in_array($el['user_email'], $data)) {
* get all comments awaiting for moderation
public function getAllByModule($status, $sql_object, $limit = false, $sort = false) {
$tmp = $this->getByModule(array('module' => 'news', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
$tmp = $this->getByModule(array('module' => 'project', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
$tmp = $this->getByModule(array('module' => 'workgroups', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
$tmp = $this->getByModule(array('module' => 'report', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
$tmp = $this->getByModule(array('module' => 'files', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
$tmp = $this->getByModule(array('module' => 'indicator', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
if(MOD_PUBLICATION == 1) {
$tmp = $this->getByModule(array('module' => 'publication', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
$tmp = $this->getByModule(array('module' => 'contribute', 'status' => $status, 'limit' => $limit), $sql_object, 'module');
// on obtient une liste de colonnes
foreach ($r as $key => $row) {
$date[$key] = $row['comment_date_timestamp'];
// Tri des données par date décroissante
// Ajoute $r en tant que dernier paramètre, pour trier par la clé commune
public function isNew($id, $sql_object) {
$id = $sql_object->DBEscape($id);
$q = "SELECT comment_status FROM " . T_COMM . " WHERE comment_id = '". $id. "';";
$r = $sql_object->DBSelect($q);
if($r[0]['comment_status'] == 'D') {
$a = $sql_object->DBEscape($a);
$q = "SELECT U.user_id, P.profile_email FROM " . T_USER . " AS U LEFT OUTER JOIN " . T_PROFILE . " AS P ON P.profile_id = U.user_profile WHERE P.profile_email = '". $a['email']. "'";
$data = $sql_object->DBSelect($q);
if(count($data) > 0 && $data != 0) {
// we loop because (in theory) a user can have several accounts associtaed with one unique email
for($i= 0; $i < count($data); $i++ ) {
$q = "UPDATE ". T_COMM . " SET comment_notification = 'N' WHERE comment_module='". $a['module']. "' AND comment_module_id='". $a['module_id']. "' AND comment_status <> 'D' AND comment_user_id='". $data[$i]['user_id']. "'";
$r = $sql_object->DBQuery($q);
// if not registered user
$q = "UPDATE ". T_COMM . " SET comment_notification = 'N' WHERE comment_module='". $a['module']. "' AND comment_module_id='". $a['module_id']. "' AND comment_status <> 'D' AND comment_email='". $a['email']. "'";
$r = $sql_object->DBQuery($q);
public function delete($id, $sql_object) {
$id = $sql_object->DBEscape($id);
$q = "DELETE FROM ". T_COMM . " WHERE comment_id='". $id. "'";
$r = $sql_object->DBQuery($q);
$id = $sql_object->DBEscape($id);
$q = "UPDATE ". T_COMM . " SET comment_status = 'E' WHERE comment_id='". $id. "'";
$r = $sql_object->DBQuery($q);
public function approve($id, $sql_object) {
$id = $sql_object->DBEscape($id);
$q = "UPDATE ". T_COMM . " SET comment_status = 'P' WHERE comment_id='". $id. "'";
$r = $sql_object->DBQuery($q);
|