All Data Structures Functions Variables Pages
ProjectsDemoDataMaker.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 Zurmo Inc.
5  *
6  * Zurmo is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  *
13  * Zurmo is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  *
23  * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
24  * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
25  *
26  * The interactive user interfaces in original and modified versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  *
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the Zurmo
32  * logo and Zurmo copyright notice. If the display of the logo is not reasonably
33  * feasible for technical reasons, the Appropriate Legal Notices must display the words
34  * "Copyright Zurmo Inc. 2017. All rights reserved".
35  ********************************************************************************/
36 
41  {
46  protected $loadMagnitude = 5;
47 
48  public static function getDependencies()
49  {
50  return array();
51  }
52 
56  public function makeAll(& $demoDataHelper)
57  {
58  assert('$demoDataHelper instanceof DemoDataHelper');
59  $projects = array();
60  $super = User::getByUsername('super');
61  for ($i = 0; $i < $this->resolveQuantityToLoad(); $i++)
62  {
63  $project = new Project();
64  $project->owner = $demoDataHelper->getRandomByModelName('User');
65  $account = $demoDataHelper->getRandomByModelName('Account');
66  $project->accounts->add($account);
67  $this->populateModel($project);
68  $project->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
69  $saved = $project->save();
70  assert('$saved');
71  $project = Project::getById($project->id);
73  securableItemGivenPermissionsForGroup($project, Group::getByName(Group::EVERYONE_GROUP_NAME));
74  $project->save();
75  assert('$saved');
76  ProjectAuditEvent::logAuditEvent(ProjectAuditEvent::PROJECT_CREATED, $project, $project->name);
77  self::addDemoTasks($project, 3, $demoDataHelper);
78  $projects[] = $project->id;
79  }
80  $demoDataHelper->setRangeByModelName('Project', $projects[0], $projects[count($projects)-1]);
81  }
82 
87  public function populateModel(& $model)
88  {
89  assert('$model instanceof Project');
90  parent::populateModel($model);
91  $projectRandomData = ZurmoRandomDataUtil::
92  getRandomDataByModuleAndModelClassNames('ProjectsModule', 'Project');
93  $name = RandomDataUtil::getRandomValueFromArray($projectRandomData['names']);
94  $model->name = $name;
95  $model->description = $name . ' Description';
96  }
97 
102  protected static function addDemoTasks($project, $taskInputCount = 1, & $demoDataHelper)
103  {
104  $randomTasks = self::getRandomTasks();
105  for ($i = 0; $i < count($randomTasks); $i++)
106  {
107  $task = new Task();
108  $task->name = $randomTasks[$i]['name'];
109  $task->owner = $demoDataHelper->getRandomByModelName('User');
110  $task->requestedByUser = $demoDataHelper->getRandomByModelName('User');
111  $task->completedDateTime = '0000-00-00 00:00:00';
112  $task->project = $project;
113  $task->status = Task::STATUS_NEW;
114  $task->save();
115  //Notification subscriber
116  $notificationSubscriber = new NotificationSubscriber();
117  $notificationSubscriber->person = $demoDataHelper->getRandomByModelName('User');
118  $notificationSubscriber->hasReadLatest = false;
119  //Task check list items
120  $task->notificationSubscribers->add($notificationSubscriber);
121  $taskCheckListItems = $randomTasks[$i]['checkListItems'];
122  foreach ($taskCheckListItems as $itemKey => $name)
123  {
124  $taskCheckListItem = new TaskCheckListItem();
125  $taskCheckListItem->name = $name;
126  if (($itemKey * $i * rand(5, 100)) % 3 == 0)
127  {
128  $taskCheckListItem->completed = true;
129  }
130  $task->checkListItems->add($taskCheckListItem);
131  ProjectsUtil::logTaskCheckItemEvent($task, $taskCheckListItem);
132  }
133  //Comments
134  $commentItems = $randomTasks[$i]['comments'];
135  foreach ($commentItems as $description)
136  {
137  $comment = new Comment();
138  $comment->description = $description;
139  $comment->setScenario('importModel');
140  $comment->createdByUser = $demoDataHelper->getRandomByModelName('User');
141  $task->comments->add($comment);
142  ProjectsUtil::logAddCommentEvent($task, strval($comment));
143  }
144  //Add Super user
145  $comment = new Comment();
146  $comment->description = 'Versatile idea regarding the task';
147  $task->comments->add($comment);
148  $task->addPermissions(Group::getByName(Group::EVERYONE_GROUP_NAME), Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER);
149  $task->save();
150  $currentStatus = $task->status;
152  $task = Task::getById($task->id);
153  $task->status = RandomDataUtil::getRandomValueFromArray(self::getTaskStatusOptions());
154  $task->save();
156  securableItemGivenPermissionsForGroup($task, Group::getByName(Group::EVERYONE_GROUP_NAME));
157  $task->save();
159  Task::getStatusDisplayName($currentStatus),
160  Task::getStatusDisplayName(intval($task->status)));
161  }
162  }
163 
168  protected static function getRandomTasks()
169  {
170  $tasksList = array(
171  'Create Demo Proposal',
172  'Come up with a contacts list for the client',
173  'Prepare telephone directory for the company',
174  'Get an accounting software',
175  'Usage of google analytics on company website',
176  );
177  $multipliedTasksList = array();
178  for ($i = 1; $i <= 2; $i++)
179  {
180  foreach ($tasksList as $task)
181  {
182  $multipliedTasksList[] = array('name' => $task . ' v' . $i,
183  'checkListItems' => self::getTaskCheckListItems($task),
184  'comments' => self::getTaskComments($task));
185  }
186  }
187  return $multipliedTasksList;
188  }
189 
194  protected static function getTaskCheckListItems($key)
195  {
196  $checklistItemsArray = array(
197  'Create Demo Proposal' => array('Get the requirements',
198  'Analysis of requirements'),
199  'Come up with a contacts list for the client' => array('Call the contacts',
200  'Enter the data into excel'),
201  'Prepare telephone directory for the company' => array('Gather the list of employees with there contact details',
202  'Enter the data into excel'),
203  'Get an accounting software' => array('Research the available softwares',
204  'Discuss with the team'),
205  'Usage of google analytics on company website' => array('Explore the usage',
206  'Implement into the website'),
207  );
208 
209  return $checklistItemsArray[$key];
210  }
211 
216  protected static function getTaskComments($key)
217  {
218  $comments = array(
219  'Create Demo Proposal' => array('Quite useful moving forward',
220  'Would be helful for other people'),
221  'Come up with a contacts list for the client' => array('Very beneficial for the company',
222  'Helpful for the sales team'),
223  'Prepare telephone directory for the company' => array('Very helpful for the employees',
224  'Can easily track people'),
225  'Get an accounting software' => array('Helpful for finance department',
226  'Reduced work load',
227  'Less number of people required'),
228  'Usage of google analytics on company website' => array('Aids in site analysis',
229  'Would be helpful from SEO perspective'),
230  );
231  return $comments[$key];
232  }
233 
238  protected static function getTaskStatusOptions()
239  {
241  return array_keys($data);
242  }
243  }
244 ?>
static getByUsername($username)
Definition: User.php:49
static logTaskStatusChangeEvent(Task $task, $currentStatusLabel, $newStatusLabel)
static addDemoTasks($project, $taskInputCount=1, &$demoDataHelper)
static getRandomValueFromArray($array)
static getRandomDataByModuleAndModelClassNames($moduleClassName, $modelClassName)
Definition: Task.php:37
static logAddTaskEvent(Task $task)
static getStatusDisplayName($status)
Definition: Task.php:267
static getByName($name)
Definition: Group.php:57
static getStatusDropDownArray()
Definition: Task.php:252
static getById($id, $modelClassName=null)
static logAuditEvent($eventName, Project $project, $data=null, User $user=null)
static logAddCommentEvent(Task $task, $comment)
static securableItemGivenPermissionsForGroup(SecurableItem $securableItem, Group $group)
static logTaskCheckItemEvent(Task $task, TaskCheckListItem $taskCheckListItem)
Generated on Fri Jun 5 2020 07:10:34