-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevent.php
More file actions
70 lines (59 loc) · 2.14 KB
/
event.php
File metadata and controls
70 lines (59 loc) · 2.14 KB
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
<?php
class Event {
private $name;
private $dirId;
private $dirName;
public $id;
public function __construct( $name, $dirName ) {
global $db;
$this->name = $name;
$this->dirName = $dirName;
$dir = new LDirectory( $dirName, true );
$this->dirId = $dir->id;
$this->id = $this->getId();
}
public function add() {
global $db;
if ( empty( $this->id ) ) {
echo $this->id;
$sth = $db->prepare( "INSERT INTO event (name, directoryId, date) VALUES (:name, :directoryId, :date)" );
$sth->execute( array( "name" => $this->name, "directoryId" => $this->dirId, "date" => time() ) );
$this->id = $this->getId();
}
}
public function remove() {
global $db;
if ( ! empty( $this->id ) ) {
$sth = $db->prepare( "DELETE FROM event WHERE name=:name AND directoryId=:directoryId" );
$sth->execute( array( "name" => $this->name, "directoryId" => $this->dirId ) );
$uevent = $this->getUnknown();
$sth = $db->prepare( "UPDATE image SET eventId=:ueventId WHERE eventId=:eventId AND directoryId=:directoryId" );
$sth->execute( array( "ueventId" => $uevent->id, "eventId" => $this->id, "directoryId" => $this->dirId ) );
} else {
echo "Event was not in the database!";
}
}
public function addImage( $image_name ) {
global $db;
$sth = $db->prepare( "UPDATE image SET eventId=:eventId WHERE name=:name AND directoryId=:directoryId" );
$sth->execute( array( "eventId" => $this->id, "name" => $image_name, "directoryId" => $this->dirId ) );
}
public function removeImage( $image_name ) {
global $db;
$uevent = $this->getUnknown();
$sth = $db->prepare( "UPDATE image SET eventId=:eventId WHERE name=:name AND directoryId=:directoryId" );
$sth->execute( array( "eventId" => $uevent->id, "name" => $image_name, "directoryId" => $this->dirId ) );
}
private function getId() {
global $db;
$sth = $db->prepare( "SELECT id FROM event WHERE name=:name AND directoryId=:directoryId" );
$sth->execute( array( "name" => $this->name, "directoryId" => $this->dirId ) );
return $sth->fetchColumn();
}
private function getUnknown() {
$uevent = new Event( "Unknown", $this->dirName );
$uevent->add();
return $uevent;
}
}
?>