PageRenderTime 51ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/workflow/engine/classes/model/Users.php

https://bitbucket.org/ferOnti/processmaker
PHP | 383 lines | 335 code | 11 blank | 37 comment | 8 complexity | 63337902b958ee2d8a4c8bd2296666c7 MD5 | raw file
  1. <?php
  2. /**
  3. * Users.php
  4. *
  5. * @package workflow.engine.classes.model
  6. *
  7. * ProcessMaker Open Source Edition
  8. * Copyright (C) 2004 - 2011 Colosa Inc.
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
  24. * Coral Gables, FL, 33134, USA, or email info@colosa.com.
  25. *
  26. */
  27. require_once 'classes/model/om/BaseUsers.php';
  28. require_once 'classes/model/IsoCountry.php';
  29. require_once 'classes/model/IsoSubdivision.php';
  30. require_once 'classes/model/IsoLocation.php';
  31. /**
  32. * Skeleton subclass for representing a row from the 'USERS' table.
  33. *
  34. *
  35. *
  36. * You should add additional methods to this class to meet the
  37. * application requirements. This class will only be generated as
  38. * long as it does not already exist in the output directory.
  39. *
  40. * @package workflow.engine.classes.model
  41. */
  42. class Users extends BaseUsers
  43. {
  44. public function create ($aData)
  45. {
  46. $con = Propel::getConnection( UsersPeer::DATABASE_NAME );
  47. try {
  48. $this->fromArray( $aData, BasePeer::TYPE_FIELDNAME );
  49. if ($this->validate()) {
  50. $result = $this->save();
  51. } else {
  52. $e = new Exception( "Failed Validation in class " . get_class( $this ) . "." );
  53. $e->aValidationFailures = $this->getValidationFailures();
  54. throw ($e);
  55. }
  56. $con->commit();
  57. return $result;
  58. } catch (Exception $e) {
  59. $con->rollback();
  60. throw ($e);
  61. }
  62. }
  63. public function userExists ($UsrUid)
  64. {
  65. try {
  66. $oRow = UsersPeer::retrieveByPK( $UsrUid );
  67. if (! is_null( $oRow )) {
  68. return true;
  69. } else {
  70. return false;
  71. }
  72. } catch (Exception $oError) {
  73. return false;
  74. }
  75. }
  76. public function load ($UsrUid)
  77. {
  78. try {
  79. $oRow = UsersPeer::retrieveByPK( $UsrUid );
  80. if (! is_null( $oRow )) {
  81. $aFields = $oRow->toArray( BasePeer::TYPE_FIELDNAME );
  82. $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
  83. $this->setNew( false );
  84. return $aFields;
  85. } else {
  86. throw (new Exception( "The row '" . $UsrUid . "' in table USER doesn't exist!" ));
  87. }
  88. } catch (PropelException $e) {
  89. //capture invalid birthday date and replace by null
  90. $msg = $e->getMessage();
  91. if (strpos( 'Unable to parse value of [usr_birthday]', $msg ) != - 1) {
  92. $oRow->setUsrBirthday( null );
  93. $oRow->save();
  94. return $this->load( $UsrUid );
  95. }
  96. } catch (Exception $oError) {
  97. throw ($oError);
  98. }
  99. }
  100. public function loadDetails ($UsrUid)
  101. {
  102. try {
  103. $result = array ();
  104. $oUser = UsersPeer::retrieveByPK( $UsrUid );
  105. if (! is_null( $oUser )) {
  106. $result['USR_UID'] = $oUser->getUsrUid();
  107. $result['USR_USERNAME'] = $oUser->getUsrUsername();
  108. $result['USR_FULLNAME'] = $oUser->getUsrFirstname() . ' ' . $oUser->getUsrLastname();
  109. $result['USR_EMAIL'] = $oUser->getUsrEmail();
  110. return $result;
  111. } else {
  112. // return $result;
  113. throw (new Exception( "The row '" . $UsrUid . "' in table USER doesn't exist!" ));
  114. }
  115. } catch (Exception $oError) {
  116. throw ($oError);
  117. }
  118. }
  119. public function loadDetailed ($UsrUid)
  120. {
  121. try {
  122. $result = array ();
  123. $oUser = UsersPeer::retrieveByPK( $UsrUid );
  124. if (! is_null( $oUser )) {
  125. $aFields = $oUser->toArray( BasePeer::TYPE_FIELDNAME );
  126. $this->fromArray( $aFields, BasePeer::TYPE_FIELDNAME );
  127. $this->setNew( false );
  128. $aIsoCountry = IsoCountry::findById( $aFields['USR_COUNTRY'] );
  129. $aIsoSubdivision = IsoSubdivision::findById( $aFields['USR_COUNTRY'], $aFields['USR_CITY'] );
  130. $aIsoLocation = IsoLocation::findById( $aFields['USR_COUNTRY'], $aFields['USR_CITY'], $aFields['USR_LOCATION'] );
  131. $aFields['USR_COUNTRY_NAME'] = $aIsoCountry['IC_NAME'];
  132. $aFields['USR_CITY_NAME'] = $aIsoSubdivision['IS_NAME'];
  133. $aFields['USR_LOCATION_NAME'] = $aIsoLocation['IL_NAME'];
  134. $result = $aFields;
  135. return $result;
  136. } else {
  137. //return $result;
  138. throw (new Exception( "The row '" . $UsrUid . "' in table USER doesn't exist!" ));
  139. }
  140. } catch (Exception $oError) {
  141. throw ($oError);
  142. }
  143. }
  144. public function update ($fields)
  145. {
  146. $con = Propel::getConnection( UsersPeer::DATABASE_NAME );
  147. try {
  148. $con->begin();
  149. $this->load( $fields['USR_UID'] );
  150. $this->fromArray( $fields, BasePeer::TYPE_FIELDNAME );
  151. if ($this->validate()) {
  152. $result = $this->save();
  153. $con->commit();
  154. return $result;
  155. } else {
  156. $con->rollback();
  157. throw (new Exception( "Failed Validation in class " . get_class( $this ) . "." ));
  158. }
  159. } catch (Exception $e) {
  160. $con->rollback();
  161. throw ($e);
  162. }
  163. }
  164. public function remove ($UsrUid)
  165. {
  166. $con = Propel::getConnection( UsersPeer::DATABASE_NAME );
  167. try {
  168. $con->begin();
  169. $this->setUsrUid( $UsrUid );
  170. $result = $this->delete();
  171. $con->commit();
  172. return $result;
  173. } catch (Exception $e) {
  174. $con->rollback();
  175. throw ($e);
  176. }
  177. }
  178. public function loadByUsername ($sUsername)
  179. {
  180. $c = new Criteria( 'workflow' );
  181. $del = DBAdapter::getStringDelimiter();
  182. $c->clearSelectColumns();
  183. $c->addSelectColumn( UsersPeer::USR_UID );
  184. $c->addSelectColumn( UsersPeer::USR_USERNAME );
  185. $c->addSelectColumn( UsersPeer::USR_STATUS );
  186. $c->add( UsersPeer::USR_USERNAME, $sUsername );
  187. return $c;
  188. }
  189. public function loadByUsernameInArray ($sUsername)
  190. {
  191. $c = $this->loadByUsername( $sUsername );
  192. $rs = UsersPeer::doSelectRS( $c );
  193. $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  194. $rs->next();
  195. $row = $rs->getRow();
  196. return $row;
  197. }
  198. public function getAllInformation ($userUid)
  199. {
  200. if (! isset( $userUid ) || $userUid == "") {
  201. throw (new Exception( "$userUid is empty." ));
  202. }
  203. try {
  204. require_once ("classes/model/IsoCountry.php");
  205. require_once ("classes/model/IsoLocation.php");
  206. require_once ("classes/model/IsoSubdivision.php");
  207. require_once ("classes/model/Language.php");
  208. G::LoadClass( "calendar" );
  209. $aFields = $this->load( $userUid );
  210. $c = new Criteria( "workflow" );
  211. $c->add( IsoCountryPeer::IC_UID, $aFields["USR_COUNTRY"] );
  212. $rs = IsoCountryPeer::doSelectRS( $c );
  213. $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  214. $rs->next();
  215. $rowC = $rs->getRow();
  216. $c->clearSelectColumns();
  217. $c->add( IsoSubdivisionPeer::IC_UID, $aFields["USR_COUNTRY"] );
  218. $c->add( IsoSubdivisionPeer::IS_UID, $aFields["USR_CITY"] );
  219. $rs = IsoSubdivisionPeer::doSelectRS( $c );
  220. $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  221. $rs->next();
  222. $rowS = $rs->getRow();
  223. $c->clearSelectColumns();
  224. $c->add( IsoLocationPeer::IC_UID, $aFields["USR_COUNTRY"] );
  225. $c->add( IsoLocationPeer::IL_UID, $aFields["USR_LOCATION"] );
  226. $rs = IsoLocationPeer::doSelectRS( $c );
  227. $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  228. $rs->next();
  229. $rowL = $rs->getRow();
  230. //Calendar
  231. $calendar = new Calendar();
  232. $calendarInfo = $calendar->getCalendarFor( $userUid, $userUid, $userUid );
  233. $aFields["USR_CALENDAR"] = ($calendarInfo["CALENDAR_APPLIED"] != "DEFAULT") ? $calendarInfo["CALENDAR_UID"] : "";
  234. //Photo
  235. $pathPhoto = PATH_IMAGES_ENVIRONMENT_USERS . $userUid . ".gif";
  236. if (! file_exists( $pathPhoto )) {
  237. $pathPhoto = PATH_HOME . "public_html" . PATH_SEP . "images" . PATH_SEP . "user.gif";
  238. }
  239. //Data
  240. $arrayData = array ();
  241. $arrayData["username"] = $aFields["USR_USERNAME"];
  242. $arrayData["firstname"] = $aFields["USR_FIRSTNAME"];
  243. $arrayData["lastname"] = $aFields["USR_LASTNAME"];
  244. $arrayData["mail"] = $aFields["USR_EMAIL"];
  245. $arrayData["address"] = $aFields["USR_ADDRESS"];
  246. $arrayData["zipcode"] = $aFields["USR_ZIP_CODE"];
  247. $arrayData["country"] = $rowC["IC_NAME"];
  248. $arrayData["state"] = $rowS["IS_NAME"];
  249. $arrayData["location"] = $rowL["IL_NAME"];
  250. $arrayData["phone"] = $aFields["USR_PHONE"];
  251. $arrayData["fax"] = $aFields["USR_FAX"];
  252. $arrayData["cellular"] = $aFields["USR_CELLULAR"];
  253. $arrayData["birthday"] = $aFields["USR_BIRTHDAY"];
  254. $arrayData["position"] = $aFields["USR_POSITION"];
  255. $arrayData["replacedby"] = $aFields["USR_REPLACED_BY"];
  256. $arrayData["duedate"] = $aFields["USR_DUE_DATE"];
  257. $arrayData["calendar"] = $aFields["USR_CALENDAR"];
  258. $arrayData["status"] = $aFields["USR_STATUS"];
  259. $arrayData["department"] = $aFields["DEP_UID"];
  260. $arrayData["reportsto"] = $aFields["USR_REPORTS_TO"];
  261. $arrayData["userexperience"] = $aFields["USR_UX"];
  262. $arrayData["photo"] = $pathPhoto;
  263. return $arrayData;
  264. } catch (Exception $e) {
  265. throw $e;
  266. }
  267. }
  268. public function getAvailableUsersCriteria ($sGroupUID = '')
  269. {
  270. try {
  271. $oCriteria = new Criteria( 'workflow' );
  272. $oCriteria->addSelectColumn( UsersPeer::USR_UID );
  273. $oCriteria->addSelectColumn( UsersPeer::USR_FIRSTNAME );
  274. $oCriteria->addSelectColumn( UsersPeer::USR_LASTNAME );
  275. $oCriteria->add( UsersPeer::USR_STATUS, 'ACTIVE' );
  276. return $oCriteria;
  277. } catch (exception $oError) {
  278. throw ($oError);
  279. }
  280. }
  281. /**
  282. * Get all Active users
  283. *
  284. * @return array of all active users
  285. */
  286. public function getAll ($start = null, $limit = null, $search = null)
  287. {
  288. $totalCount = 0;
  289. $criteria = new Criteria( 'workflow' );
  290. $criteria->addSelectColumn( UsersPeer::USR_UID );
  291. $criteria->addSelectColumn( UsersPeer::USR_USERNAME );
  292. $criteria->addSelectColumn( UsersPeer::USR_FIRSTNAME );
  293. $criteria->addSelectColumn( UsersPeer::USR_LASTNAME );
  294. $criteria->add( UsersPeer::USR_STATUS, 'ACTIVE' );
  295. $criteria->addAscendingOrderByColumn( UsersPeer::USR_LASTNAME );
  296. if ($search) {
  297. $criteria->add( $criteria->getNewCriterion( UsersPeer::USR_USERNAME, "%$search%", Criteria::LIKE )->addOr( $criteria->getNewCriterion( UsersPeer::USR_FIRSTNAME, "%$search%", Criteria::LIKE ) )->addOr( $criteria->getNewCriterion( UsersPeer::USR_LASTNAME, "%$search%", Criteria::LIKE ) ) );
  298. }
  299. $c = clone $criteria;
  300. $c->clearSelectColumns();
  301. $c->addSelectColumn( 'COUNT(*)' );
  302. $dataset = UsersPeer::doSelectRS( $c );
  303. $dataset->next();
  304. $rowCount = $dataset->getRow();
  305. if (is_array( $rowCount )) {
  306. $totalCount = $rowCount[0];
  307. }
  308. if ($start) {
  309. $criteria->setOffset( $start );
  310. }
  311. if ($limit) {
  312. $criteria->setLimit( $limit );
  313. }
  314. $rs = UsersPeer::doSelectRS( $criteria );
  315. $rs->setFetchmode( ResultSet::FETCHMODE_ASSOC );
  316. $rows = Array ();
  317. while ($rs->next()) {
  318. $rows[] = $rs->getRow();
  319. }
  320. $result->data = $rows;
  321. $result->totalCount = $totalCount;
  322. return $result;
  323. }
  324. public function userVacation ($UsrUid = "")
  325. {
  326. $aFields = array ();
  327. $cnt = 0;
  328. do {
  329. if ($UsrUid != "" && $cnt < 100) {
  330. $aFields = $this->load( $UsrUid );
  331. $UsrUid = $aFields['USR_REPLACED_BY'];
  332. } else {
  333. break;
  334. }
  335. $cnt ++;
  336. } while ($aFields['USR_STATUS'] != 'ACTIVE');
  337. return $aFields;
  338. }
  339. }