PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Layer-5__DB_operation/Qualifications.php

#
PHP | 326 lines | 197 code | 76 blank | 53 comment | 8 complexity | 17a553e8a5a8f9bea38aec11dd6e3578 MD5 | raw file
Possible License(s): AGPL-3.0
  1. <?php
  2. // Authors: Davi Leal
  3. //
  4. // Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Davi Leal <davi at leals dot com>
  5. //
  6. // This program is free software: you can redistribute it and/or modify it under
  7. // the terms of the GNU Affero General Public License as published by the Free Software Foundation,
  8. // either version 3 of the License, or (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied
  12. // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
  13. // General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License along with this
  16. // program in the COPYING file. If not, see <http://www.gnu.org/licenses/>.
  17. require_once "../Layer-5__DB_operation/PostgreSQL.php";
  18. require_once "../Layer-5__DB_operation/FS_Experiences.php";
  19. // Methods take the values form the global $_POST[] array.
  20. class Qualifications
  21. {
  22. private $postgresql;
  23. function __construct()
  24. {
  25. $this->postgresql = new PostgreSQL();
  26. }
  27. public function getQualificationsForEntity($Id)
  28. {
  29. $sqlQuery = "PREPARE query(integer) AS SELECT Q1_ProfessionalExperienceSinceYear,QP_LK_DesiredContractType,QP_DesiredWageRank,QP_LU_WageRankCurrency,QP_LB_WageRankByPeriod,QP_CurrentEmployability,QP_AvailableToTravel,QP_AvailableToChangeResidence,Q1_CompletedEdition FROM Q1_Qualifications WHERE Q1_E1_Id=$1; EXECUTE query('$Id');";
  30. $result = $this->postgresql->getPostgreSQLObject($sqlQuery,1);
  31. $array = array();
  32. $array[0] = pg_fetch_all_columns($result, 0); // Q1_ProfessionalExperienceSinceYear
  33. $array[2] = pg_fetch_all_columns($result, 1); // QP_LK_DesiredContractType
  34. $array[3] = pg_fetch_all_columns($result, 2); // QP_DesiredWageRank
  35. $array[4] = pg_fetch_all_columns($result, 3); // QP_LU_WageRankCurrency
  36. $array[5] = pg_fetch_all_columns($result, 4); // QP_LB_WageRankByPeriod
  37. $array[6] = pg_fetch_all_columns($result, 5); // QP_CurrentEmployability
  38. $array[7] = pg_fetch_all_columns($result, 6); // QP_AvailableToTravel
  39. $array[8] = pg_fetch_all_columns($result, 7); // QP_AvailableToChangeResidence
  40. $array[10] = pg_fetch_all_columns($result, 8); // Q1_CompletedEdition
  41. // The curreny name.
  42. $currencies = new Currencies();
  43. if (isset($array[4][0]) )
  44. $array[15] = $currencies->getCurrencyName($array[4][0]);
  45. else
  46. $array[15] = '';
  47. // Profiles
  48. $productProfiles = new ProductProfiles();
  49. $array[20] = $productProfiles->getProductProfilesForEntity($Id);
  50. $professionalProfiles = new ProfessionalProfiles();
  51. $array[21] = $professionalProfiles->getProfessionalProfilesForEntity($Id);
  52. $fieldProfiles = new FieldProfiles();
  53. $array[22] = $fieldProfiles->getFieldProfilesForEntity($Id);
  54. // Academic
  55. $academic = new Academic();
  56. $arrayAC = $academic->getAcademicForEntity($Id);
  57. $array[40] = $arrayAC[0];
  58. $array[41] = $arrayAC[1];
  59. $array[42] = $arrayAC[2];
  60. $array[43] = $arrayAC[3];
  61. $array[44] = $arrayAC[4];
  62. $array[45] = $arrayAC[5];
  63. $array[46] = $arrayAC[6];
  64. $array[47] = $arrayAC[7];
  65. // Certifications
  66. $certifications = new Certifications();
  67. $arrayCE = $certifications->getRequestedCertificationsForEntity($Id);
  68. $array[23] = $arrayCE[0];
  69. $array[24] = $arrayCE[1];
  70. // Contributions, FreeSoftwareExperiences
  71. $freeSoftwareExperiences = new FreeSoftwareExperiences();
  72. $arrayEX = $freeSoftwareExperiences->getFreeSoftwareExperiencesForEntity($Id);
  73. $array[25] = $arrayEX[0];
  74. $array[26] = $arrayEX[1];
  75. $array[27] = $arrayEX[2];
  76. // Qualification Languages table
  77. $languages = new Languages();
  78. $arrayLL = $languages->getLanguagesForEntity($Id);
  79. $array[28] = $arrayLL[0];
  80. $array[29] = $arrayLL[1];
  81. $array[30] = $arrayLL[2];
  82. // Qualification Skills table
  83. $skills = new Skills();
  84. $arrayLS = $skills->getSkillsForEntity($Id);
  85. $array[31] = $arrayLS[0];
  86. $array[32] = $arrayLS[1];
  87. $array[33] = $arrayLS[2];
  88. $array[34] = $arrayLS[3];
  89. return $array;
  90. }
  91. public function addQualifications($completedEdition)
  92. {
  93. // As there are several tables involved, we use a transaction to be sure, all operations are done, or nothing is done.
  94. $this->postgresql->execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE",0);
  95. $this->postgresql->execute("BEGIN",0);
  96. // Qualifications
  97. $EntityId = isset($_SESSION['EntityId']) ? trim($_SESSION['EntityId']) : '';
  98. $ProfessionalExperienceSinceYear = isset($_POST['ProfessionalExperienceSinceYear']) ? trim($_POST['ProfessionalExperienceSinceYear']) : '';
  99. $sqlQuery = "PREPARE query(integer,text) AS INSERT INTO Q1_Qualifications (Q1_E1_Id,Q1_ProfessionalExperienceSinceYear) VALUES ($1,$2); EXECUTE query('$EntityId','".pg_escape_string($ProfessionalExperienceSinceYear)."');";
  100. $this->postgresql->execute($sqlQuery,1);
  101. // Profiles
  102. $productProfiles = new ProductProfiles();
  103. $productProfiles->setProductProfilesForEntity();
  104. $professionalProfiles = new ProfessionalProfiles();
  105. $professionalProfiles->setProfessionalProfilesForEntity();
  106. $fieldProfiles = new FieldProfiles();
  107. $fieldProfiles->setFieldProfilesForEntity();
  108. // Saving only the first section. It is not need to update the Q1_CompletedEdition flag due to it is 'false' by default.
  109. $this->postgresql->execute("COMMIT",0); // Note: The result is not checked, but any error is managed by the 'query' fuction.
  110. }
  111. public function deleteQualifications()
  112. {
  113. // Delete the subscriptions to job offers
  114. $sqlQuery = "PREPARE query(integer) AS DELETE FROM R0_Qualifications2JobOffersJoins WHERE R0_E1_Id=$1; EXECUTE query('$_SESSION[EntityId]');";
  115. $result = $this->postgresql->execute($sqlQuery,1);
  116. // NotYetRequestedCertifications to requested certifications
  117. $certifications = new Certifications();
  118. $certifications->delRequestedCertificationsForEntity();
  119. // Profiles
  120. $productProfiles = new ProductProfiles();
  121. $productProfiles->delProductProfilesForEntity();
  122. $professionalProfiles = new ProfessionalProfiles();
  123. $professionalProfiles->delProfessionalProfilesForEntity();
  124. $fieldProfiles = new FieldProfiles();
  125. $fieldProfiles->delFieldProfilesForEntity();
  126. // Academic table
  127. $academic = new Academic();
  128. $academic->delAcademicForEntity();
  129. // Contributions/FreeSoftwareExperiences
  130. $freeSoftwareExperiences = new FreeSoftwareExperiences();
  131. $freeSoftwareExperiences->delFreeSoftwareExperiencesForEntity();
  132. // Languages table
  133. $languages = new Languages();
  134. $languages->delLanguagesForEntity();
  135. // Skills table
  136. $skills = new Skills();
  137. $skills->delSkillsForEntity();
  138. // Qualifications
  139. $sqlQuery = "PREPARE query(integer) AS DELETE FROM Q1_Qualifications WHERE Q1_E1_Id=$1; EXECUTE query('$_SESSION[EntityId]');";
  140. $result = $this->postgresql->execute($sqlQuery,1);
  141. }
  142. public function updateQualifications($section,$completedEdition)
  143. {
  144. // As there are several tables involved, we use a transaction to be sure, all operations are done, or nothing is done.
  145. $this->postgresql->execute("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE",0);
  146. $this->postgresql->execute("BEGIN",0);
  147. switch($section)
  148. {
  149. case 'profiles_etc':
  150. // Q1_Qualifications table
  151. $ProfessionalExperienceSinceYear = isset($_POST['ProfessionalExperienceSinceYear']) ? trim($_POST['ProfessionalExperienceSinceYear']) : '';
  152. $sqlQuery = "PREPARE query(text,bool,integer) AS UPDATE Q1_Qualifications SET Q1_ProfessionalExperienceSinceYear=$1,Q1_CompletedEdition=$2 WHERE Q1_E1_Id=$3; EXECUTE query('".pg_escape_string($ProfessionalExperienceSinceYear)."','$completedEdition','{$_SESSION['EntityId']}');";
  153. $this->postgresql->execute($sqlQuery,1);
  154. // Profiles
  155. $productProfiles = new ProductProfiles();
  156. $productProfiles->setProductProfilesForEntity();
  157. $professionalProfiles = new ProfessionalProfiles();
  158. $professionalProfiles->setProfessionalProfilesForEntity();
  159. $fieldProfiles = new FieldProfiles();
  160. $fieldProfiles->setFieldProfilesForEntity();
  161. break;
  162. case 'academic':
  163. // Academic table
  164. $academic = new Academic();
  165. $academic->setAcademicForEntity();
  166. // Update the Q1_CompletedEdition flag
  167. $sqlQuery = "PREPARE query(bool,integer) AS UPDATE Q1_Qualifications SET Q1_CompletedEdition=$1 WHERE Q1_E1_Id=$2; EXECUTE query('$completedEdition','{$_SESSION['EntityId']}');";
  168. $this->postgresql->execute($sqlQuery,1);
  169. break;
  170. case 'certifications':
  171. // NotYetRequestedCertifications to requested certifications
  172. $certifications = new Certifications();
  173. $certifications->setRequestedCertificationsForEntity();
  174. // Update the Q1_CompletedEdition flag
  175. $sqlQuery = "PREPARE query(bool,integer) AS UPDATE Q1_Qualifications SET Q1_CompletedEdition=$1 WHERE Q1_E1_Id=$2; EXECUTE query('$completedEdition','{$_SESSION['EntityId']}');";
  176. $this->postgresql->execute($sqlQuery,1);
  177. break;
  178. case 'projects':
  179. // Contributions, FreeSoftwareExperiences
  180. $freeSoftwareExperiences = new FreeSoftwareExperiences();
  181. $freeSoftwareExperiences->setFreeSoftwareExperiencesForEntity();
  182. // Update the Q1_CompletedEdition flag
  183. $sqlQuery = "PREPARE query(bool,integer) AS UPDATE Q1_Qualifications SET Q1_CompletedEdition=$1 WHERE Q1_E1_Id=$2; EXECUTE query('$completedEdition','{$_SESSION['EntityId']}');";
  184. $this->postgresql->execute($sqlQuery,1);
  185. break;
  186. case 'languages':
  187. // Languages table
  188. $languages = new Languages();
  189. $languages->setLanguagesForEntity();
  190. // Update the Q1_CompletedEdition flag
  191. $sqlQuery = "PREPARE query(bool,integer) AS UPDATE Q1_Qualifications SET Q1_CompletedEdition=$1 WHERE Q1_E1_Id=$2; EXECUTE query('$completedEdition','{$_SESSION['EntityId']}');";
  192. $this->postgresql->execute($sqlQuery,1);
  193. break;
  194. case 'skills':
  195. // Skills table
  196. $skills = new Skills();
  197. $skills->setSkillsForEntity();
  198. // Update the Q1_CompletedEdition flag
  199. $sqlQuery = "PREPARE query(bool,integer) AS UPDATE Q1_Qualifications SET Q1_CompletedEdition=$1 WHERE Q1_E1_Id=$2; EXECUTE query('$completedEdition','{$_SESSION['EntityId']}');";
  200. $this->postgresql->execute($sqlQuery,1);
  201. break;
  202. case 'location':
  203. // Q1_Qualifications table
  204. if (isset($_POST['AvailableToTravel']) and $_POST['AvailableToTravel'] == 'on')
  205. $AvailableToTravel = 'true';
  206. else $AvailableToTravel = 'false';
  207. if (isset($_POST['AvailableToChangeResidence']) and $_POST['AvailableToChangeResidence'] == 'on')
  208. $AvailableToChangeResidence = 'true';
  209. else $AvailableToChangeResidence = 'false';
  210. $AvailableToTravel = trim($AvailableToTravel);
  211. $AvailableToChangeResidence = trim($AvailableToChangeResidence);
  212. $sqlQuery = "PREPARE query(bool,bool,bool,integer) AS UPDATE Q1_Qualifications SET QP_AvailableToTravel=$1,QP_AvailableToChangeResidence=$2,Q1_CompletedEdition=$3 WHERE Q1_E1_Id=$4; EXECUTE query('$AvailableToTravel','$AvailableToChangeResidence','$completedEdition','{$_SESSION['EntityId']}');";
  213. $this->postgresql->execute($sqlQuery,1);
  214. break;
  215. case 'contract':
  216. // Q1_Qualifications table
  217. $DesiredContractType = isset($_POST['DesiredContractType']) ? trim($_POST['DesiredContractType']) : '';
  218. $DesiredWageRank = isset($_POST['DesiredWageRank']) ? trim($_POST['DesiredWageRank']) : '';
  219. $WageRankCurrency = isset($_POST['WageRankCurrency']) ? trim($_POST['WageRankCurrency']) : '';
  220. $WageRankByPeriod = isset($_POST['WageRankByPeriod']) ? trim($_POST['WageRankByPeriod']) : '';
  221. $CurrentEmployability = isset($_POST['CurrentEmployability']) ? trim($_POST['CurrentEmployability']) : '';
  222. $sqlQuery = "PREPARE query(text,text,text,text,text,bool,integer) AS UPDATE Q1_Qualifications SET QP_LK_DesiredContractType=$1,QP_DesiredWageRank=$2,QP_LU_WageRankCurrency=$3,QP_LB_WageRankByPeriod=$4,QP_CurrentEmployability=$5,Q1_CompletedEdition=$6 WHERE Q1_E1_Id=$7; EXECUTE query('$DesiredContractType','".pg_escape_string($DesiredWageRank)."','".pg_escape_string($WageRankCurrency)."','$WageRankByPeriod','$CurrentEmployability','$completedEdition','{$_SESSION['EntityId']}');";
  223. $this->postgresql->execute($sqlQuery,1);
  224. break;
  225. default:
  226. $error = "<p>".$_SERVER["REQUEST_URI"].": ".gettext('ERROR: Unexpected condition')."</p>";
  227. throw new Exception($error,false);
  228. }
  229. $this->postgresql->execute("COMMIT",0);
  230. }
  231. // methods to check the Access Control List
  232. // Check if the request comes from the Qualifications owner
  233. public function isOwner($E1_Id)
  234. {
  235. if ( $_SESSION['EntityId'] == $E1_Id ) // There is not need to query the Data Base :-)
  236. return true;
  237. else
  238. return false;
  239. }
  240. // Check if the request comes from an Entity that has a JobOffer with such Qualifications subscribed
  241. public function isJobOfferApplication($E1_Id)
  242. {
  243. $sqlQuery = "PREPARE query(integer,integer) AS SELECT count(*) FROM R0_Qualifications2JobOffersJoins WHERE R0_J1_Id IN ( SELECT J1_Id FROM J1_JobOffers WHERE J1_E1_Id=$1 AND J1_ExpirationDate > 'now' ) AND R0_E1_Id=$2; EXECUTE query('$_SESSION[EntityId]','$E1_Id');"; // AND J1_Closed='f'
  244. $result = $this->postgresql->getOneField($sqlQuery,1);
  245. if ( intval($result[0]) >= 1 )
  246. return true;
  247. else
  248. return false;
  249. }
  250. }