- Making code more efficient and less a copy and paste
- $sql = 'SELECT * FROM `phpbb_profile_fields_data`';
- $result = $db->sql_query($sql);
- while ($row = $db->sql_fetchrow($result))
- {
- /////////////////////////////////// START - 8 MAN BONETHRASHER
- $normal = '';
- $hard = '';
- $nightmare = '';
- /////// START - CHECK NORMAL
- if ($row['pf_kp_em_no_bonethr'] == '1')
- {
- $normal = ' <img src="/styles/subsilver2/theme/images/soap/no.png" />';
- }
- else if ($row['pf_kp_em_no_bonethr'] == '2')
- {
- $normal = '';
- }
- else if (is_null($row['pf_kp_em_no_bonethr']))
- {
- echo "Boss was set as NULL This should not happen!";
- }
- else
- {
- echo "Sosia messed up go hit him in the face.";
- }
- /////// END - CHECK NORMAL
- /////// START - CHECK HARD
- if ($row['pf_kp_em_ha_bonethr'] == '1')
- {
- $hard = ' <img src="/styles/subsilver2/theme/images/soap/ha.png" />';
- }
- else if ($row['pf_kp_em_ha_bonethr'] == '2')
- {
- $hard = '';
- }
- else if (is_null($row['pf_kp_em_ha_bonethr']))
- {
- echo "Boss was set as NULL This should not happen!";
- }
- else
- {
- echo "Sosia messed up go hit him in the face.";
- }
- /////// END - CHECK HARD
- /////// START - CHECK NIGHTMARE
- if ($row['pf_kp_em_kn_bonethr'] == '1')
- {
- $nightmare =' <img src="/styles/subsilver2/theme/images/soap/kn.png" />';
- }
- else if ($row['pf_kp_em_kn_bonethr'] == '2')
- {
- $nightmare = '';
- }
- else if (is_null($row['pf_kp_em_kn_bonethr']))
- {
- echo "Boss was set as NULL This should not happen!";
- }
- else
- {
- echo "Sosia messed up go hit him in the face.";
- }
- /////// END - CHECK NIGHTMARE
- if ($normal == '' && $hard == '' && $nightmare == '')
- {
- }
- else
- {
- $template->assign_block_vars('8m_bonethrasher', array(
- 'VAR1' => $row['pf_guild_name'],
- 'VAR2' => $normal,
- 'VAR3' => $hard,
- 'VAR4' => $nightmare,
- ));
- }
- }
- $db->sql_freeresult($result);
- class checks {
- public function checkBosses($normalBoss, $hardBoss, $nightmareBoss) {
- $difficulties = array();
- $difficulties['normal'] = array('boss' => $normalBoss);
- $difficulties['hard'] = array('boss' => $hardBoss);
- $difficulties['nightmare'] = array('boss' => $nightmareBoss);
- foreach ($this->difficulties as $difficulty -> $boss) {
- $this->difficulties[$difficulty]['result'] = checkDifficulty($boss['boss'], $difficulty);
- }
- $normal = $this->difficulties['normal']['result'];
- $hard = $this->difficulties['hard']['result'];
- $nightmare = $this->difficulties['nightmare']['result'];
- if ($normal == '' && $hard == '' && $nightmare == '') {
- return null;
- } else {
- return array(
- 'normal' => $normal,
- 'hard' => $hard,
- 'nightmare' => $nightmare,
- );
- }
- }
- protected function checkDifficulty($boss, $difficulty) {
- if ($difficulty == 'normal') {
- $image = ' <img src="/styles/subsilver2/theme/images/soap/no.png" />';
- } else if ($difficulty == 'hard') {
- $image = ' <img src="/styles/subsilver2/theme/images/soap/ha.png" />';
- } else if ($difficulty == 'nightmare') {
- $image = ' <img src="/styles/subsilver2/theme/images/soap/kn.png" />';
- }
- if ($boss == '1') {
- return $image;
- } else if ($boss == '2') {
- return '';
- } else if (is_null($boss)) {
- echo "Boss was set as NULL This should not happen!";
- } else {
- echo "Sosia messed up go hit him in the face.";
- }
- }
- }
- $checkResult = checks::checkBosses($row['pf_kp_em_no_bonethr'], $row['pf_kp_em_ha_bonethr'], $row['pf_kp_em_kn_bonethr']);
- if ($checkResult != null) {
- $template->assign_block_vars('8m_bonethrasher', array(
- 'VAR1' => $row['pf_guild_name'],
- 'VAR2' => $normal,
- 'VAR3' => $hard,
- 'VAR4' => $nightmare,
- ));
- }
- foreach ($bosses as $boss) {
- //Full code to be repeated for each boss here
- }