Beispiel #1
0
function expandArray($startstr, $array, &$resarray)
{
    if (sizeof($array) == 1) {
        $current = $array[0];
        $start = $current[0];
        $end = $current[1];
        for ($i = $start; $i <= $end; $i++) {
            $resarray[] = $startstr . '[' . $i . ']';
        }
    } else {
        $current = array_shift($array);
        $start = $current[0];
        $end = $current[1];
        for ($i = $start; $i <= $end; $i++) {
            expandArray('[' . $i . ']', $array, $resarray);
        }
    }
}
Beispiel #2
0
 function getDataQuestions()
 {
     $questions = array();
     foreach ($this->getQuestions() as $name => $question) {
         if ($question->getQuestionType()->getAnswerType() == QUESTION_TYPE_SETOF) {
             foreach ($question->getQuestionType()->getEnumeratedOptions() as $key => $enum) {
                 if ($question->isArray()) {
                     $resarray = array();
                     expandArray('', $question->getArray(), $resarray);
                     foreach ($resarray as $bracketName) {
                         $questions[$name . $bracketName . '[' . $key . ']'] = $question;
                     }
                 } else {
                     $questions[$name . '[' . $key . ']'] = $question;
                 }
             }
             //array! []
         } else {
             if ($question->isArray()) {
                 $resarray = array();
                 expandArray('', $question->getArray(), $resarray);
                 foreach ($resarray as $bracketName) {
                     $questions[$name . $bracketName] = $question;
                 }
             } else {
                 $questions[$name] = $question;
             }
         }
     }
     return $questions;
 }
Beispiel #3
0
 public function board_constuction($bsid)
 {
     $this->load->helper('vitaly');
     $this->db->select(array('id', 'position', 'row', 'column', 'adjacent', 'port_rotation'));
     $this->db->where(array('bs_id' => $bsid));
     $this->db->order_by('row', 'asc');
     $this->db->order_by('column', 'asc');
     $aMap = $this->db->get('soc_boardsetup')->result_array();
     $aMaxVal = $this->db->query('Select MAX(`row`) as maxRow, Max(`column`) as maxColumn from `soc_boardsetup` WHERE `bs_id` =' . $bsid)->row_array();
     $maxRow = $aMaxVal['maxRow'];
     $maxCol = $aMaxVal['maxColumn'];
     $countMapArray = 0;
     $this->db->select(array('resource_hex', 'number_tile'));
     $this->db->where(array('bs_id' => $bsid));
     $aPieces = $this->db->get('soc_piecesetup')->row_array();
     $aHex = expandArray(json_decode($aPieces['resource_hex']));
     $aTile = expandArray(json_decode($aPieces['number_tile']));
     shuffle($aHex);
     shuffle($aTile);
     $countHex = 0;
     $countTile = 0;
     $gameid = 1;
     $data = array();
     //$maxMapCount = sizeof($aMap);
     for ($r = 1; $r <= $maxRow; ++$r) {
         for ($c = 1; $c <= $maxCol; ++$c) {
             $class = "row_even";
             if (abs($r) % 2 > 0) {
                 $class = "row_odd";
             }
             if ($c == 1) {
                 $class .= " start";
             }
             if (!array_key_exists($countMapArray, $aMap) || $c != $aMap[$countMapArray]['column']) {
                 //It's a blank piece
                 $data[$r][$c] = array('id' => 'r' . $r . 'c' . $c, 'class' => $class, 'type' => 'blank', 'src' => 'Hexagon - template.png');
                 continue;
             } elseif ($aMap[$countMapArray]['position'] < 0) {
                 // It's water!
                 $adjacent = $aMap[$countMapArray]['adjacent'];
                 $custom = 'data-adjHex="' . $adjacent . '"';
                 if (!is_null($aMap[$countMapArray]['port_rotation'])) {
                     $this->db->select("type");
                     $this->db->where(array("hex" => $aMap[$countMapArray]['position']));
                     $aTemp = $this->db->get("soc_portlocation")->row_array();
                     $class .= " rotate" . $aMap[$countMapArray]['port_rotation'];
                     $src = 'Hexagon -port.png';
                     $numberTile = '<div class="portTile port_' . $aTemp['type'] . '"></div>';
                 } else {
                     $src = 'Hexagon water.png';
                     $numberTile = '';
                 }
                 $data[$r][$c] = array('id' => 'r' . $r . 'c' . $c, 'class' => $class, 'type' => 'water', 'src' => $src, 'custom' => $custom, 'numberTile' => $numberTile);
             } else {
                 //It's a land card
                 $curHex = $aHex[$countHex];
                 if ($curHex == 'desert') {
                     $curTile = '0';
                     $numberTile = '';
                 } else {
                     $curTile = $aTile[$countTile];
                     ++$countTile;
                     $numberTile = '<div class="numberTile">' . $curTile . '</div>';
                 }
                 ++$countHex;
                 $adjacent = $aMap[$countMapArray]['adjacent'];
                 $custom = 'data-adjHex="' . $adjacent . '"';
                 $data[$r][$c] = array('id' => 'r' . $r . 'c' . $c, 'class' => $class, 'type' => 'land', 'src' => 'Hexagon -' . $curHex . '.png', 'resource' => $curHex, 'number' => $curTile, 'custom' => $custom, 'numberTile' => $numberTile);
             }
             /*
             //This is necessary to setup the adjacent in the database
             if (($r % 2) > 0) { //odd row
                 $adjacent = 'r' . ($r - 1) . 'c' . ($c - 1) . ' ';
                 $adjacent .= 'r' . ($r - 1) . 'c' . $c . ' ';
                 $adjacent .= 'r' . $r . 'c' . ($c + 1) . ' ';
                 $adjacent .= 'r' . ($r + 1) . 'c' . $c . ' ';
                 $adjacent .= 'r' . ($r + 1) . 'c' . ($c - 1) . ' ';
                 $adjacent .= 'r' . $r . 'c' . ($c - 1);
             
             } else { // even row
                 $adjacent = 'r' . ($r - 1) . 'c' . $c . ' ';
                 $adjacent .= 'r' . ($r - 1) . 'c' . ($c + 1) . ' ';
                 $adjacent .= 'r' . $r . 'c' . ($c + 1) . ' ';
                 $adjacent .= 'r' . ($r + 1) . 'c' . ($c + 1) . ' ';
                 $adjacent .= 'r' . ($r + 1) . 'c' . $c . ' ';
                 $adjacent .= 'r' . $r . 'c' . ($c - 1);
             }
             
             $this->db->where('id', $aMap[$countMapArray]['id']);
             $this->db->update('soc_boardsetup', array('adjacent' => $adjacent));
             //end of temporary section
             */
             $countMapArray++;
         }
     }
     $final = array('data' => $data, 'maxCol' => $maxCol, 'maxRow' => $maxRow);
     return $final;
 }