コード例 #1
0
 public static function pegarDoPost()
 {
     //var_dump($_POST);
     $item = null;
     $tipo_item = intval($_POST['item_tipo']);
     $slug = '';
     $nome = '';
     $peso = 0.0;
     $preco = 0.0;
     $pericia_slug = '';
     if (array_key_exists('slug', $_POST)) {
         $slug = $_POST['slug'];
     }
     if (array_key_exists('nome', $_POST)) {
         $nome = $_POST['nome'];
     }
     if (array_key_exists('peso', $_POST)) {
         $peso = floatval($_POST['peso']);
     }
     if (array_key_exists('preco', $_POST)) {
         $preco = floatval($_POST['preco']);
     }
     if (array_key_exists('pericia_slug', $_POST)) {
         $pericia_slug = $_POST['pericia_slug'];
     }
     switch ($tipo_item) {
         case 1:
             $item = new Item($slug, $nome, $peso, $preco);
             break;
         case 2:
         case 3:
             $item = new Arma($slug, $nome, $peso, $preco, $pericia_slug);
             if (array_key_exists('arma_mao', $_POST)) {
                 $item->setMao($_POST['arma_mao']);
             }
             break;
         case 4:
             $item = new ArmaMuscular($slug, $nome, $peso, $preco, $pericia_slug);
             break;
         default:
             throw new Exception("Tipo de Item '{$_POST['item_tipo']}' não existe.");
             break;
     }
     if (in_array($tipo_item, array(2, 3))) {
         if (count($_POST['dano']) > 0) {
             foreach ($_POST['dano'] as $dado) {
                 $item->addDano(new ArmaDano($dado['tipo'], $dado['dano'], intval($dado['bonus']), floatval($dado['alcance_de']), floatval($dado['alcance_ate']), 0, intval($dado['preparacao'])));
             }
         }
         /*
                     <input type="hidden" class="tipo" name="dano[<?php echo $i; ?>][tipo]" value="<?php echo $dano->getTipo(); ?>">
                     <input type="hidden" class="dano" name="dano[<?php echo $i; ?>][dano]" value="<?php echo $dano->getDano(); ?>">
                     <input type="hidden" class="bonus" name="dano[<?php echo $i; ?>][bonus]" value="<?php echo $dano->getBonus(); ?>">
                     <input type="hidden" class="preparacao" name="dano[<?php echo $i; ?>][preparacao]" value="<?php //echo $dano->getPreparacao(); ?>">
                     <input type="hidden" class="alcance_de" name="dano[<?php echo $i; ?>][alcance_de]" value="<?php echo $dano->getAlcanceDe(); ?>">
                     <input type="hidden" class="alcance_ate" name="dano[<?php echo $i; ?>][alcance_ate]" value="<?php echo $dano->getAlcanceAte(); ?>">
         */
     }
     if ($tipo_item == 3) {
         $longe = new ArmaMuscular($slug, $nome, $peso, $preco, $pericia_slug);
         static::carregarLongeDoPost($longe);
         $item->setArremesso($longe);
     } elseif ($tipo_item == 4) {
         static::carregarLongeDoPost($item);
     }
     /*
             echo '<pre>';
             var_dump($_POST, $item);
             echo '</pre>';
             exit();
     * 
     */
     return $item;
 }