Merge branch 'verions-new' of https://git.xdrm.io/ptut/vhost into verions-new
This commit is contained in:
commit
058eb5c275
|
@ -10,7 +10,10 @@ namespace api\module;
|
|||
|
||||
|
||||
use database\core\Repo;
|
||||
use database\repo\database;
|
||||
use database\repo\department;
|
||||
use database\repo\meta;
|
||||
use database\repo\professor;
|
||||
|
||||
class departmentController
|
||||
{
|
||||
|
@ -110,4 +113,52 @@ class departmentController
|
|||
|
||||
}
|
||||
|
||||
|
||||
public function post($args){
|
||||
$name = null;
|
||||
extract($args);
|
||||
|
||||
/** @var meta $metaRepo */
|
||||
$metaRepo = Repo::getRepo("meta");
|
||||
/** @var professor $profRep */
|
||||
$profRep = Repo::getRepo("professor");
|
||||
/** @var database $dbRepo */
|
||||
$dbRepo = Repo::getRepo("database");
|
||||
|
||||
//create the department in the meta database
|
||||
$depId = $metaRepo->createDepartment($name);
|
||||
|
||||
//link the current user to that department
|
||||
$metaRepo->link($_SESSION['CAS']['login'],$depId);
|
||||
|
||||
//create the database and init the structure
|
||||
$dbName = $dbRepo->init($depId);
|
||||
|
||||
//link the new database to the department
|
||||
$metaRepo->createVersion("Version 1",$dbName,$depId,true);
|
||||
|
||||
//get the current user data from current department
|
||||
$user = $profRep->get($_SESSION['CAS']['id'])[0];
|
||||
|
||||
//switch our connexion to that database
|
||||
Repo::switchDatabase($dbName);
|
||||
|
||||
//create the default admin in the new database (categories are common to all department)
|
||||
$profRep->create($user["lastName"],
|
||||
$user["firstName"],
|
||||
$user["Categorie_idCategorie"],
|
||||
$user["hoursToDo"],
|
||||
$user["abreviation"],
|
||||
true,
|
||||
$user["casLogin"]);
|
||||
|
||||
//update user session
|
||||
$departments = $metaRepo->get_prof_departments($user["casLogin"]);
|
||||
$_SESSION['AvailableDepartments'] = $departments;
|
||||
|
||||
//we are good now
|
||||
return ["success" => true];
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -78,7 +78,7 @@
|
|||
}
|
||||
|
||||
public static function switchDatabase(string $dbName){
|
||||
return static::$driver->pdo()->prepare("USE $dbName")->execute();
|
||||
return static::$driver->pdo()->exec("USE $dbName;SET autocommit=1;");
|
||||
}
|
||||
|
||||
public static function getDBConfig() : array{
|
||||
|
|
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: lucas
|
||||
* Date: 09/05/18
|
||||
* Time: 16:55
|
||||
*/
|
||||
|
||||
namespace database\repo;
|
||||
|
||||
|
||||
use database\core\Repo;
|
||||
use database\core\Repo_i;
|
||||
|
||||
class database extends Repo_i {
|
||||
|
||||
/**
|
||||
* @param int $depId
|
||||
* @return String the name of the department database
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function init(int $depId) : String{
|
||||
|
||||
/** @var department $metaRep */
|
||||
$metaRep = Repo::getRepo("department");
|
||||
|
||||
$SQL = "
|
||||
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
|
||||
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `Categorie`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `Categorie` (
|
||||
`idCategorie` INT(11) NOT NULL,
|
||||
`labelCategorie` VARCHAR(100) NOT NULL,
|
||||
PRIMARY KEY (`idCategorie`))
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `Professeur`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `Professeur` (
|
||||
`idProfesseur` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`casLogin` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`lastName` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`firstName` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`abreviation` VARCHAR(10) NULL DEFAULT NULL COMMENT 'Abreviation used in the excel document',
|
||||
`admin` TINYINT(4) NOT NULL DEFAULT 0,
|
||||
`hoursToDo` INT(11) NOT NULL DEFAULT 0,
|
||||
`Categorie_idCategorie` INT(11) NOT NULL,
|
||||
PRIMARY KEY (`idProfesseur`),
|
||||
INDEX `fk_Professeur_Categorie1_idx` (`Categorie_idCategorie` ASC),
|
||||
CONSTRAINT `fk_Professeur_Categorie1`
|
||||
FOREIGN KEY (`Categorie_idCategorie`)
|
||||
REFERENCES `Categorie` (`idCategorie`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 34
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `Formation`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `Formation` (
|
||||
`idFormation` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`labelFormation` VARCHAR(50) NULL DEFAULT NULL,
|
||||
`isInternal` TINYINT(4) NULL DEFAULT 1,
|
||||
PRIMARY KEY (`idFormation`))
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 20
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `UE`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `UE` (
|
||||
`code` VARCHAR(20) NOT NULL,
|
||||
`label` VARCHAR(100) NOT NULL,
|
||||
`required` TINYINT(4) NOT NULL DEFAULT 1,
|
||||
`volumeCours` FLOAT NOT NULL DEFAULT 0,
|
||||
`volumeTP` FLOAT NOT NULL DEFAULT 0,
|
||||
`volumeTD` FLOAT NOT NULL,
|
||||
`disabled` TINYINT(4) NOT NULL DEFAULT 0,
|
||||
`Formation_idFormation` INT(11) NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`code`),
|
||||
INDEX `fk_UE_Formation1_idx` (`Formation_idFormation` ASC),
|
||||
CONSTRAINT `fk_UE_Formation1`
|
||||
FOREIGN KEY (`Formation_idFormation`)
|
||||
REFERENCES `Formation` (`idFormation`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1
|
||||
COMMENT = 'Table contenant le code et le label des UE';
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `Cours`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `Cours` (
|
||||
`idCours` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`UE_code` VARCHAR(20) NOT NULL,
|
||||
`Professeur_idProfesseur` INT(11) NULL DEFAULT NULL,
|
||||
`volume` FLOAT NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`idCours`),
|
||||
INDEX `fk_Cours_UE_idx` (`UE_code` ASC),
|
||||
INDEX `fk_Cours_Professeur1_idx` (`Professeur_idProfesseur` ASC),
|
||||
CONSTRAINT `fk_Cours_Professeur1`
|
||||
FOREIGN KEY (`Professeur_idProfesseur`)
|
||||
REFERENCES `Professeur` (`idProfesseur`)
|
||||
ON DELETE SET NULL
|
||||
ON UPDATE SET NULL,
|
||||
CONSTRAINT `fk_Cours_UE`
|
||||
FOREIGN KEY (`UE_code`)
|
||||
REFERENCES `UE` (`code`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 88
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `GroupeCours`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `GroupeCours` (
|
||||
`Formation_idFormation` INT(11) NOT NULL,
|
||||
`Cours_idCours` INT(11) NOT NULL,
|
||||
PRIMARY KEY (`Formation_idFormation`, `Cours_idCours`),
|
||||
INDEX `fk_Formation_has_Cours_Cours1_idx` (`Cours_idCours` ASC),
|
||||
INDEX `fk_Formation_has_Cours_Formation1_idx` (`Formation_idFormation` ASC),
|
||||
CONSTRAINT `fk_Formation_has_Cours_Cours1`
|
||||
FOREIGN KEY (`Cours_idCours`)
|
||||
REFERENCES `Cours` (`idCours`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_Formation_has_Cours_Formation1`
|
||||
FOREIGN KEY (`Formation_idFormation`)
|
||||
REFERENCES `Formation` (`idFormation`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `TD`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `TD` (
|
||||
`idTD` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`UE_code` VARCHAR(20) NOT NULL,
|
||||
`Professeur_idProfesseur` INT(11) NULL DEFAULT NULL,
|
||||
`volume` FLOAT NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`idTD`),
|
||||
INDEX `fk_TD_UE1_idx` (`UE_code` ASC),
|
||||
INDEX `fk_TD_Professeur1_idx` (`Professeur_idProfesseur` ASC),
|
||||
CONSTRAINT `fk_TD_Professeur1`
|
||||
FOREIGN KEY (`Professeur_idProfesseur`)
|
||||
REFERENCES `Professeur` (`idProfesseur`)
|
||||
ON DELETE SET NULL
|
||||
ON UPDATE SET NULL,
|
||||
CONSTRAINT `fk_TD_UE1`
|
||||
FOREIGN KEY (`UE_code`)
|
||||
REFERENCES `UE` (`code`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 107
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `GroupeTD`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `GroupeTD` (
|
||||
`Formation_idFormation` INT(11) NOT NULL,
|
||||
`TD_idTD` INT(11) NOT NULL,
|
||||
PRIMARY KEY (`Formation_idFormation`, `TD_idTD`),
|
||||
INDEX `fk_Formation_has_TD_TD1_idx` (`TD_idTD` ASC),
|
||||
INDEX `fk_Formation_has_TD_Formation1_idx` (`Formation_idFormation` ASC),
|
||||
CONSTRAINT `fk_Formation_has_TD_Formation1`
|
||||
FOREIGN KEY (`Formation_idFormation`)
|
||||
REFERENCES `Formation` (`idFormation`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_Formation_has_TD_TD1`
|
||||
FOREIGN KEY (`TD_idTD`)
|
||||
REFERENCES `TD` (`idTD`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `TP`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `TP` (
|
||||
`idTP` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`UE_code` VARCHAR(20) NOT NULL,
|
||||
`Professeur_idProfesseur` INT(11) NULL DEFAULT NULL,
|
||||
`volume` FLOAT NOT NULL DEFAULT 0,
|
||||
PRIMARY KEY (`idTP`),
|
||||
INDEX `fk_TP_UE1_idx` (`UE_code` ASC),
|
||||
INDEX `fk_TP_Professeur1_idx` (`Professeur_idProfesseur` ASC),
|
||||
CONSTRAINT `fk_TP_Professeur1`
|
||||
FOREIGN KEY (`Professeur_idProfesseur`)
|
||||
REFERENCES `Professeur` (`idProfesseur`)
|
||||
ON DELETE SET NULL
|
||||
ON UPDATE SET NULL,
|
||||
CONSTRAINT `fk_TP_UE1`
|
||||
FOREIGN KEY (`UE_code`)
|
||||
REFERENCES `UE` (`code`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 164
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `GroupeTP`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `GroupeTP` (
|
||||
`Formation_idFormation` INT(11) NOT NULL,
|
||||
`TP_idTP` INT(11) NOT NULL,
|
||||
PRIMARY KEY (`Formation_idFormation`, `TP_idTP`),
|
||||
INDEX `fk_Formation_has_TP_TP1_idx` (`TP_idTP` ASC),
|
||||
INDEX `fk_Formation_has_TP_Formation1_idx` (`Formation_idFormation` ASC),
|
||||
CONSTRAINT `fk_Formation_has_TP_Formation1`
|
||||
FOREIGN KEY (`Formation_idFormation`)
|
||||
REFERENCES `Formation` (`idFormation`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE,
|
||||
CONSTRAINT `fk_Formation_has_TP_TP1`
|
||||
FOREIGN KEY (`TP_idTP`)
|
||||
REFERENCES `TP` (`idTP`)
|
||||
ON DELETE CASCADE
|
||||
ON UPDATE CASCADE)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
SET SQL_MODE=@OLD_SQL_MODE;
|
||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
|
||||
|
||||
LOCK TABLES `Categorie` WRITE;
|
||||
/*!40000 ALTER TABLE `Categorie` DISABLE KEYS */;
|
||||
INSERT INTO `Categorie` VALUES (1,'Professeurs et Maîtres de Conférences'),(2,'ATERs'),(3,'CDDs enseignement'),(4,'Doctorants Vacataires'),(5,'Permanents UPPA'),(6,'Vacataires extérieurs');
|
||||
/*!40000 ALTER TABLE `Categorie` ENABLE KEYS */;
|
||||
UNLOCK TABLES;
|
||||
";
|
||||
|
||||
return $metaRep->createVersionDatabase($depId,$SQL);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -326,4 +326,12 @@ class meta extends Repo_i {
|
|||
|
||||
return $st->execute($execute);
|
||||
}
|
||||
|
||||
public function createDepartment(String $name) : int{
|
||||
$st = $this->pdo->prepare("INSERT INTO meta_vhost.departement(label) VALUE (:label)");
|
||||
|
||||
$st->execute(["label" => $name]);
|
||||
|
||||
return $this->pdo->lastInsertId();
|
||||
}
|
||||
}
|
|
@ -82,6 +82,14 @@
|
|||
}
|
||||
},
|
||||
|
||||
"POST": {
|
||||
"des": "Create a new Department",
|
||||
"per": [["cas_user"]],
|
||||
"par": {
|
||||
"name": { "des": "Name of the department", "typ": "text"}
|
||||
}
|
||||
},
|
||||
|
||||
"PUT":{
|
||||
"des": "Switch the user on another department database",
|
||||
"per": [["cas_user"]],
|
||||
|
|
Loading…
Reference in New Issue