PageRenderTime 26ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/install/TeamDemoData.php

https://github.com/jacknicole/sugarcrm_dev
PHP | 191 lines | 101 code | 23 blank | 67 comment | 5 complexity | 1cf512bcb6834cdac2c154b2f42d14cd MD5 | raw file
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM Community Edition is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. class TeamDemoData {
  38. var $_team;
  39. var $_large_scale_test;
  40. var $guids = array(
  41. 'jim' => 'seed_jim_id',
  42. 'sarah' => 'seed_sarah_id',
  43. 'sally' => 'seed_sally_id',
  44. 'max' => 'seed_max_id',
  45. 'will' => 'seed_will_id',
  46. 'chris' => 'seed_chris_id',
  47. /*
  48. * Pending fix of demo data mechanism
  49. 'jim' => 'jim00000-0000-0000-0000-000000000000',
  50. 'sarah' => 'sarah000-0000-0000-0000-000000000000',
  51. 'sally' => 'sally000-0000-0000-0000-000000000000',
  52. 'max' => 'max00000-0000-0000-0000-000000000000',
  53. 'will' => 'will0000-0000-0000-0000-000000000000',
  54. 'chris' => 'chris000-0000-0000-0000-000000000000',
  55. */
  56. );
  57. /**
  58. * Constructor for creating demo data for teams
  59. */
  60. function TeamDemoData($seed_team, $large_scale_test = false)
  61. {
  62. $this->_team = $seed_team;
  63. $this->_large_scale_test = $large_scale_test;
  64. }
  65. /**
  66. *
  67. */
  68. function create_demo_data() {
  69. global $current_language;
  70. global $sugar_demodata;
  71. foreach($sugar_demodata['teams'] as $v)
  72. {
  73. if (!$this->_team->retrieve($v['team_id']))
  74. $this->_team->create_team($v['name'], $v['description'], $v['team_id']);
  75. }
  76. if($this->_large_scale_test)
  77. {
  78. $team_list = $this->_seed_data_get_team_list();
  79. foreach($team_list as $team_name)
  80. {
  81. $this->_quick_create($team_name);
  82. }
  83. }
  84. $this->add_users_to_team();
  85. }
  86. function add_users_to_team() {
  87. // Create the west team memberships
  88. $this->_team->retrieve("West");
  89. $this->_team->add_user_to_team($this->guids['sarah']);
  90. $this->_team->add_user_to_team($this->guids['sally']);
  91. $this->_team->add_user_to_team($this->guids["max"]);
  92. // Create the east team memberships
  93. $this->_team->retrieve("East");
  94. $this->_team->add_user_to_team($this->guids["will"]);
  95. $this->_team->add_user_to_team($this->guids['chris']);
  96. }
  97. /**
  98. *
  99. */
  100. function get_random_team()
  101. {
  102. $team_list = $this->_seed_data_get_team_list();
  103. $team_list_size = count($team_list);
  104. $random_index = mt_rand(0,$team_list_size-1);
  105. return $team_list[$random_index];
  106. }
  107. /**
  108. *
  109. */
  110. function get_random_teamset()
  111. {
  112. $team_list = $this->_seed_data_get_teamset_list();
  113. $team_list_size = count($team_list);
  114. $random_index = mt_rand(0,$team_list_size-1);
  115. return $team_list[$random_index];
  116. }
  117. /**
  118. *
  119. */
  120. function _seed_data_get_teamset_list()
  121. {
  122. $teamsets = Array();
  123. $teamsets[] = array("East", "West");
  124. $teamsets[] = array("East", "West", "1");
  125. $teamsets[] = array("West", "East");
  126. $teamsets[] = array("West", "East", "1");
  127. $teamsets[] = array("1", "East");
  128. $teamsets[] = array("1", "West");
  129. return $teamsets;
  130. }
  131. /**
  132. *
  133. */
  134. function _seed_data_get_team_list()
  135. {
  136. $teams = Array();
  137. //bug 28138 todo
  138. $teams[] = "north";
  139. $teams[] = "south";
  140. $teams[] = "left";
  141. $teams[] = "right";
  142. $teams[] = "in";
  143. $teams[] = "out";
  144. $teams[] = "fly";
  145. $teams[] = "walk";
  146. $teams[] = "crawl";
  147. $teams[] = "pivot";
  148. $teams[] = "money";
  149. $teams[] = "dinero";
  150. $teams[] = "shadow";
  151. $teams[] = "roof";
  152. $teams[] = "sales";
  153. $teams[] = "pillow";
  154. $teams[] = "feather";
  155. return $teams;
  156. }
  157. /**
  158. *
  159. */
  160. function _quick_create($name)
  161. {
  162. if (!$this->_team->retrieve($name))
  163. {
  164. $this->_team->create_team($name, $name, $name);
  165. }
  166. }
  167. }
  168. ?>