Conditions | 17 |
Paths | 432 |
Total Lines | 98 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
48 | public function submit($_content=null) |
||
49 | { |
||
50 | if (is_array($_content)) |
||
51 | { |
||
52 | $config = new Api\Config(self::CONFIG_APP); |
||
|
|||
53 | if ($_content['postpone']) |
||
54 | { |
||
55 | Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT,time()+$_content['postpone'],self::CONFIG_APP); |
||
56 | $what = 'postpone'; |
||
57 | } |
||
58 | elseif(!$_content['cancel']) |
||
59 | { |
||
60 | Api\Config::save_value(self::CONFIG_LAST_SUBMIT,time(),self::CONFIG_APP); |
||
61 | Api\Config::save_value(self::CONFIG_SUBMIT_ID,empty($_content['submit_id']) ? '***none***' : $_content['submit_id'],self::CONFIG_APP); |
||
62 | Api\Config::save_value(self::CONFIG_COUNTRY,empty($_content['country']) ? '***multinational***' : $_content['country'],self::CONFIG_APP); |
||
63 | Api\Config::save_value(self::CONFIG_USAGE_TYPE,$_content['usage_type'],self::CONFIG_APP); |
||
64 | Api\Config::save_value(self::CONFIG_INSTALL_TYPE,$_content['install_type'],self::CONFIG_APP); |
||
65 | Api\Config::save_value(self::CONFIG_POSTPONE_SUBMIT,null,self::CONFIG_APP); // remove evtl. postpone time |
||
66 | $what = 'submitted'; |
||
67 | } |
||
68 | Egw::redirect_link('/admin/index.php','ajax=true&statistics='.($what ? $what : 'canceled'),'admin'); |
||
69 | } |
||
70 | $sel_options['usage_type'] = array( |
||
71 | 'commercial' => lang('Commercial: all sorts of companies'), |
||
72 | 'governmental' => lang('Governmental: incl. state or municipal authorities or services'), |
||
73 | 'educational' => lang('Educational: Universities, Schools, ...'), |
||
74 | 'non-profit' => lang('Non profit: Clubs, associations, ...'), |
||
75 | 'personal' => lang('Personal: eg. within a family'), |
||
76 | 'other' => lang('Other'), |
||
77 | ); |
||
78 | $sel_options['install_type'] = array( |
||
79 | 'docker' => lang('Docker'), |
||
80 | 'package' => lang('RPM or Debian package'), |
||
81 | 'git' => lang('Git clone'), |
||
82 | 'archive' => lang('Archive: zip or tar'), |
||
83 | 'other' => lang('Other'), |
||
84 | ); |
||
85 | $sel_options['postpone'] = array( |
||
86 | //10 => '10 secs', |
||
87 | 3600 => lang('one hour'), |
||
88 | 2*3600 => lang('two hours'), |
||
89 | 24*3600 => lang('one day'), |
||
90 | 2*24*3600 => lang('two days'), |
||
91 | 7*24*3600 => lang('one week'), |
||
92 | 14*24*3600 => lang('two weeks'), |
||
93 | 30*24*3600 => lang('one month'), |
||
94 | 60*24*3600 => lang('two months'), |
||
95 | ); |
||
96 | $config = Api\Config::read(self::CONFIG_APP); |
||
97 | //_debug_array($config); |
||
98 | $content = array_merge(self::gather_data(),array( |
||
99 | 'statistic_url' => self::STATISTIC_URL, |
||
100 | 'submit_host' => parse_url(self::SUBMIT_URL,PHP_URL_HOST), |
||
101 | 'submit_url' => self::SUBMIT_URL, |
||
102 | 'last_submitted' => $config[self::CONFIG_LAST_SUBMIT], |
||
103 | )); |
||
104 | //_debug_array($content); |
||
105 | |||
106 | // show previous submit ID |
||
107 | if ($config['statistics_submit_id']) |
||
108 | { |
||
109 | $content['submit_id'] = $config['statistics_submit_id'] == '***none***' ? '' : $config['statistics_submit_id']; |
||
110 | } |
||
111 | // show previous Api\Country |
||
112 | if ($config[self::CONFIG_COUNTRY]) |
||
113 | { |
||
114 | $content['country'] = $config[self::CONFIG_COUNTRY] == '***multinational***' ? '' : $config[self::CONFIG_COUNTRY]; |
||
115 | } |
||
116 | // show previous usage_type |
||
117 | if ($config[self::CONFIG_USAGE_TYPE]) |
||
118 | { |
||
119 | $content['usage_type'] = $config[self::CONFIG_USAGE_TYPE]; |
||
120 | } |
||
121 | // check if we detected svn or rpm/deb packages --> readonly |
||
122 | if ($content['install_type'] && isset($sel_options['install_type'][$content['install_type']])) |
||
123 | { |
||
124 | $sel_options['install_type'] = array($content['install_type'] => $sel_options['install_type'][$content['install_type']]); |
||
125 | } |
||
126 | // else default to previous type |
||
127 | elseif($config[self::CONFIG_INSTALL_TYPE]) |
||
128 | { |
||
129 | $content['install_type'] = $config[self::CONFIG_INSTALL_TYPE]; |
||
130 | } |
||
131 | // check if we are due for a new submission |
||
132 | if (!isset($config[self::CONFIG_LAST_SUBMIT]) || $config[self::CONFIG_LAST_SUBMIT ] <= time()-self::SUBMISION_RATE) |
||
133 | { |
||
134 | // clear etemplate_exec_id and replace form.action, before submitting the form |
||
135 | $content['onclick'] = "return app.admin.submit_statistic(this.form,'$content[submit_url]');"; |
||
136 | } |
||
137 | else // we are not due --> tell it the user |
||
138 | { |
||
139 | $readonlys['submit'] = $readonlys['postpone'] = true; |
||
140 | $content['msg'] = lang('Your last submission was less then %1 days ago!', |
||
141 | ceil((time()-$config[self::CONFIG_LAST_SUBMIT])/24/3600)); |
||
142 | } |
||
143 | $GLOBALS['egw_info']['flags']['app_header'] = lang('Submit statistic information'); |
||
144 | $tmpl = new Etemplate('admin.statistics'); |
||
145 | $tmpl->exec('admin.admin_statistics.submit',$content,$sel_options,$readonlys); |
||
146 | } |
||
315 |