예제 #1
0
 public function ajaxbukhsearchAction()
 {
     $id = $this->_request->getParam('id');
     $tsols = new Model_DbTable_Tsol();
     $tsol = $tsols->fetchAll($tsols->select());
     $ret = array();
     foreach ($tsol as $key => $value) {
         $ret[] = array('id' => $value['id'], 'name' => $value['name']);
     }
     echo Zend_Json::encode($ret);
 }
예제 #2
0
 public function ajaxdavaascoreAction()
 {
     $davaa_num = $this->_request->getParam('davaa_num');
     $fantasy_id = $this->_request->getParam('fantasy_id');
     $onoo = new Model_DbTable_Score();
     $ds = new Model_DbTable_Davaa();
     $dd = $ds->fetchAll($ds->select()->where('fantasy_id =' . $fantasy_id . ' AND davaa_num =' . $davaa_num));
     $barildaan = 0;
     foreach ($dd as $key => $value) {
         $barildaan = $value['barildaan_id'];
     }
     $onoolts = new Model_DbTable_Onoolt();
     $onoolt = $onoolts->fetchAll($onoolts->select()->where('barildaan_id =' . $barildaan));
     $bukhs = new Model_DbTable_Bukh();
     $tsols = new Model_DbTable_Tsol();
     $tsoluud = array();
     $tsol = $tsols->fetchAll($tsols->select());
     for ($i = 0; $i < 1000; $i++) {
         $tsoluud[$i] = 0;
     }
     foreach ($tsol as $key => $value) {
         $tsoluud[$value['id']] = $value['score'];
     }
     //Энд галуудын фантази оноог тооцоолно
     $davaagals = new Model_DbTable_Davaagal();
     $davaa = $davaagals->fetchAll($davaagals->select()->where('fantasy_id = ' . $fantasy_id . ' AND davaa_num = ' . $davaa_num));
     foreach ($davaa as $key => $val) {
         $bukh1_id = $val['bukh1_id'];
         $bukh2_id = $val['bukh2_id'];
         $bukh3_id = $val['bukh3_id'];
         $bukh4_id = $val['bukh4_id'];
         $bukh5_id = $val['bukh5_id'];
         $bukh6_id = $val['bukh6_id'];
         $bukh7_id = $val['bukh7_id'];
         $bukh8_id = $val['bukh8_id'];
         $bukh9_id = $val['bukh9_id'];
         $bukh10_id = $val['bukh10_id'];
         $galid = $val['gal_id'];
         $score = 0;
         $bukh1score = 0;
         $bukh2score = 0;
         $bukh3score = 0;
         $bukh4score = 0;
         $bukh5score = 0;
         $bukh6score = 0;
         $bukh7score = 0;
         $bukh8score = 0;
         $bukh9score = 0;
         $bukh10score = 0;
         foreach ($onoolt as $key => $on) {
             if ($on['bukh1_id'] == $bukh1_id || $on['bukh2_id'] == $bukh1_id) {
                 $bukh = $bukhs->fetchAll($bukhs->select()->where('id =' . $on['bukh1_id'] . ' OR id = ' . $on['bukh2_id']));
                 foreach ($bukh as $key => $bb) {
                     if ($bb['id'] == $on['bukh1_id']) {
                         $bukh1_tsolid = $bb['tsolid'];
                     } else {
                         $bukh2_tsolid = $bb['tsolid'];
                     }
                 }
                 if ($on['bukh1_id'] == $bukh1_id) {
                     if ($on['davsanbukh_id'] == $bukh1_id) {
                         $bukh1score += ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 20 + 1000;
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh1score -= ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 10 + 300;
                         }
                     }
                 } else {
                     if ($on['davsanbukh_id'] == $bukh1_id) {
                         $bukh1score += ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 20 + 1000;
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh1score -= ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 10 + 300;
                         }
                     }
                 }
             }
             if ($on['bukh1_id'] == $bukh2_id || $on['bukh2_id'] == $bukh2_id) {
                 $bukh = $bukhs->fetchAll($bukhs->select()->where('id =' . $on['bukh1_id'] . ' OR id = ' . $on['bukh2_id']));
                 foreach ($bukh as $key => $bb) {
                     if ($bb['id'] == $on['bukh1_id']) {
                         $bukh1_tsolid = $bb['tsolid'];
                     } else {
                         $bukh2_tsolid = $bb['tsolid'];
                     }
                 }
                 if ($on['bukh1_id'] == $bukh2_id) {
                     if ($on['davsanbukh_id'] == $bukh2_id) {
                         $bukh2score += ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh2score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh2score -= ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 10 + 300;
                         }
                     }
                 } else {
                     if ($on['davsanbukh_id'] == $bukh2_id) {
                         $bukh2score += ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh2score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh2score -= ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 10 + 300;
                         }
                     }
                 }
             }
             ////////////////////////////////////////////////////////////////////////////////////////
             if ($on['bukh1_id'] == $bukh3_id || $on['bukh2_id'] == $bukh3_id) {
                 $bukh = $bukhs->fetchAll($bukhs->select()->where('id =' . $on['bukh1_id'] . ' OR id = ' . $on['bukh2_id']));
                 foreach ($bukh as $key => $bb) {
                     if ($bb['id'] == $on['bukh1_id']) {
                         $bukh1_tsolid = $bb['tsolid'];
                     } else {
                         $bukh2_tsolid = $bb['tsolid'];
                     }
                 }
                 if ($on['bukh1_id'] == $bukh3_id) {
                     if ($on['davsanbukh_id'] == $bukh3_id) {
                         $bukh3score += ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh3score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh3score -= ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 10 + 300;
                         }
                     }
                 } else {
                     if ($on['davsanbukh_id'] == $bukh3_id) {
                         $bukh3score += ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh3score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh3score -= ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 10 + 300;
                         }
                     }
                 }
             }
             /////////////////////////////////////////////////////////////////////////////////////////
             if ($on['bukh1_id'] == $bukh4_id || $on['bukh2_id'] == $bukh4_id) {
                 $bukh = $bukhs->fetchAll($bukhs->select()->where('id =' . $on['bukh1_id'] . ' OR id = ' . $on['bukh2_id']));
                 foreach ($bukh as $key => $bb) {
                     if ($bb['id'] == $on['bukh1_id']) {
                         $bukh1_tsolid = $bb['tsolid'];
                     } else {
                         $bukh2_tsolid = $bb['tsolid'];
                     }
                 }
                 if ($on['bukh1_id'] == $bukh4_id) {
                     if ($on['davsanbukh_id'] == $bukh4_id) {
                         $bukh4score += ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh4score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh4score -= ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 10 + 300;
                         }
                     }
                 } else {
                     if ($on['davsanbukh_id'] == $bukh4_id) {
                         $bukh4score += ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh4score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh4score -= ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 10 + 300;
                         }
                     }
                 }
             }
             /////////////////////////////////////////////////////////////////////////////////////////
             if ($on['bukh1_id'] == $bukh5_id || $on['bukh2_id'] == $bukh5_id) {
                 $bukh = $bukhs->fetchAll($bukhs->select()->where('id =' . $on['bukh1_id'] . ' OR id = ' . $on['bukh2_id']));
                 foreach ($bukh as $key => $bb) {
                     if ($bb['id'] == $on['bukh1_id']) {
                         $bukh1_tsolid = $bb['tsolid'];
                     } else {
                         $bukh2_tsolid = $bb['tsolid'];
                     }
                 }
                 if ($on['bukh1_id'] == $bukh5_id) {
                     if ($on['davsanbukh_id'] == $bukh5_id) {
                         $bukh5score += ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh5score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh5score -= ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 10 + 300;
                         }
                     }
                 } else {
                     if ($on['davsanbukh_id'] == $bukh5_id) {
                         $bukh5score += ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh5score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh5score -= ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 10 + 300;
                         }
                     }
                 }
             }
             /////////////////////////////////////////////////////////////////////////////////////////
             if ($on['bukh1_id'] == $bukh6_id || $on['bukh2_id'] == $bukh6_id) {
                 $bukh = $bukhs->fetchAll($bukhs->select()->where('id =' . $on['bukh1_id'] . ' OR id = ' . $on['bukh2_id']));
                 foreach ($bukh as $key => $bb) {
                     if ($bb['id'] == $on['bukh1_id']) {
                         $bukh1_tsolid = $bb['tsolid'];
                     } else {
                         $bukh2_tsolid = $bb['tsolid'];
                     }
                 }
                 if ($on['bukh1_id'] == $bukh6_id) {
                     if ($on['davsanbukh_id'] == $bukh6_id) {
                         $bukh6score += ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh6score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh6score -= ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 10 + 300;
                         }
                     }
                 } else {
                     if ($on['davsanbukh_id'] == $bukh6_id) {
                         $bukh6score += ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh6score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh6score -= ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 10 + 300;
                         }
                     }
                 }
             }
             /////////////////////////////////////////////////////////////////////////////////////////
             if ($on['bukh1_id'] == $bukh7_id || $on['bukh2_id'] == $bukh7_id) {
                 $bukh = $bukhs->fetchAll($bukhs->select()->where('id =' . $on['bukh1_id'] . ' OR id = ' . $on['bukh2_id']));
                 foreach ($bukh as $key => $bb) {
                     if ($bb['id'] == $on['bukh1_id']) {
                         $bukh1_tsolid = $bb['tsolid'];
                     } else {
                         $bukh2_tsolid = $bb['tsolid'];
                     }
                 }
                 if ($on['bukh1_id'] == $bukh7_id) {
                     if ($on['davsanbukh_id'] == $bukh7_id) {
                         $bukh7score += ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh7score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh7score -= ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 10 + 300;
                         }
                     }
                 } else {
                     if ($on['davsanbukh_id'] == $bukh7_id) {
                         $bukh7score += ($tsoluud[$on['bukh1_id']] - $tsoluud[$on['bukh2_id']]) * 20 + 1000;
                         if ($on['davaa_num'] > 1) {
                             $bukh7score += $on['davaa_num'] * 100;
                         }
                     } else {
                         if ($on['davaa_num'] > 1) {
                             $bukh7score -= ($tsoluud[$on['bukh2_id']] - $tsoluud[$on['bukh1_id']]) * 10 + 300;
                         }
                     }
                 }
             }
         }
         $score = $bukh1score + $bukh2score + $bukh3score + $bukh4score + $bukh5score + $bukh6score + $bukh7score;
         $kk = 1;
         $davaagals->update(array('score' => $score), 'fantasy_id =' . $fantasy_id . ' and davaa_num =' . $davaa_num . ' and gal_id =' . $galid);
         $ds->update(array('active' => $kk), 'fantasy_id =' . $fantasy_id . ' and davaa_num =' . $davaa_num);
         $oo = $onoo->fetchAll($onoo->select()->where('fantasyid =' . $fantasy_id . ' and galid =' . $galid));
         $total = 0;
         foreach ($oo as $key => $value) {
             $total = $value['total_score'];
         }
         $total += $score;
         $onoo->update(array('total_score' => $total), 'fantasyid =' . $fantasy_id . ' and galid =' . $galid);
     }
     $ret = array();
     echo Zend_Json::encode($ret);
 }
예제 #3
0
 public function indexAction()
 {
     $tsols = new Model_DbTable_Tsol();
     $this->view->tsol = $tsols->fetchAll($tsols->select()->order('score DESC'));
 }