PageRenderTime 29ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/com_joomleague/administrator/components/com_joomleague/models/quickadd.php

https://gitlab.com/julienv/joomleague
PHP | 295 lines | 228 code | 32 blank | 35 comment | 26 complexity | 53e16dfa6b4a762cf22d1d275f3d961a MD5 | raw file
  1. <?php
  2. /**
  3. * @copyright Copyright (C) 2006-2014 joomleague.at. All rights reserved.
  4. * @license GNU/GPL, see LICENSE.php
  5. * Joomla! is free software. This version may have been modified pursuant
  6. * to the GNU General Public License, and as distributed it includes or
  7. * is derivative of works licensed under the GNU General Public License or
  8. * other free or open source software licenses.
  9. * See COPYRIGHT.php for copyright notices and details.
  10. */
  11. // Check to ensure this file is included in Joomla!
  12. defined('_JEXEC') or die('Restricted access');
  13. jimport('joomla.application.component.model');
  14. require_once ( JPATH_COMPONENT . DS . 'models' . DS . 'list.php' );
  15. /**
  16. * Joomleague Component person search Model
  17. *
  18. * @package JoomLeague
  19. * @since 1.5
  20. */
  21. class JoomleagueModelQuickAdd extends JoomleagueModelList
  22. {
  23. var $_identifier = "quickadd";
  24. /*
  25. * @param {string} query - the search string
  26. * @param {int} projectteam_id - the projectteam_id
  27. */
  28. function getNotAssignedPlayers($searchterm, $projectteam_id)
  29. {
  30. $query = " SELECT pl.*, pl.id as id2
  31. FROM #__joomleague_person AS pl
  32. WHERE ( LOWER( CONCAT(pl.firstname, ' ', pl.lastname) ) LIKE " . $this->_db->Quote("%" . $searchterm . "%") . " OR
  33. alias LIKE " . $this->_db->Quote("%" . $searchterm . "%") . " OR
  34. nickname LIKE " . $this->_db->Quote("%" . $searchterm . "%") . " OR
  35. id = " . $this->_db->Quote($searchterm) . ")
  36. AND pl.published = '1'
  37. AND pl.id NOT IN ( SELECT person_id
  38. FROM #__joomleague_team_player AS tp
  39. WHERE projectteam_id = ". $this->_db->Quote($projectteam_id) . " AND
  40. tp.person_id = pl.id ) ";
  41. $option = JRequest::getCmd('option');
  42. $mainframe = JFactory::getApplication();
  43. $filter_order = $mainframe->getUserStateFromRequest( $option . 'pl_filter_order', 'filter_order', 'pl.lastname', 'cmd' );
  44. $filter_order_Dir = $mainframe->getUserStateFromRequest( $option . 'pl_filter_order_Dir', 'filter_order_Dir', '', 'word' );
  45. if ( $filter_order == 'pl.lastname' )
  46. {
  47. $orderby = ' ORDER BY pl.lastname ' . $filter_order_Dir;
  48. }
  49. else
  50. {
  51. $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ' , pl.lastname ';
  52. }
  53. $query = $query . $orderby;
  54. $this->_db->setQuery( $query );
  55. if ( !$this->_data = $this->_getList( $query, $this->getState( 'limitstart' ), $this->getState( 'limit' ) ) )
  56. {
  57. echo $this->_db->getErrorMsg();
  58. }
  59. $this->_total = $this->_getListCount( $query );
  60. return $this->_data;
  61. }
  62. /*
  63. * @param {string} query - the search string
  64. * @param {int} projectteam_id - the projectteam_id
  65. */
  66. function getNotAssignedStaff($searchterm, $projectteam_id)
  67. {
  68. $query = "SELECT pl.* ";
  69. $query .= "FROM #__joomleague_person AS pl ";
  70. $query .= "WHERE (LOWER( CONCAT(pl.firstname, ' ', pl.lastname) ) LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  71. $query .= " OR alias LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  72. $query .= " OR nickname LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  73. $query .= " OR pl.id = ".$this->_db->Quote($searchterm) . ") ";
  74. $query .= " AND pl.published = '1'";
  75. $query .= " AND pl.id NOT IN ( SELECT person_id ";
  76. $query .= " FROM #__joomleague_team_staff AS ts ";
  77. $query .= " WHERE projectteam_id = ". $this->_db->Quote($projectteam_id);
  78. $query .= " AND ts.person_id = pl.id ) ";
  79. $option = JRequest::getCmd('option');
  80. $mainframe = JFactory::getApplication();
  81. $filter_order = $mainframe->getUserStateFromRequest( $option . 'pl_filter_order', 'filter_order', 'pl.lastname', 'cmd' );
  82. $filter_order_Dir = $mainframe->getUserStateFromRequest( $option . 'pl_filter_order_Dir', 'filter_order_Dir', '', 'word' );
  83. if ( $filter_order == 'pl.lastname' )
  84. {
  85. $orderby = ' ORDER BY pl.lastname ' . $filter_order_Dir;
  86. }
  87. else
  88. {
  89. $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ' , pl.lastname ';
  90. }
  91. $query = $query . $orderby;
  92. $this->_db->setQuery( $query );
  93. if ( !$this->_data = $this->_getList( $query,
  94. $this->getState( 'limitstart' ),
  95. $this->getState( 'limit' ) ) )
  96. {
  97. echo $this->_db->getErrorMsg();
  98. }
  99. $this->_total = $this->_getListCount( $query );
  100. return $this->_data;
  101. }
  102. /*
  103. * @param {string} query - the search string
  104. * @param {int} projectteam_id - the projectteam_id
  105. */
  106. function getNotAssignedReferees($searchterm, $projectid)
  107. {
  108. $query = "SELECT pl.* ";
  109. $query .= "FROM #__joomleague_person AS pl ";
  110. $query .= "WHERE (LOWER( CONCAT(pl.firstname, ' ', pl.lastname) ) LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  111. $query .= " OR alias LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  112. $query .= " OR nickname LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  113. $query .= " OR pl.id = ".$this->_db->Quote($searchterm) . ") ";
  114. $query .= " AND pl.published = '1'";
  115. $query .= " AND pl.id NOT IN ( SELECT person_id ";
  116. $query .= " FROM #__joomleague_project_referee AS pr ";
  117. $query .= " WHERE project_id = ". $this->_db->Quote($projectid);
  118. $query .= " AND pr.person_id = pl.id ) ";
  119. $option = JRequest::getCmd('option');
  120. $mainframe = JFactory::getApplication();
  121. $filter_order = $mainframe->getUserStateFromRequest( $option . 'pl_filter_order', 'filter_order', 'pl.lastname', 'cmd' );
  122. $filter_order_Dir = $mainframe->getUserStateFromRequest( $option . 'pl_filter_order_Dir', 'filter_order_Dir', '', 'word' );
  123. if ( $filter_order == 'pl.lastname' )
  124. {
  125. $orderby = ' ORDER BY pl.lastname ' . $filter_order_Dir;
  126. }
  127. else
  128. {
  129. $orderby = ' ORDER BY ' . $filter_order . ' ' . $filter_order_Dir . ' , pl.lastname ';
  130. }
  131. $query = $query . $orderby;
  132. $this->_db->setQuery( $query );
  133. if ( !$this->_data = $this->_getList( $query,
  134. $this->getState( 'limitstart' ),
  135. $this->getState( 'limit' ) ) )
  136. {
  137. echo $this->_db->getErrorMsg();
  138. }
  139. $this->_total = $this->_getListCount( $query );
  140. return $this->_data;
  141. }
  142. /*
  143. * @param {string} query - the search string
  144. * @param {int} projectteam_id - the projectteam_id
  145. */
  146. function getNotAssignedTeams($searchterm, $projectid)
  147. {
  148. $query = "SELECT t.* ";
  149. $query .= "FROM #__joomleague_team AS t ";
  150. $query .= "WHERE (LOWER( t.name ) LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  151. $query .= " OR alias LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  152. $query .= " OR LOWER( short_name ) LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  153. $query .= " OR LOWER( middle_name ) LIKE ".$this->_db->Quote("%".$searchterm."%")." ";
  154. $query .= " OR id = ".$this->_db->Quote($searchterm) . ") ";
  155. $query .= " AND t.id NOT IN ( SELECT team_id ";
  156. $query .= " FROM #__joomleague_project_team AS pt ";
  157. $query .= " WHERE project_id = ". $this->_db->Quote($projectid);
  158. $query .= ") ";
  159. $this->_db->setQuery( $query);
  160. if ( !$this->_data = $this->_getList( $query,
  161. $this->getState( 'limitstart' ),
  162. $this->getState( 'limit' ) ) )
  163. {
  164. echo $this->_db->getErrorMsg();
  165. }
  166. $this->_total = $this->_getListCount( $query );
  167. return $this->_data;
  168. }
  169. function addPlayer($projectteam_id, $personid, $name = null)
  170. {
  171. if ( !$personid && empty($name) ) {
  172. $this->setError(Jtext::_('COM_JOOMLEAGUE_ADMIN_QUICKADD_CTRL_ADD_PLAYER_REQUIRES_ID_OR_NAME'));
  173. return false;
  174. }
  175. // add the new individual as their name was sent through.
  176. if (!$personid)
  177. {
  178. $mdlPerson = JLGModel::getInstance('Person', 'JoomleagueModel');
  179. $name = explode(" ", $name);
  180. $firstname = ''; $nickname=''; $lastname='';
  181. if(count($name) == 1) {
  182. $firstname = ucfirst($name[0]);
  183. $nickname = $name[0];
  184. $lastname = ".";
  185. }
  186. if(count($name) == 2) {
  187. $firstname = ucfirst($name[0]);
  188. $nickname = $name[1];
  189. $lastname = ucfirst($name[1]);
  190. }
  191. if(count($name) == 3) {
  192. $firstname = ucfirst($name[0]);
  193. $nickname = $name[1];
  194. $lastname = ucfirst($name[2]);
  195. }
  196. $data = array(
  197. "firstname" => $firstname,
  198. "nickname" => $nickname,
  199. "lastname" => $lastname,
  200. "published" => 1
  201. );
  202. $personid = $mdlPerson->store($data);
  203. }
  204. if (!$personid) {
  205. $this->setError(Jtext::_('COM_JOOMLEAGUE_ADMIN_QUICKADD_CTRL_FAILED_ADDING_PERSON'));
  206. return false;
  207. }
  208. // check if indivual belongs to project team already
  209. $query = ' SELECT person_id FROM #__joomleague_team_player '
  210. . ' WHERE projectteam_id = '. $this->_db->Quote($projectteam_id)
  211. . ' AND person_id = '. $this->_db->Quote($personid);
  212. $this->_db->setQuery($query);
  213. $res = $this->_db->loadResult();
  214. if (!$res)
  215. {
  216. $tblTeamplayer = JTable::getInstance( 'Teamplayer', 'Table' );
  217. $tblTeamplayer->person_id = $personid;
  218. $tblTeamplayer->projectteam_id = $projectteam_id;
  219. $tblProjectTeam = JTable::getInstance( 'Projectteam', 'Table' );
  220. $tblProjectTeam->load($projectteam_id);
  221. if ( !$tblTeamplayer->check() )
  222. {
  223. $this->setError( $tblTeamplayer->getError() );
  224. return false;
  225. }
  226. // Get data from player
  227. $query = " SELECT picture, position_id
  228. FROM #__joomleague_person AS pl
  229. WHERE pl.id=". $this->_db->Quote($personid) . "
  230. AND pl.published = 1";
  231. $this->_db->setQuery( $query );
  232. $person = $this->_db->loadObject();
  233. if ( $person )
  234. {
  235. if ($person->position_id)
  236. {
  237. $query = "SELECT id FROM #__joomleague_project_position ";
  238. $query.= " WHERE position_id = " . $person->position_id;
  239. $query.= " AND project_id = " . $tblProjectTeam->project_id;
  240. $this->_db->setQuery($query);
  241. if ($resPrjPosition = $this->_db->loadObject())
  242. {
  243. $tblTeamplayer->project_position_id = $resPrjPosition->id;
  244. }
  245. }
  246. $tblTeamplayer->picture = $person->picture;
  247. $tblTeamplayer->projectteam_id = $projectteam_id;
  248. }
  249. $query = " SELECT max(ordering) count
  250. FROM #__joomleague_team_player";
  251. $this->_db->setQuery( $query );
  252. $tp = $this->_db->loadObject();
  253. $tblTeamplayer->ordering = (int) $tp->count + 1;
  254. if ( !$tblTeamplayer->store() )
  255. {
  256. $this->setError( $tblTeamplayer->getError() );
  257. return false;
  258. }
  259. }
  260. return true;
  261. }
  262. }
  263. ?>