summaryrefslogtreecommitdiff
path: root/model/Album.php
blob: 2254c1089daf8e2e06f4f1f71fa03b6941324b67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
// model/Album.php

class Album extends Page // classe "objet"
{
	public function __construct($page)
	{
		$this->page = $page;
		$this->format = 'json'; // vaut 'html' dans la classe mère
		$this->time = time();
	}

	// GET

	// SET

	// fonctions CRUD

	// create
	public function createVignette($titre, $annee, $pochette)
    {
    	$this->format = 'json';
    	
    	if($pochette != '')
    	{
    		// télécharger la pochette
	        require('model/Image.php');
	        $Image = new Image(false);
	        $Image->upload();

	        /*$erreur = $Image->getError();
	        if(!empty($erreur))
	        {}*/
    	}

    	$albumJSON = json_encode([$titre, $annee, $pochette]);

    	$nom_fichier = 'data/' . $this->page . '/' . $this->format .  '/' . $this->time . '.' . $this->format;

    	$fichier = fopen($nom_fichier, 'w'); // w pour créer ou écraser
	    fputs($fichier, $albumJSON);
	    fclose($fichier);
	    chmod($nom_fichier, 0666);
    }

	// read
	public function getVignette()
	{
		return(file_get_contents($this->fileName));
	}

	// page de l'album
	public static function readOneAlbum($albumCode)
	{
		return(file_get_contents('data/discographie/html/' . $albumCode . '.html'));
	}

	// pour afficher des dates
	/*public function getDate($fileNumber)
	{
		// le 2è paramètre exclut le suffixe .html
		$timestamp = basename($this->files[$fileNumber], '.html');
		return getdate($timestamp);
	}*/

	// update
	public function updateVignette()
	{}

	// delete
	public function delete()
	{
		unlink($this->fileName);
	}
}