linea21-core
[ class tree: linea21-core ] [ index: linea21-core ] [ all elements ]

Source for file mysql.inc.php

Documentation is available at mysql.inc.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage comment
  5.  * @author Simon Georget <simon@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11.  
  12.   $q =    "SELECT COUNT(comment_id) AS nb FROM " . T_COMM . " WHERE comment_status='P' OR comment_status='D' OR comment_status='E';";
  13.  
  14.   return $q;
  15. }
  16.  
  17. function SQL_getCommentsNumber($a) {
  18.  
  19.   $q =    "SELECT COUNT(comment_id) AS nb FROM " . T_COMM . " WHERE comment_module='".$a['module']."' AND comment_module_id='".$a['module_id']."' AND comment_status='P';";
  20.  
  21.   return $q;
  22. }
  23.  
  24. function SQL_getComments($options) {
  25.  
  26.   $status = ' AND ';
  27.  
  28.   if(isset($options['status'])) {
  29.     for($i=0; $i < count($options['status']); $i++) {
  30.       if($i != 0) $prefix = ' OR '; else $prefix='(';
  31.       $status .= $prefix."comment_status='" . $options['status'][$i] . "'";
  32.     }
  33.     $status .= ')';
  34.   } else {
  35.     $status .="comment_status='P'";
  36.   }
  37.   if(isset($options['given_id'])) {
  38.     $given_id = " AND comment_id ='".$options['given_id']."'";
  39.   } else {
  40.     $given_id = '';
  41.   }
  42.   if(isset($options['module'])) {
  43.     $module_filter = " AND comment_module ='".$options['module']."' AND comment_module_id ='".$options['module_id']."'";
  44.   } else {
  45.     $module_filter = '';
  46.   }
  47.   isset($options['order_by']) ? $options['order_by'] =  $options['order_by'] : $options['order_by'] = 'DESC';
  48.  
  49.   $q =    "SELECT C.*, U.user_id, U.user_login, P.profile_avatar, ".
  50.             "UNIX_TIMESTAMP(C.comment_date_crea) AS comment_date_timestamp, ".
  51.             "DATE_FORMAT(C.comment_date_crea, '".toStringSqlDate('long')."') AS comment_date_crea_display ".
  52.             "FROM " . T_COMM . " AS C ".
  53.             "LEFT OUTER JOIN " . T_USER . " AS U ON C.comment_user_id = U.user_id ".
  54.             "LEFT OUTER JOIN " . T_PROFILE . " AS P ON P.profile_id = U.user_profile ".
  55.             "WHERE 1".$module_filter . $status . $given_id . " ORDER BY comment_date_crea ".$options['order_by']." ;";
  56.  
  57.   return $q;
  58. }
  59.  
  60. function SQL_getModuleComments($options) {
  61.  
  62.   switch ($options['module']) {
  63.     case 'news':
  64.       $q  = "LEFT OUTER JOIN " . T_NEWS . " AS N ON N.news_id = C.comment_module_id ";
  65.       $field = "N.news_title";
  66.       break;
  67.     case 'project':
  68.       $q  = "LEFT OUTER JOIN " . T_PROJECT . " AS PR ON PR.project_id = C.comment_module_id ";
  69.       $field = "PR.project_name";
  70.       break;
  71.     case 'workgroups':
  72.       $q  = "LEFT OUTER JOIN " . T_WORK . " AS W ON W.workshop_id = C.comment_module_id ";
  73.       $field = "W.workshop_denomination";
  74.       break;
  75.     case 'indicator':
  76.       $q  = "LEFT OUTER JOIN " . T_SDI_INFO . " AS S ON S.sdii_id = C.comment_module_id ";
  77.       $field = "S.sdii_name";
  78.       break;
  79.     case 'publication':
  80.       $q  = "LEFT OUTER JOIN " . T_PUBLI . " AS PU ON PU.publi_id = C.comment_module_id ";
  81.       $field = "PU.publi_title";
  82.       break;
  83.     case 'report':
  84.       $q  = "LEFT OUTER JOIN " . T_WORK_REP  . " AS R ON R.workrep_id = C.comment_module_id ";
  85.       $field = "R.workrep_title";
  86.       break;
  87.     case 'files':
  88.       $q  = "";
  89.       $field = "SUBSTRING_INDEX(C.comment_module_id, '/', -1)";
  90.       break;
  91.     case 'contribute':
  92.       $q  = "";
  93.       $field = "C.comment_module_id";
  94.       break;
  95.     default:
  96.       die($options['module'] . ' is not a valid option.');
  97.       break;
  98.   }
  99.   $status = ' AND ';
  100.  
  101.   if(isset($options['status'])) {
  102.     for($i=0; $i < count($options['status']); $i++) {
  103.       if($i != 0) $prefix = ' OR '; else $prefix='(';
  104.       $status .= $prefix."comment_status='" . $options['status'][$i] . "'";
  105.     }
  106.     $status .= ')';
  107.   } else {
  108.     $status .="comment_status='P'";
  109.   }
  110.   if(isset($options['given_id'])) {
  111.     $given_id = " AND comment_id='".$options['given_id']."'";
  112.   } else {
  113.     $given_id = '';
  114.   }
  115.   isset($options['order_by']) ? '' : $options['order_by'] = 'DESC';
  116.  
  117.   if(isset($options['limit']) && is_numeric($options['limit'])) {
  118.     isset($options['start']) ? $start = isset($options['start']) : $start = 0;
  119.     $limit = ' LIMIT '.$start.', '. $options['limit'];
  120.   } else {
  121.     $limit = '';
  122.   }
  123.  
  124.   $q =    "SELECT C.*, U.user_id, U.user_login, P.profile_avatar, ". $field ." AS item_title, ".
  125.             "UNIX_TIMESTAMP(C.comment_date_crea) AS comment_date_timestamp, ".
  126.             "DATE_FORMAT(C.comment_date_crea, '".toStringSqlDate('long')."') AS comment_date_crea_display ".
  127.             "FROM " . T_COMM . " AS C ".
  128.             "LEFT OUTER JOIN " . T_USER . " AS U ON C.comment_user_id = U.user_id ".
  129.             "LEFT OUTER JOIN " . T_PROFILE . " AS P ON P.profile_id = U.user_profile ".
  130.   $q .
  131.             "WHERE comment_module='".$options['module']."'" . $status . $given_id . " ORDER BY comment_date_crea ".$options['order_by']. $limit. " ;";
  132.  
  133.   return $q;
  134. }
  135.  
  136. function SQL_getRegisteredSubscribers($options) {
  137.   
  138.   $q =     "SELECT P.profile_email AS user_email FROM ". T_COMM . " AS C ".
  139.         "LEFT OUTER JOIN " . T_USER . " AS U ON C.comment_user_id = U.user_id ".
  140.         "LEFT OUTER JOIN " . T_PROFILE . " AS P ON P.profile_id = U.user_profile ".
  141.           "WHERE comment_module='".$options['module']."' AND comment_module_id='".$options['module_id']."' AND comment_email = '' AND comment_notification = 'Y' AND user_validity = 'Y';";
  142.   
  143.   return $q;
  144.   
  145. }
  146.  
  147. function SQL_getNonRegisteredSubscribers($options) {
  148.   
  149.   $q = "SELECT C.comment_email AS user_email FROM ". T_COMM . " AS C WHERE comment_module='".$options['module']."' AND comment_module_id='".$options['module_id']."' AND comment_email <> '' AND comment_status <> 'D' AND comment_notification = 'Y';";
  150.   
  151.   return $q;
  152.   
  153. }
  154.  
  155. function SQL_getUserInfo($id) {
  156.   
  157.   $q = "SELECT user_login, profile_email FROM ". T_USER . " AS U LEFT OUTER JOIN " . T_PROFILE . " AS P ON P.profile_id = U.user_profile WHERE user_id = '".$id."' ";
  158.   
  159.   return $q;
  160. }
  161.  
  162. function SQL_getCommentItem($options) {
  163.  
  164.   switch ($options['module']) {
  165.     case 'news':
  166.       $q  = "SELECT news_title AS item_title FROM " . T_NEWS . " WHERE news_id = '".$options['module_id']."';";
  167.       $field = "N.news_title";
  168.       break;
  169.     case 'project':
  170.       $q  = "SELECT project_name AS item_title FROM " . T_PROJECT . " WHERE project_id = '".$options['module_id']."';";
  171.       break;
  172.     case 'workgroups':
  173.       $q  = "SELECT workshop_denomination AS item_title FROM " . T_WORK . " WHERE workshop_id = '".$options['module_id']."';";
  174.       break;
  175.     case 'indicator':
  176.       $q  = "SELECT sdii_name AS item_title FROM " . T_SDI_INFO . " WHERE sdii_id = '".$options['module_id']."';";
  177.       break;
  178.     case 'publication':
  179.       $q  = "SELECT publi_title AS item_title FROM " . T_PUBLI . " WHERE publi_id = '".$options['module_id']."';";
  180.       break;
  181.     case 'report':
  182.       $q  = "SELECT workrep_title AS item_title FROM " . T_WORK_REP  . " WHERE workrep_id = '".$options['module_id']."';";
  183.       break;
  184.     case 'files':
  185.       $q =     "SELECT SUBSTRING_INDEX(comment_module_id, '/', -1) AS item_title FROM " . T_COMM . " WHERE comment_module_id = '".$options['module_id']."';";
  186.       break;
  187.     case 'contribute':
  188.       $q =     "SELECT comment_module_id AS item_title FROM " . T_COMM . " WHERE comment_module_id = '".$options['module_id']."';";
  189.       break;
  190.     default:
  191.       die($options['module'] . ' is not a valid option.');
  192.       break;
  193.   }
  194.   return $q;
  195.  
  196. }

Documentation generated on Thu, 03 May 2012 15:06:41 +0200 by phpDocumentor 1.4.1