/** * Méthode : page qui gère la sauvegarde ou le delete avec un renvois soit au détail ou listing */ public function save($type = FALSE, $idRegion = FALSE) { if (($save = $this->input->post()) !== FALSE) { unset($save['json_actions_length']); $map = Map_Model::instance(); if ($type == 'sauve' || $type == 'valid') { $save['background_color'] = str_replace('#', '0x', $save['background_color']); $save['ambiance'] = str_replace('#', '0x', $save['ambiance']); $map->delete('( x > ' . $save['x'] . ' OR y > ' . $save['y'] . ' OR z > ' . $save['z'] . ' ) AND region_id = ' . $idRegion); $this->region->update($save, $idRegion); } elseif ($type == 'trash') { if (($region = $this->region->select(array('id_parent' => $idRegion), 1)) !== FALSE) { url::redirect('regions/show/' . $idRegion . '?msg=' . urlencode(Kohana::lang('region.yes_parent'))); } $this->region->delete($idRegion); } } $url = 'regions/show/' . $idRegion; if ($type == 'annul' || $type == 'valid' || $type == 'trash') { $url = 'regions'; if (isset($save['id_parent']) && $save['id_parent']) { $url = 'regions/child/' . $save['id_parent']; } } return parent::redirect($url, $type); }
public function __construct() { parent::__construct(); parent::login(); $this->auto_render = FALSE; if (!request::is_ajax()) { return FALSE; } $this->user->x = $this->input->get('x', $this->user->x); $this->user->y = $this->input->get('y', $this->user->y); $this->user->z = $this->input->get('z', $this->user->z); $this->user->region_id = $this->input->get('region', $this->user->region_id); if (($this->data = Map_Model::instance()->select(array('region_id' => $this->user->region_id, 'module_map !=' => '', 'x' => $this->user->x, 'y' => $this->user->y, 'z' => $this->user->z), 1)) && $this->data->action_map && ($this->data->action_map = @unserialize($this->data->action_map))) { $this->user->hp = $this->input->get('hp', $this->user->hp); $this->user->mp = $this->input->get('mp', $this->user->mp); $this->user->xp = $this->input->get('xp', $this->user->xp); $this->user->currentdirection_x = $this->input->get('currentdirection_x', $this->user->currentdirection_x); $this->user->update(); } else { die(Kohana::lang('action.impossible_action')); } }
/** * Methode public : gestion du détail pour le formulaire */ public function form($file, $id_region, $x, $y, $z) { $this->auto_render = FALSE; if (!request::is_ajax()) { return FALSE; } if (!file_exists(MODPATH . 'plugins/views/' . $file . '/admin.php')) { echo '<h4 class="alert_error">' . Kohana::lang('action.alert_view', $file) . '</h4>'; return FALSE; } $data = false; if (($select = Map_Model::instance()->select(array('region_id' => $id_region, 'x' => $x, 'y' => $y, 'z' => $z), 1)) && $select->action_map) { $data = @unserialize($select->action_map); } $view = new View($file . '/admin'); if (file_exists(MODPATH . 'plugins/controllers/admin_' . $file . EXT)) { eval('Admin_' . ucfirst($file) . '_Controller::index( $view );'); } $view->row = $select; $view->data = $data; $view->render(true); }
/** * Gestion edit module * * @return void */ public function up() { $this->auto_render = FALSE; $rows = Map_Model::instance()->select(); foreach ($rows as $row) { if ($row->subX || $row->subY || $row->subZ) { $array['subX'] = $row->x + $row->subX; $array['subX'] = $row->y + $row->subY; $array['subZ'] = $row->z + $row->subZ; $array['x'] = $array['y'] = $array['z'] = 0; Map_Model::instance()->update($array, array('id' => $row->id)); } } }
/** * Gestion remove bloc * * @return void */ public function remove() { $this->auto_render = FALSE; if (!request::is_ajax()) { return FALSE; } $value = $this->input->post(); unset($value['materials']); Map_Model::instance()->delete($value); }
/** * Générer un JSON * * @return void */ public function index($render = TRUE) { $json = new View('map/json'); $json->my = $this->user; if (!($this->region = Region_Model::instance()->select(array('id' => $this->user->region_id), 1))) { return FALSE; } $json->items = Item_Model::instance()->select(); $elements = $modules = $items = FALSE; if (($rows = Map_Model::instance()->select(array('region_id' => $this->region->id), FALSE)) !== FALSE) { $prenoms = Name_Model::instance()->select(); $listName = array(); foreach ($prenoms as $prenom) { $listName[] = ucfirst(mb_strtolower($prenom->prenom)); } $images = file::listing_dir(DOCROOT . 'images/character'); foreach ($rows as $row) { if (!$row->module_map && !$row->bot) { $elements[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . $row->y . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "materials" : [ "' . $row->background_px . '", "' . $row->background_nx . '", "' . $row->background_py . '", "' . $row->background_ny . '", "' . $row->background_pz . '", "' . $row->background_nz . '" ] }'; } else { $data = @unserialize($row->action_map); $action = json_encode($data); if ($row->module_map == 'article') { $article = Article_Model::instance()->select(array('id_article' => $data->id_article, 'article_category_id' => 2, 'status' => 1), 1); $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . $row->y . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : ' . json_encode($article->article) . ' }'; } elseif ($row->bot) { $v = new stdClass(); $v->id = 0; $v->name = $row->bot ? $row->title : $listName[array_rand($listName)]; $v->x = $row->x; $v->y = $row->y; $v->z = $row->z; $v->region_id = $row->region_id; $v->user_id = $this->user->id; if ($row->bot == 2) { $v->image = 'animals/bears.png'; } elseif ($row->bot == 3) { $v->image = 'animals/dog.png'; } else { $v->image = 'character/' . $images[array_rand($images)]; } $v->hp_max = 100; $v->hp = 100; $v->leak = 0; $v->type = $row->bot; $v->fixe = $row->bot && !$row->module_map ? 0 : 1; $v->argent = 1000; $v->xp = 10; $v->niveau = 0; $this->botFixe[] = $v; if ($row->module_map == 'quete') { $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . ($row->y - 1) . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : "" }'; } } else { $modules[] = '{"x" : ' . $row->x . ', "z" : ' . $row->z . ', "y" : ' . ($row->y - 1) . ', "subX" : ' . $row->subX . ', "subZ" : ' . $row->subZ . ', "subY" : ' . $row->subY . ', "data" : ' . $action . ', "article" : "" }'; } } } } $articles = Article_Model::instance()->select(array('region_id' => $this->region->id, 'article_category_id' => 2, 'status' => 1)); $articlesList = null; if ($articles) { foreach ($articles as $row) { $articlesList[] = json_encode($row->reponse ? $row->article . '<div class="reponse">' . $row->reponse . '</div>' : $row->article); } } $this->region->map = new stdClass(); $this->region->map->region = $this->region; $this->region->map->elements = $elements ? implode(',', $elements) : FALSE; $this->region->map->modules = $modules ? implode(',', $modules) : FALSE; $this->region->map->articles = $articlesList ? implode(',', $articlesList) : FALSE; $this->region->map->region->bots = $this->botFixe; $json->region = $this->region; $sounds = file::listing_dir(DOCROOT . 'audios', array('home.mp3')); $json->sounds = $sounds ? json_encode($sounds) : FALSE; return $json->render($render); }
public function __construct() { parent::__construct(); parent::access('element'); $this->elements = Map_Model::instance(); }
/** * Methode : gestion du listing en ajax */ public function resultatAjax() { $this->auto_render = FALSE; if (!request::is_ajax()) { return FALSE; } $arrayCol = array('id_quete', 'title', 'element_detail_id_start', 'element_detail_id_stop', 'niveau', 'argent', 'status'); $searchAjax = Search_Model::instance(); $arrayResultat = $searchAjax->indexRecherche($arrayCol, 'quetes', $this->input); if (($module = Map_Model::instance()->select(array('module_map' => 'quete'), false)) !== FALSE) { foreach ($module as $row) { $showModule[$row->id] = $row; } } $display = false; foreach ($arrayResultat as $row) { $url = 'quetes/show/' . $row->id_quete; $v[] = '<center>' . $row->id_quete . '</center>'; $v[] = html::anchor($url, $row->title); $v[] = isset($showModule[$row->element_detail_id_start]) ? $showModule[$row->element_detail_id_start]->title : Kohana::lang('form.inconnu'); $v[] = isset($showModule[$row->element_detail_id_stop]) ? $showModule[$row->element_detail_id_stop]->title : Kohana::lang('form.inconnu'); $v[] = $row->niveau; $v[] = number_format($row->argent) . ' ' . Kohana::config('game.money'); $v[] = $row->status ? '<strong class="vert">' . Kohana::lang('form.actif') . '</strong>' : '<strong class="rouge">' . Kohana::lang('form.no_actif') . '</strong>'; $v[] = '<center>' . html::anchor($url, html::image('images/template/drawings.png', array('title' => Kohana::lang('form.edit'), 'class' => 'icon_list'))) . '</center>'; $display .= '[' . parent::json($v) . '],'; unset($v); } echo $searchAjax->displayRecherche($display, $this->input->get('sEcho')); }