+
+ // getReportOptions - returns an array of report options constructed from session bean.
+ //
+ // Note: similarly to ttFavReportHelper::getReportOptions, this function is a part of
+ // refactoring to simplify maintenance of report generating functions, as we currently
+ // have 2 sets: normal reporting (from bean), and fav report emailing (from db fields).
+ // Using options obtained from either db or bean shall allow us to use only one set of functions.
+ static function getReportOptions($bean) {
+ global $user;
+
+ // Prepare an array of report options.
+ $options = array();
+
+ // Construct one by one.
+ $options['name'] = null; // No name required.
+ $options['user_id'] = $user->id; // Not sure if we need user_id here. Fav reports use it to recycle $user object in cron.php.
+ $options['client_id'] = $bean->getAttribute('client');
+ $options['cf_1_option_id'] = $bean->getAttribute('option');
+ $options['project_id'] = $bean->getAttribute('project');
+ $options['task_id'] = $bean->getAttribute('task');
+ $options['billable'] = $bean->getAttribute('include_records');
+ $options['invoice'] = $bean->getAttribute('invoice');
+ $options['paid_status'] = $bean->getAttribute('paid_status');
+ if (is_array($bean->getAttribute('users'))) $options['users'] = join(',', $bean->getAttribute('users'));
+ $options['period'] = $bean->getAttribute('period');
+ $options['period_start'] = $bean->getAttribute('start_date');
+ $options['period_end'] = $bean->getAttribute('end_date');
+ $options['show_client'] = $bean->getAttribute('chclient');
+
+/*
+ * TODO: remaining fields to fill in...
+ `show_invoice` tinyint(4) NOT NULL default 0, # whether to show invoice column
+ `show_paid` tinyint(4) NOT NULL default 0, # whether to show paid column
+ `show_ip` tinyint(4) NOT NULL default 0, # whether to show ip column
+ */
+ $options['show_project'] = $bean->getAttribute('chproject');
+ $options['show_start'] = $bean->getAttribute('chstart');
+/*
+ `show_duration` tinyint(4) NOT NULL default 0, # whether to show duration field
+ `show_cost` tinyint(4) NOT NULL default 0, # whether to show cost field
+ */
+ $options['show_task'] = $bean->getAttribute('chtask');
+ $options['show_end'] = $bean->getAttribute('chfinish');
+/*
+ `show_note` tinyint(4) NOT NULL default 0, # whether to show note column
+ `show_custom_field_1` tinyint(4) NOT NULL default 0, # whether to show custom field 1
+ */
+ $options['show_custom_field_1'] = $bean->getAttribute('chcf_1');
+ /*
+ `show_work_units` tinyint(4) NOT NULL default 0, # whether to show work units
+ `show_totals_only` tinyint(4) NOT NULL default 0, # whether to show totals only
+ **/
+ $options['group_by'] = $bean->getAttribute('group_by');
+/*
+ * TODO: remaining fields to fill in...
+ `status` tinyint(4) default 1, # favorite report status
+ PRIMARY KEY (`id`)
+);
+ */
+ return $options;
+ }
+
+ // verifyBean is a security function to make sure data in bean makes sense for a group.
+ static function verifyBean($bean) {
+ global $user;
+
+ // Check users.
+ $users_in_bean = $bean->getAttribute('users');
+ if (is_array($users_in_bean)) {
+ $users_in_group = ttTeamHelper::getUsers();
+ foreach ($users_in_group as $user_in_group) {
+ $valid_ids[] = $user_in_group['id'];
+ }
+ foreach ($users_in_bean as $user_in_bean) {
+ if (!in_array($user_in_bean, $valid_ids)) {
+ return false;
+ }
+ }
+ }
+
+ // TODO: add additional checks here. Perhaps do it before saving the bean for consistency.
+ return true;
+ }