29-08-2010, 02:51 PM
En fait, après avoir bouclé mon modèle, j'ai rajouté des "knowledges" et ça repart en vrille malgré cette requête. Je poste le schéma de base de donnée.
Voici tout le knowledge_model
Code :
-- phpMyAdmin SQL Dump
-- version 3.2.5
-- http://www.phpmyadmin.net
--
-- Serveur: 127.0.0.1
-- Généré le : Dim 29 Août 2010 à 14:53
-- Version du serveur: 5.1.43
-- Version de PHP: 5.3.2
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Base de données: `bdd_ultima_thulee`
--
-- --------------------------------------------------------
--
-- Structure de la table `utg_country`
--
CREATE TABLE IF NOT EXISTS `utg_country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(25) COLLATE latin1_general_ci NOT NULL,
`description` text COLLATE latin1_general_ci NOT NULL,
`vassal_tax` int(3) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;
--
-- Contenu de la table `utg_country`
--
INSERT INTO `utg_country` (`id`, `name`, `description`, `vassal_tax`) VALUES
(1, 'Saint Asrock', 'trop fort les meilleurs', 15),
(2, 'Marches d''Argent', 'blablabla bla', 10),
(3, 'Malt Saviör', '', 9),
(4, 'Eren-Saviör', '', 5);
-- --------------------------------------------------------
--
-- Structure de la table `utg_country_knowledge`
--
CREATE TABLE IF NOT EXISTS `utg_country_knowledge` (
`id_country` int(11) NOT NULL,
`id_knowledge` int(11) NOT NULL,
`knowledge_acquired` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`knowledge_status` int(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id_country`,`id_knowledge`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
--
-- Contenu de la table `utg_country_knowledge`
--
INSERT INTO `utg_country_knowledge` (`id_country`, `id_knowledge`, `knowledge_acquired`, `knowledge_status`) VALUES
(1, 1, '2010-08-15 12:52:29', 2),
(1, 2, '2010-08-29 12:52:13', 1);
-- --------------------------------------------------------
--
-- Structure de la table `utg_knowledge`
--
CREATE TABLE IF NOT EXISTS `utg_knowledge` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`family` varchar(50) COLLATE latin1_general_ci NOT NULL,
`name` varchar(50) COLLATE latin1_general_ci NOT NULL,
`description` text COLLATE latin1_general_ci NOT NULL,
`img_url` varchar(100) COLLATE latin1_general_ci NOT NULL,
`active` int(1) NOT NULL,
`time_to_discover` int(10) NOT NULL,
`price` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=5 ;
--
-- Contenu de la table `utg_knowledge`
--
INSERT INTO `utg_knowledge` (`id`, `family`, `name`, `description`, `img_url`, `active`, `time_to_discover`, `price`) VALUES
(1, 'Culture', 'Théâtre', 'Le théâtre est l''épanouissement de soi !', '', 1, 86400, 1000),
(2, 'Guerre', 'Archérie', 'L''art de cribler un ennemi de flèches sans prendre de risques !', '', 1, 3600, 5000),
(3, 'Art', 'Peinture', 'L''ère des grands artistes !', '', 1, 36000, 10000),
(4, 'none', 'Superpuissance', 'La puissance des dieux', '', 1, 24575, 100000);
-- --------------------------------------------------------
--
-- Structure de la table `utg_knowledge_links`
--
CREATE TABLE IF NOT EXISTS `utg_knowledge_links` (
`id_knowledge_parent` int(11) NOT NULL,
`id_knowledge_child` int(11) NOT NULL,
`type_parent` int(2) NOT NULL,
PRIMARY KEY (`id_knowledge_parent`,`id_knowledge_child`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
--
-- Contenu de la table `utg_knowledge_links`
--
INSERT INTO `utg_knowledge_links` (`id_knowledge_parent`, `id_knowledge_child`, `type_parent`) VALUES
(1, 2, 1),
(2, 4, 1),
(3, 4, 1);
Voici tout le knowledge_model
Code PHP :
<?php
class Knowledges_model extends Model
{
function Knowledges_model()
{
parent::Model();
}
function Get_knowledges()
{
$fief = $this->session->userdata('current_view_fief');
$knowledges = $this->db->query("
SELECT utg_knowledge.id AS id_knowledge, utg_knowledge.name AS name_knowledge, utg_knowledge.description AS description_knowledge,
utg_knowledge.price AS price_knowledge
FROM utg_knowledge INNER JOIN utg_country_knowledge ON utg_knowledge.id = utg_country_knowledge.id_knowledge
WHERE utg_country_knowledge.id_country = $fief
AND utg_country_knowledge.knowledge_status = 2
");
return $knowledges;
}
function Get_started_knowledges()
{
$fief = $this->session->userdata('current_view_fief');
$started_knowledges = $this->db->query("
SELECT utg_knowledge.id AS id, utg_knowledge.time_to_discover AS research_time, utg_country_knowledge.knowledge_acquired AS start_date,
utg_knowledge.name AS name, utg_knowledge.description AS description, utg_knowledge.family AS family
FROM utg_knowledge INNER JOIN utg_country_knowledge ON utg_knowledge.id = utg_country_knowledge.id_knowledge
WHERE utg_country_knowledge.id_country = $fief
AND utg_country_knowledge.knowledge_status = 1
ORDER BY family ASC
");
return $started_knowledges;
}
function Get_available_knowledges()
{
// On va chercher les savoirs disponibles.
// Les savoirs disponibles répondent a toutes les conditions de liaison et de descendance des autres savoirs
// Il faut d'abord récupérer tous les savoirs détenus par un country
$fief = $this->session->userdata('current_view_fief');
$available_knowledges = $this->db->query("
SELECT knowledge.id, knowledge.name, knowledge.family, knowledge.description, knowledge.img_url,
knowledge.time_to_discover, knowledge.price
FROM utg_knowledge knowledge
WHERE knowledge.active = 1 AND knowledge.id
NOT IN (
SELECT utg_knowledge_links.id_knowledge_parent
FROM utg_knowledge_links
WHERE utg_knowledge_links.id_knowledge_child
NOT IN (
SELECT utg_country_knowledge.id_knowledge
FROM utg_country_knowledge
WHERE utg_country_knowledge.id_country = $fief
)
)
");
return $available_knowledges;
}
}
Et dans le controller on retrouve
Code PHP :
<?php
function knowledges()
{
$data = $this->Retrieve_informations();
$data['to_be_researched_knowledge'] = $this->Get_available_knowledges();
$data['knowned_knowledge'] = $this->Get_knowledges();
$data['started_knowledges'] = $this->Get_started_knowledges();
foreach($data['started_knowledges']->result() as $row)
{
$data['time_left'][$row->id] = $this->TimeToJourJ($row->start_date, $row->research_time);
}
$data["main_content"] = "game/knowledges.php";
$this->load->view("game/includes/template", $data);
}
function Get_available_knowledges()
{
$this->load->model('knowledges_model');
$available_knowledges = $this->knowledges_model->Get_available_knowledges();
return $available_knowledges;
}
function Get_knowledges()
{
$this->load->model('knowledges_model');
$knowledges = $this->knowledges_model->Get_knowledges();
return $knowledges;
}
function Get_started_knowledges()
{
$this->load->model('knowledges_model');
$started_knowledges = $this->knowledges_model->Get_started_knowledges();
return $started_knowledges;
}