347 lines
8.4 KiB
PHP
347 lines
8.4 KiB
PHP
<?php
|
|
class Version{
|
|
|
|
protected $ID;
|
|
protected $name;
|
|
protected $sendDate;
|
|
protected $publicFiles;//String "jar xlsx javadoc" in bdd , stored as a string array
|
|
protected $tags;//String "beta bugged" in bdd , stored as a string array
|
|
protected $project;
|
|
protected $language;
|
|
protected $versionAbs;
|
|
|
|
public function __construct($ID){
|
|
$this->ID = $ID;
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE ID=?');
|
|
$req->execute(array($ID));
|
|
if($rep = $req->fetch()){
|
|
$this->valid = TRUE;
|
|
$this->name = $rep['name'];
|
|
$this->sendDate = $rep['sendDate'];
|
|
$this->publicFiles = explode(" ",$rep['publicFiles']);
|
|
$this->tags = explode(" ",$rep['tags']);
|
|
$this->project = new Projet($rep['projectID']);
|
|
$this->language = Langage::getFromID(intval($rep['languageID']));
|
|
$this->versionAbs = $rep['versionAbs'];
|
|
}else{
|
|
$this->valid = FALSE;
|
|
}
|
|
}
|
|
|
|
public function exists(){
|
|
return $this->valid;
|
|
}
|
|
|
|
public function __toString(){
|
|
try{
|
|
$out = 'Version\n';
|
|
$out .= '\tID:' . $this->ID . '\n';
|
|
$out .= '\tName:{' . $this->name . '}\n';
|
|
$out .= '\tSend date:' . $this->sendDate . '\n';
|
|
$out .= '\tPublic files:"' . implode(' ',$this->publicFiles) . '"}\n';
|
|
$out .= '\tTags:"' . implode(' ',$this->tags) . '"}\n';
|
|
$out .= '\tProject:' . substr(str_replace('\n\t',';',$this->project->__toString()),0,-1) . '\n';
|
|
$out .= '\tLanguage:' . $this->language->getName() . '\n';
|
|
$out .= '\tVersion absolue:' . $this->versionAbs . '\n';
|
|
return $out;
|
|
}catch(Error $e){
|
|
echo '#' . $this->language . "#";
|
|
return $e->__toString();
|
|
}
|
|
}
|
|
|
|
|
|
//Getters
|
|
public function getID(){
|
|
return $this->ID;
|
|
}
|
|
|
|
public function getName(){
|
|
return $this->name;
|
|
}
|
|
|
|
public function getSendDate(){
|
|
return $this->sendDate;
|
|
}
|
|
|
|
public function getPublicFiles(){
|
|
//returns a string array
|
|
return $this->publicFiles;
|
|
}
|
|
|
|
public function getTags(){
|
|
//returns a string array
|
|
return $this->tags;
|
|
}
|
|
|
|
public function getProject(){
|
|
return $this->project;
|
|
}
|
|
|
|
public function getLanguage(){
|
|
return $this->language;
|
|
}
|
|
|
|
public function getVersionAbs(){
|
|
return $this->versionAbs;
|
|
}
|
|
|
|
//Useful Getters
|
|
//TODO make all of the following 'is' functions using haveTag
|
|
public function haveTag($tag){
|
|
return in_array($tag,$this->tags);
|
|
}
|
|
|
|
public function isJarPublic(){
|
|
return in_array("jar",$this->publicFiles);
|
|
}
|
|
|
|
public function isJavaPublic(){
|
|
return in_array("java",$this->publicFiles);
|
|
}
|
|
|
|
public function isJavadocPublic(){
|
|
return in_array("javadoc",$this->publicFiles);
|
|
}
|
|
|
|
public function isXlsmPublic(){
|
|
return in_array("xlsm",$this->publicFiles);
|
|
}
|
|
|
|
public function isVbPublic(){
|
|
return in_array("vb",$this->publicFiles);
|
|
}
|
|
|
|
public function isAlpha(){
|
|
return in_array("alpha",$this->tags);
|
|
}
|
|
|
|
public function isBeta(){
|
|
return in_array("beta",$this->tags);
|
|
}
|
|
|
|
public function isRelease(){
|
|
return in_array("release",$this->tags);
|
|
}
|
|
|
|
public function isTest(){
|
|
return in_array("test",$this->tags);
|
|
}
|
|
|
|
public function isBugged(){
|
|
return in_array("bugged",$this->tags);
|
|
}
|
|
|
|
//Setters
|
|
public function storeTags(){
|
|
$rep = $GLOBALS['bdd']->prepare('UPDATE versions SET tags=? WHERE ID=?');
|
|
$rep->execute(array(implode(' ',$this->tags),$this->ID));
|
|
}
|
|
|
|
public function addTag($tag,$store = TRUE){
|
|
$this->deleteTag($tag,FALSE);
|
|
$this->tags[] = $tag;
|
|
if($store)$this->storeTags();
|
|
}
|
|
|
|
public function deleteTag($tag,$store = TRUE){
|
|
$this->tags = array_diff($this->tags,array($tag));
|
|
if($store)$this->storeTags();
|
|
}
|
|
|
|
public function setARelease(){
|
|
$this->deleteTag('alpha',FALSE);
|
|
$this->deleteTag('beta',FALSE);
|
|
$this->addTag('release',FALSE);
|
|
$this->storeTags();
|
|
}
|
|
|
|
public function setAnAlpha(){
|
|
$this->deleteTag('beta',FALSE);
|
|
$this->deleteTag('release',FALSE);
|
|
$this->addTag('alpha',FALSE);
|
|
$this->storeTags();
|
|
}
|
|
|
|
public function setABeta(){
|
|
$this->deleteTag('alpha',FALSE);
|
|
$this->deleteTag('release',FALSE);
|
|
$this->addTag('beta',FALSE);
|
|
$this->storeTags();
|
|
}
|
|
|
|
public function setATest(){
|
|
$this->addTag('test');
|
|
}
|
|
|
|
public function setNotATest(){
|
|
$this->delTag('test');
|
|
}
|
|
|
|
public function setBugged(){
|
|
$this->addTag('bugged');
|
|
}
|
|
|
|
public function setNotBugged(){
|
|
$this->delTag('bugged');
|
|
}
|
|
|
|
public function storePublicFiles(){
|
|
$rep = $GLOBALS['bdd']->prepare('UPDATE versions SET publicFiles=? WHERE ID=?');
|
|
$rep->execute(array(implode(' ',$this->publicFiles),$this->ID));
|
|
}
|
|
|
|
public function addPublicFile($file,$store = TRUE){
|
|
$this->deletePublicFile($file,FALSE);
|
|
$this->publicFiles[] = $file;
|
|
if($store)$this->storePublicFiles();
|
|
}
|
|
|
|
public function deletePublicFile($file,$store = TRUE){
|
|
$this->publicFiles = array_diff($this->publicFiles,array($file));
|
|
if($store)$this->storePublicFiles();
|
|
}
|
|
|
|
public function setJarPublic(){
|
|
$this->addPublicFile('jar');
|
|
}
|
|
|
|
public function setJarNotPublic(){
|
|
$this->deletePublicFile('jar');
|
|
}
|
|
|
|
public function setJavaPublic(){
|
|
$this->addPublicFile('java');
|
|
}
|
|
|
|
public function setJavaNotPublic(){
|
|
$this->deletePublicFile('java');
|
|
}
|
|
|
|
public function setJavadocPublic(){
|
|
$this->addPublicFile('javadoc');
|
|
}
|
|
|
|
public function setJavadocNotPublic(){
|
|
$this->deletePublicFile('javadoc');
|
|
}
|
|
|
|
public function setXlsmPublic(){
|
|
$this->addPublicFile('xlsm');
|
|
}
|
|
|
|
public function setXlsmNotPublic(){
|
|
$this->deletePublicFile('xlsm');
|
|
}
|
|
|
|
public function setVbPublic(){
|
|
$this->addPublicFile('vb');
|
|
}
|
|
|
|
public function setVbNotPublic(){
|
|
$this->deletePublicFile('vb');
|
|
}
|
|
|
|
|
|
//Version Getter
|
|
private static function versionGetterOutput($req){
|
|
$out = array();
|
|
while($rep = $req->fetch())
|
|
$out[] = new Version($rep['ID']);
|
|
switch(count($out)){
|
|
case 0:
|
|
return NULL;
|
|
case 1:
|
|
return $out[0];
|
|
default:
|
|
return $out;
|
|
}
|
|
}
|
|
|
|
public static function getFromProjectAndName($project,$name){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE projectID=? AND name=?');
|
|
$req->execute(array($project->getID(),$name));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getFromProjectLanguageAndVersionAbs($project,$language,$versionAbs){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE projectID=? AND languageID=? AND versionAbs=?');
|
|
$req->execute(array($project->getID(),$language->getID(),$versionAbs));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getFromLanguage($language){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE languageID=?');
|
|
$req->execute(array($language->getID()));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getFromProject($project){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE projectID=?');
|
|
$req->execute(array($project->getID()));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getHighestFromProject($project){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE projectID=? and versionAbs=(SELECT MAX(versionAbs) FROM versions WHERE projectID=?)');
|
|
$req->execute(array($project->getID(),$project->getID()));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getFromName($name){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE name=?');
|
|
$req->execute(array($name));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getFromTag($tag){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions');
|
|
$req->execute();
|
|
$out = array();
|
|
while ($rep = $req->fetch()) {
|
|
$projet = new Version($rep['ID']);
|
|
if ($projet->haveTag($tag))
|
|
$out[] = $projet;
|
|
}
|
|
switch(count($out)){
|
|
case 0:
|
|
return NULL;
|
|
case 1:
|
|
return $out[0];
|
|
default:
|
|
return $out;
|
|
}
|
|
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getFromSendDate($date){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE sendDate=?');
|
|
$req->execute(array($date));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getSendedLaterThan($date){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE sendDate>?');
|
|
$req->execute(array($date));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public static function getSendedEarlierThan($date){
|
|
$req = $GLOBALS['bdd']->prepare('SELECT * FROM versions WHERE sendDate<?');
|
|
$req->execute(array($date));
|
|
return Version::versionGetterOutput($req);
|
|
}
|
|
|
|
public function delete(){
|
|
$req = $GLOBALS['bdd']->prepare('DELETE FROM versions WHERE ID=?');
|
|
$req->execute(array($this->getID()));
|
|
$this->valid = FALSE;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|