Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: None  |  size: 4.42 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Making code more efficient and less a copy and paste
  2. $sql = 'SELECT * FROM `phpbb_profile_fields_data`';
  3.  
  4.   $result = $db->sql_query($sql);
  5.  
  6.   while ($row = $db->sql_fetchrow($result))
  7.   {      
  8.     /////////////////////////////////// START - 8 MAN BONETHRASHER
  9.     $normal = '';
  10.     $hard = '';
  11.     $nightmare = '';
  12.     /////// START - CHECK NORMAL
  13.     if ($row['pf_kp_em_no_bonethr'] == '1')
  14.         {
  15.             $normal = '&nbsp;<img src="/styles/subsilver2/theme/images/soap/no.png" />';
  16.         }      
  17.     else if ($row['pf_kp_em_no_bonethr'] == '2')
  18.         {
  19.             $normal = '';
  20.         }      
  21.     else if (is_null($row['pf_kp_em_no_bonethr']))
  22.         {
  23.             echo "Boss was set as NULL This should not happen!";
  24.         }
  25.     else
  26.         {
  27.             echo "Sosia messed up go hit him in the face.";
  28.         }
  29.     /////// END - CHECK NORMAL  
  30.     /////// START - CHECK HARD
  31.     if ($row['pf_kp_em_ha_bonethr'] == '1')
  32.         {
  33.             $hard = '&nbsp;<img src="/styles/subsilver2/theme/images/soap/ha.png" />';
  34.         }      
  35.     else if ($row['pf_kp_em_ha_bonethr'] == '2')
  36.         {
  37.             $hard = '';
  38.         }      
  39.     else if (is_null($row['pf_kp_em_ha_bonethr']))
  40.         {
  41.             echo "Boss was set as NULL This should not happen!";
  42.         }
  43.     else
  44.         {
  45.             echo "Sosia messed up go hit him in the face.";
  46.         }
  47.     /////// END - CHECK HARD    
  48.     /////// START - CHECK NIGHTMARE
  49.     if ($row['pf_kp_em_kn_bonethr'] == '1')
  50.         {
  51.             $nightmare ='&nbsp;<img src="/styles/subsilver2/theme/images/soap/kn.png" />';
  52.         }      
  53.     else if ($row['pf_kp_em_kn_bonethr'] == '2')
  54.         {
  55.             $nightmare = '';
  56.         }      
  57.     else if (is_null($row['pf_kp_em_kn_bonethr']))
  58.         {
  59.             echo "Boss was set as NULL This should not happen!";
  60.         }
  61.     else
  62.         {
  63.             echo "Sosia messed up go hit him in the face.";
  64.         }
  65.     /////// END - CHECK NIGHTMARE  
  66.  
  67. if ($normal == '' && $hard == '' && $nightmare == '')
  68.         {
  69.  
  70.         }
  71.     else
  72.         {
  73.             $template->assign_block_vars('8m_bonethrasher', array(
  74.             'VAR1' => $row['pf_guild_name'],
  75.             'VAR2' => $normal,
  76.             'VAR3' => $hard,
  77.             'VAR4' => $nightmare,
  78.             ));
  79.         }
  80.  
  81.   }
  82.  
  83.   $db->sql_freeresult($result);
  84.        
  85. class checks {
  86.  
  87.     public function checkBosses($normalBoss, $hardBoss, $nightmareBoss) {
  88.  
  89.         $difficulties = array();
  90.  
  91.         $difficulties['normal'] = array('boss' => $normalBoss);
  92.         $difficulties['hard'] = array('boss' => $hardBoss);
  93.         $difficulties['nightmare'] = array('boss' => $nightmareBoss);
  94.  
  95.         foreach ($this->difficulties as $difficulty -> $boss) {
  96.             $this->difficulties[$difficulty]['result'] = checkDifficulty($boss['boss'], $difficulty);
  97.         }
  98.  
  99.         $normal = $this->difficulties['normal']['result'];
  100.         $hard = $this->difficulties['hard']['result'];
  101.         $nightmare = $this->difficulties['nightmare']['result'];
  102.  
  103.  
  104.         if ($normal == '' && $hard == '' && $nightmare == '') {
  105.             return null;
  106.         } else {
  107.             return array(
  108.                 'normal' => $normal,
  109.                 'hard' => $hard,
  110.                 'nightmare' => $nightmare,
  111.             );
  112.         }
  113.     }
  114.  
  115.     protected function checkDifficulty($boss, $difficulty) {
  116.  
  117.         if ($difficulty == 'normal') {
  118.             $image = '&nbsp;<img src="/styles/subsilver2/theme/images/soap/no.png" />';
  119.         } else if ($difficulty == 'hard') {
  120.             $image = '&nbsp;<img src="/styles/subsilver2/theme/images/soap/ha.png" />';
  121.         } else if ($difficulty == 'nightmare') {
  122.             $image = '&nbsp;<img src="/styles/subsilver2/theme/images/soap/kn.png" />';
  123.         }
  124.  
  125.         if ($boss == '1') {
  126.             return $image;
  127.         } else if ($boss == '2') {
  128.             return '';
  129.         } else if (is_null($boss)) {
  130.             echo "Boss was set as NULL This should not happen!";
  131.         } else {
  132.             echo "Sosia messed up go hit him in the face.";
  133.         }
  134.     }
  135. }
  136.        
  137. $checkResult = checks::checkBosses($row['pf_kp_em_no_bonethr'], $row['pf_kp_em_ha_bonethr'], $row['pf_kp_em_kn_bonethr']);
  138.  
  139. if ($checkResult != null) {
  140.     $template->assign_block_vars('8m_bonethrasher', array(
  141.         'VAR1' => $row['pf_guild_name'],
  142.         'VAR2' => $normal,
  143.         'VAR3' => $hard,
  144.         'VAR4' => $nightmare,
  145.     ));
  146. }
  147.        
  148. foreach ($bosses as $boss) {
  149.     //Full code to be repeated for each boss here
  150. }