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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
| <?php
class Media extends AppModel {
var $name = 'Media';
var $validate = array(
'mediatype_id' => array('numeric'),
'level_id' => array('numeric'),
'title' => array('blank' =>
array('rule' => 'notEmpty','required' => true, 'allowEmpty' => false)
),
'description' => array('blank' =>
array('rule' => 'notEmpty','required' => true, 'allowEmpty' => false)
),
'url' => array('url' =>
array('rule' => 'url', 'required' => true, 'allowEmpty' => false, 'message' => URL_MESSAGE)
),
'icon_url' => array('url' =>
array('rule' => 'url', 'required' => false, 'allowEmpty' => true, 'message' => URL_MESSAGE)
),
);
//The Associations below have been created with all possible keys, those that are not needed can be removed
var $belongsTo = array(
'Mediatype' => array(
'className' => 'Mediatype',
'foreignKey' => 'mediatype_id',
'conditions' => '',
'fields' => '',
'order' => ''
),
'Level' => array(
'className' => 'Level',
'foreignKey' => 'level_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
var $hasAndBelongsToMany = array(
'Course' => array(
'className' => 'Course',
'joinTable' => 'courses_media',
'foreignKey' => 'media_id',
'associationForeignKey' => 'course_id',
'unique' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
nsertQuery' => "REPLACE INTO 'courses_media' (course_id, media_id)
VALUES('" . mysql_real_escape_string($this->data['Media']['id']),
),
'Subject' => array(
'className' => 'Subject',
'joinTable' => 'media_subjects',
'foreignKey' => 'media_id',
'associationForeignKey' => 'subject_id',
'unique' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
function beforeSave() {
if (!empty($this->data['Media']['file']['name'])) {
if ($this->data['Media']['file']['name'] = $this->__uploadFile($this->data['Media']['file'])) {
$this->data['Media']['filepath'] = $this->data['Media']['file']['name'];
$this->data['Media']['filesize'] = $this->data['Media']['file']['size'];
$this->data['Media']['file_extension'] = end(explode(".", $this->data['Media']['file']['name']));
} else {
return false;
}
}
return true;
}
function beforeDelete() {
$media = $this->read(null, $this->id);
return $this->__deleteFile($media['Media']['filepath']);
}
}
?> |