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

Source for file pgsql.inc.php

Documentation is available at pgsql.inc.php

  1. <?php
  2. /**
  3.  * @package linea21.core
  4.  * @subpackage search
  5.  * @author linea21 <info@linea21.com>
  6.  * @version $id SVN
  7.  * @access public
  8.  * @license http://opensource.org/licenses/gpl-3.0.html
  9.  */
  10.  
  11. /**
  12.  * SQL_comment_search()
  13.  *
  14.  * @param string $string 
  15.  * @param string $type 
  16.  * @return string $q
  17.  */
  18. function SQL_comment_search($string, $type)
  19. {
  20.  
  21.   if ($type == 'PUBLIC') {
  22.     $status_mask = " AND comment_status = 'P' ";
  23.   }
  24.   if ($type == 'ADMIN') {
  25.     $status_mask = '';
  26.   }
  27.  
  28.   $q =    "SELECT C.*, U.user_id, U.user_login, ".
  29.         "to_char(C.comment_date_crea, '".toStringSqlDate('long')."') AS date_display, ".
  30.         "to_char(rank(idxfti, q)*100, \'99.99\') AS pertinence FROM " . T_COMM . " AS C ".
  31.         "LEFT OUTER JOIN " . T_USER . " AS U ON C.comment_user_id = U.user_id ".
  32.         "LEFT OUTER JOIN " . T_PROFILE . " AS P ON P.profile_id = U.user_profile ".
  33.           "to_tsquery(\'default\', \''.$string.'\') as q WHERE idxfti @@ q ".
  34.         $status_mask . " ORDER BY rank(idxfti, q) DESC;";
  35.  
  36.   return $q;
  37. }
  38.  
  39. /**
  40.  * SQL_project_search()
  41.  *
  42.  * @param string $string 
  43.  * @param string $type 
  44.  * @return string $q
  45.  */
  46. function SQL_project_search($string, $type)
  47. {
  48.  
  49.   if ($type == 'PUBLIC') {
  50.     $date = 'project_published_date';
  51.     $statut_mask = 'AND project_statut<>\'E\' AND project_statut<>\'AA\' AND project_statut<>\'D\'';
  52.   }
  53.   if ($type == 'ADMIN') {
  54.     $date = 'project_date_crea';
  55.     $statut_mask = 'AND project_statut<>\'E\'';
  56.   }
  57.   $q = 'SELECT project_id, project_name, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, project_statut AS statut, to_char(rank(idxfti, q)*100, \'99.99\') AS pertinence FROM ' . T_PROJECT . ', to_tsquery(\'default\', \''.$string.'\') as q WHERE idxfti @@ q '. $statut_mask . ' ORDER BY rank(idxfti, q) DESC;';
  58.  
  59.   return $q;
  60. }
  61.  
  62. /**
  63.  * SQL_news_search()
  64.  *
  65.  * @param string $string 
  66.  * @param string $type 
  67.  * @return string $q
  68.  */
  69. function SQL_news_search($string, $type)
  70. {
  71.   if ($type == 'PUBLIC') {
  72.     $date = 'news_published_date';
  73.     $statut_mask = 'AND news_statut<>\'E\' AND news_statut<>\'AA\' AND news_statut<>\'D\'';
  74.   }
  75.   if ($type == 'ADMIN') {
  76.     $date = 'news_date_crea';
  77.     $statut_mask = 'AND news_statut<>\'E\'';
  78.   }
  79.   $q = 'SELECT news_id, news_title, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, news_statut AS statut, to_char(rank(idxfti, q)*100, \'99.99\') AS pertinence FROM ' . T_NEWS . ', to_tsquery(\'default\', \''.$string.'\') as q WHERE idxfti @@ q '. $statut_mask . ' ORDER BY rank(idxfti, q) DESC;';
  80.  
  81.   return $q;
  82. }
  83.  
  84. /**
  85.  * SQL_newsletter_search()
  86.  *
  87.  * @param string $string 
  88.  * @param string $type 
  89.  * @return string $q
  90.  */
  91. function SQL_newsletter_search($string, $type)
  92. {
  93.   if ($type == 'PUBLIC') {
  94.     $date = 'newsletter_published_date';
  95.     $statut_mask = 'AND newsletter_statut<>\'E\' AND newsletter_statut<>\'D\'';
  96.   }
  97.   if ($type == 'ADMIN') {
  98.     $date = 'newsletter_date_crea';
  99.     $statut_mask = 'AND newsletter_statut<>\'E\'';
  100.   }
  101.   $q = 'SELECT newsletter_id, newsletter_title, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, newsletter_statut AS statut, to_char(rank(idxfti, q)*100, \'99.99\') AS pertinence FROM ' . T_NEWSLETTER . ', to_tsquery(\'default\', \''.$string.'\') as q WHERE idxfti @@ q '. $statut_mask . ' ORDER BY rank(idxfti, q) DESC;';
  102.  
  103.   return $q;
  104. }
  105.  
  106. /**
  107.  * SQL_publication_search()
  108.  *
  109.  * @param string $string 
  110.  * @param string $type 
  111.  * @return string $q
  112.  */
  113. function SQL_publication_search($string, $type)
  114. {
  115.   if ($type == 'PUBLIC') {
  116.     $date = 'publi_published_date';
  117.     $statut_mask = 'AND publi_statut<>\'E\' AND publi_statut<>\'AA\' AND publi_statut<>\'D\'';
  118.   }
  119.   if ($type == 'ADMIN') {
  120.     $date = 'publi_date_crea';
  121.     $statut_mask = 'AND publi_statut<>\'E\'';
  122.   }
  123.   $q = 'SELECT publi_id, publi_title, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, publi_statut AS statut, to_char(rank(idxfti, q)*100, \'99.99\') AS pertinence FROM ' . T_PUBLI . ', to_tsquery(\'default\', \''.$string.'\') as q WHERE idxfti @@ q AND publi_statut<>\'E\' ' . $statut_mask . ' ORDER BY rank(idxfti, q) DESC;';
  124.  
  125.   return $q;
  126. }
  127.  
  128. /**
  129.  * SQL_publication_content_search()
  130.  *
  131.  * @param string $string 
  132.  * @param string $type 
  133.  * @return string $q
  134.  */
  135. function SQL_publication_content_search($string, $type)
  136. {
  137.   if ($type == 'PUBLIC') {
  138.     $date = 'publi_published_date';
  139.     $statut_mask = 'AND publi_statut<>\'E\' AND publi_statut<>\'AA\' AND publi_statut<>\'D\' AND publicon_validity=\'Y\'';
  140.   }
  141.   if ($type == 'ADMIN') {
  142.     $date = 'publi_date_crea';
  143.     $statut_mask = 'AND publi_statut<>\'E\' AND publicon_validity=\'Y\'';
  144.   }
  145.   $q = 'SELECT publi_id, publi_title, publicon_id, publicon_title, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, publi_statut AS statut, to_char(rank(pc.idxfti, q)*100, \'99.99\') AS pertinence FROM to_tsquery(\'default\', \''.$string.'\') as q, ' . J_PARTS . ' LEFT OUTER JOIN ' . T_PUBLI_CONT . ' AS pc ON j_parts_id  =  publicon_id LEFT OUTER JOIN  ' . T_PUBLI . ' AS p ON  j_root_id= publi_id WHERE pc.idxfti @@ q AND j_type=\'P\' ' . $statut_mask . ' ORDER BY rank(pc.idxfti, q) DESC;';
  146.  
  147.   return $q;
  148. }
  149.  
  150. /**
  151.  * SQL_sdi_search()
  152.  *
  153.  * @param string $string 
  154.  * @param string $type 
  155.  * @return string $q
  156.  */
  157. function SQL_sdi_search($string, $type)
  158. {
  159.   if ($type == 'PUBLIC') {
  160.     $statut_mask = 'AND sdii_statut<>\'D\' AND sdii_statut<>\'E\'';
  161.   }
  162.   if ($type == 'ADMIN') {
  163.     $statut_mask = 'AND sdii_statut<>\'E\'';
  164.   }
  165.   $q = 'SELECT sdii_id, sdii_name, to_char(sdii_date_crea, \''.toStringSqlDate().'\') AS date_display, sdii_statut AS statut, to_char(rank(idxfti, q)*100, \'99.99\') AS pertinence FROM ' . T_SDI_INFO . ', to_tsquery(\'default\', \''.$string.'\') as q  WHERE idxfti @@ q ' . $statut_mask . ' ORDER BY rank(idxfti, q) DESC;';
  166.  
  167.   return $q;
  168. }
  169.  
  170. /**
  171.  * SQL_workshop_search()
  172.  *
  173.  * @param string $string 
  174.  * @param string $type 
  175.  * @return string $q
  176.  */
  177. function SQL_workshop_search($string, $type)
  178. {
  179.   if ($type == 'PUBLIC') {
  180.     $date = 'workshop_date_crea';
  181.     $statut_mask = 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\'';
  182.   }
  183.   if ($type == 'ADMIN') {
  184.     $date = 'workshop_date_crea';
  185.     $statut_mask = 'AND workshop_statut<>\'E\'';
  186.   }
  187.   $q = 'SELECT workshop_id, workshop_denomination, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, workshop_statut AS statut, to_char(rank(idxfti, q)*100, \'99.99\') AS pertinence FROM ' . T_WORK . ', to_tsquery(\'default\', \''.$string.'\') as q WHERE idxfti @@ q ' . $statut_mask . ' ORDER BY rank(idxfti, q) DESC;';
  188.  
  189.   return $q;
  190. }
  191.  
  192. /**
  193.  * SQL_workshop_content_search()
  194.  *
  195.  * @param string $string 
  196.  * @param string $type 
  197.  * @return string $q
  198.  */
  199. function SQL_workrep_search($string, $type)
  200. {
  201.   if ($type == 'PUBLIC') {
  202.     $date = 'workrep_published_date';
  203.     $statut_mask = 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workrep_statut<>\'E\' AND workrep_statut<>\'AA\' AND workrep_statut<>\'D\'';
  204.   }
  205.   if ($type == 'ADMIN') {
  206.     $date = 'workrep_date_crea';
  207.     $statut_mask = 'AND workshop_statut<>\'E\' AND workrep_statut<>\'E\'';
  208.   }
  209.   $q = 'SELECT workrep_id, workrep_title, workshop_id, workshop_denomination, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, workrep_statut AS statut, to_char(rank(wr.idxfti, q)*100, \'99.99\') AS pertinence FROM to_tsquery(\'default\', \''.$string.'\') as q, ' . T_WORK_REP . ' AS wr LEFT OUTER JOIN ' . T_WORK . ' AS w ON workrep_workshop_id  =  workshop_id WHERE wr.idxfti @@ q ' . $statut_mask . ' ORDER BY rank(wr.idxfti, q) DESC;';
  210.  
  211.   return $q;
  212. }
  213.  
  214. /**
  215.  * SQL_workshop_content_search()
  216.  *
  217.  * @param string $string 
  218.  * @param string $type 
  219.  * @return string $q
  220.  */
  221. function SQL_workrep_content_search($string, $type)
  222. {
  223.   if ($type == 'PUBLIC') {
  224.     $date = 'workrep_date_crea';
  225.     $statut_mask = 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workrep_statut<>\'E\' AND workrep_statut<>\'AA\' AND workrep_statut<>\'D\' AND workrepcon_validity=\'Y\'';
  226.   }
  227.   if ($type == 'ADMIN') {
  228.     $date = 'workrep_date_crea';
  229.     $statut_mask = 'AND workshop_statut<>\'E\' AND workrep_statut<>\'E\' AND workrepcon_validity=\'Y\'';
  230.   }
  231.   $q = 'SELECT workrep_id, workrep_title, workrepcon_id, workrepcon_title, to_char(' . $date . ', \''.toStringSqlDate().'\') AS date_display, workrep_statut AS statut, to_char(rank(wrc.idxfti, q)*100, \'99.99\') AS pertinence FROM to_tsquery(\'default\', \''.$string.'\') as q, ' . J_PARTS . ' LEFT OUTER JOIN ' . T_WORK_REP . '  AS wr ON j_root_id  =  workrep_id LEFT OUTER JOIN ' . T_WORK_REP_CONT . ' AS wrc ON  j_parts_id= workrepcon_id LEFT OUTER JOIN ' . T_WORK . ' ON workrep_workshop_id  =  workshop_id WHERE wrc.idxfti @@ q  AND j_type=\'W\' ' . $statut_mask . ' ORDER BY rank(wrc.idxfti, q) DESC;';
  232.  
  233.   return $q;
  234. }
  235.  
  236. /**
  237.  * SQL_workshop_content_search()
  238.  *
  239.  * @param string $string 
  240.  * @param string $type 
  241.  * @return string $q
  242.  */
  243. function SQL_workshop_calendar_search($string, $type)
  244. {
  245.   if ($type == 'PUBLIC') {
  246.     $statut_mask = 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workcal_validity=\'Y\'';
  247.   }
  248.   if ($type == 'ADMIN') {
  249.     $statut_mask = 'AND workshop_statut<>\'E\' AND workcal_validity=\'Y\'';
  250.   }
  251.  
  252.   $q = 'SELECT workcal_id, workcal_task, workcal_workshop_id, workshop_denomination, workshop_statut AS statut, to_char(rank(wc.idxfti, q)*100, \'99.99\') AS pertinence FROM to_tsquery(\'default\', \''.$string.'\') as q, ' . T_WORK_CAL . ' AS wc LEFT OUTER JOIN ' . T_WORK . ' AS w ON  workcal_workshop_id  = workshop_id WHERE wc.idxfti @@ q ' . $statut_mask . ' ORDER BY rank(wc.idxfti, q) DESC;';
  253.  
  254.   return $q;
  255. }
  256.  
  257. /**
  258.  * SQL_workshop_content_search()
  259.  *
  260.  * @param string $string 
  261.  * @param string $type 
  262.  * @return string $q
  263.  */
  264. function SQL_workshop_com_search($string, $type)
  265. {
  266.   if ($type == 'PUBLIC') {
  267.     $statut_mask = 'AND workshop_statut<>\'E\' AND workshop_statut<>\'AA\' AND workshop_statut<>\'D\' AND workcom_statut <>\'E\'';
  268.   }
  269.   if ($type == 'ADMIN') {
  270.     $statut_mask = 'AND workshop_statut<>\'E\' AND workcom_statut <>\'E\'';
  271.   }
  272.  
  273.   $q = 'SELECT workcom_id, workcom_parent, workcom_subject, workcom_workshop_id, workshop_denomination, workshop_statut AS statut, to_char(rank(wc.idxfti, q)*100, \'99.99\') AS pertinence FROM to_tsquery(\'default\', \''.$string.'\') as q, ' . T_WORK_COM . '  AS wc LEFT OUTER JOIN ' . T_WORK . ' AS w ON  workcom_workshop_id  = workshop_id WHERE wc.idxfti @@ q ' . $statut_mask . ' ORDER BY rank(wc.idxfti, q) DESC;';
  274.  
  275.   return $q;
  276. }
  277.  
  278. /**
  279.  * SQL_yellowpages_search()
  280.  *
  281.  * @param string $string 
  282.  * @param string $type 
  283.  * @param string $searchtype 
  284.  * @return string $q
  285.  */
  286. function SQL_yellowpages_search($string, $type, $searchtype)
  287. {
  288.   if ($type == 'PUBLIC') {
  289.     $statut_mask = 'AND yellowp_statut<>\'E\' AND yellowp_statut<>\'AA\' AND yellowp_statut<>\'D\'';
  290.   }
  291.   if ($type == 'ADMIN') {
  292.     $statut_mask = 'AND yellowp_statut<>\'E\'';
  293.   }
  294.   $q = 'SELECT yellowp_id, yellowp_name, to_char(yellowp_date_crea, \''.toStringSqlDate().'\') AS date_display, yellowp_statut AS statut FROM ' . T_YELLOWPAGES . ' ' . SQL_ConstructorExpression($string, $searchtype, 'yellowp_name') . ' ' . $statut_mask . ' ORDER BY yellowp_name ASC;';
  295.  
  296.   return $q;
  297. }
  298.  
  299. /**
  300.  * SQL_user_search()
  301.  *
  302.  * @param string $string 
  303.  * @param string $type 
  304.  * @param string $searchtype 
  305.  * @return string $q
  306.  */
  307. function SQL_user_search($string, $type, $searchtype)
  308. {
  309.   if ($type == 'PUBLIC') {
  310.     $statut_mask = 'AND user_validity<>\'D\' AND user_validity<>\'N\'';
  311.   }
  312.   if ($type == 'ADMIN') {
  313.     $statut_mask = 'AND user_validity<>\'N\'';
  314.   }
  315.   $q = 'SELECT user_id, user_login, to_char(user_date_crea, \''.toStringSqlDate().'\') AS date_display, user_validity AS statut FROM ' . T_USER . ' ' . SQL_ConstructorExpression($string, $searchtype, 'user_login') . ' ' . $statut_mask . ' ORDER BY user_login ASC;';
  316.  
  317.   return $q;
  318. }
  319.  
  320. /**
  321.  * SQL_theme_search()
  322.  *
  323.  * @param string $string 
  324.  * @param string $type 
  325.  * @param string $searchtype 
  326.  * @return string $q
  327.  */
  328. function SQL_theme_search($string, $type, $searchtype)
  329. {
  330.   if ($type == 'PUBLIC') {
  331.     $statut_mask = 'AND theme_statut<>\'D\' AND theme_statut<>\'E\'';
  332.   }
  333.   if ($type == 'ADMIN') {
  334.     $statut_mask = 'AND theme_statut<>\'E\'';
  335.   }
  336.   $q = 'SELECT theme_id, theme_name, to_char(theme_date_crea, \''.toStringSqlDate().'\') AS date_display, theme_statut AS statut FROM ' . T_THEME . ' ' . SQL_ConstructorExpression($string, $searchtype, 'theme_name') . ' ' . $statut_mask . ' ORDER BY theme_name ASC;';
  337.  
  338.   return $q;
  339. }
  340.  
  341. /**
  342.  * SQL_scale_search()
  343.  *
  344.  * @param string $string 
  345.  * @param string $type 
  346.  * @param string $searchtype 
  347.  * @return string $q
  348.  */
  349. function SQL_scale_search($string, $type, $searchtype)
  350. {
  351.   if ($type == 'PUBLIC') {
  352.     $statut_mask = 'AND scale_statut<>\'D\' AND scale_statut<>\'E\' AND scale_statut<>\'I\'';
  353.   }
  354.   if ($type == 'ADMIN') {
  355.     $statut_mask = 'AND scale_statut<>\'I\' AND scale_statut<>\'E\'';
  356.   }
  357.   $q = 'SELECT scale_id, scale_denomination, to_char(scale_date_crea, \''.toStringSqlDate().'\') AS date_display, scale_statut AS statut FROM ' . T_SCALE . ' ' . SQL_ConstructorExpression($string, $searchtype, 'scale_denomination') . ' ' . $statut_mask . ' ORDER BY scale_denomination ASC;';
  358.  
  359.   return $q;
  360. }
  361.  
  362. /**
  363.  * SQL_level_search()
  364.  *
  365.  * @param string $string 
  366.  * @param string $type 
  367.  * @param string $searchtype 
  368.  * @return string $q
  369.  */
  370. function SQL_level_search($string, $type, $searchtype)
  371. {
  372.   if ($type == 'PUBLIC') {
  373.     $statut_mask = 'AND level_statut<>\'D\' AND level_statut<>\'E\'';
  374.   }
  375.   if ($type == 'ADMIN') {
  376.     $statut_mask = 'AND level_statut<>\'E\'';
  377.   }
  378.   $q = "SELECT level_id, level_name, to_char(level_date_crea, '".toStringSqlDate()."') AS date_display, level_statut AS statut FROM " . T_LEVEL . " " . SQL_ConstructorExpression($string, $searchtype, 'level_name') . ' ' . $statut_mask . " ORDER BY level_name ASC;";
  379.  
  380.   return $q;
  381. }
  382.  
  383. /**
  384.  * SQL_ConstructorExpression()
  385.  * Construit les requĂȘtes simple
  386.  *
  387.  * @param string $string 
  388.  * @param string $searchtype 
  389.  * @param string $field_name 
  390.  * @return string $q
  391.  */
  392. function SQL_ConstructorExpression($string, $searchtype, $field_name)
  393. {
  394.   $clause_requete = 'WHERE ';
  395.   $sep = '';
  396.   $string = trim($string);
  397.   $strings = @explode(' ', $string);
  398.   switch ($searchtype) {
  399.     case 'one':
  400.       for($i = 0; $i < count($strings); $i++) {
  401.         if(strlen($strings[$i])<=3)    $clause_requete .= $sep . $field_name . ' LIKE \'' . $strings[$i] . '%\'';
  402.         else $clause_requete .= $sep . $field_name . ' LIKE \'%' . $strings[$i] . '%\'';
  403.         $sep = ' OR ';
  404.       }
  405.       break;
  406.     case 'all':
  407.       for($i = 0; $i < count($strings); $i++) {
  408.         if(strlen($strings[$i])<=3) $clause_requete .= $sep . $field_name . ' LIKE \'' . $strings[$i] . '%\'';
  409.         else $clause_requete .= $sep . $field_name . ' LIKE \'%' . $strings[$i] . '%\'';
  410.         $sep = ' AND ';
  411.       }
  412.       break;
  413.     case 'exp':
  414.       $clause_requete .= $field_name . '=\'' . $string . '\'';
  415.       break;
  416.     default:
  417.       $clause_requete .= $field_name . ' LIKE \'%' . $string . '%\'';
  418.       break;
  419.   }
  420.   return $clause_requete;
  421. }
  422.  
  423. ?>

Documentation generated on Thu, 03 May 2012 15:07:05 +0200 by phpDocumentor 1.4.1