1
+ <?php
2
+ /** Metadata Model Base */
3
+ abstract class MetadataModelBase extends AppModel
4
+ {
5
+ /** Constructor*/
6
+ public function __construct ()
7
+ {
8
+ parent ::__construct ();
9
+ $ this ->_name = 'metadata ' ;
10
+ $ this ->_key = 'metadata_id ' ;
11
+ $ this ->_mainData = array (
12
+ 'metadata_id ' => array ('type ' => MIDAS_DATA ),
13
+ 'metadatatype ' => array ('type ' => MIDAS_DATA ),
14
+ 'element ' => array ('type ' => MIDAS_DATA ),
15
+ 'qualifier ' => array ('type ' => MIDAS_DATA ),
16
+ 'description ' => array ('type ' => MIDAS_DATA ),
17
+ 'value ' => array ('type ' => MIDAS_DATA ),
18
+ 'itemrevision_id ' => array ('type ' => MIDAS_MANY_TO_ONE , 'model ' => 'ItemRevision ' , 'parent_column ' => 'itemrevision_id ' , 'child_column ' => 'itemrevision_id ' ),
19
+ );
20
+ $ this ->initialize (); // required
21
+ } // end __construct()
22
+
23
+ abstract function getMetadata ($ type ,$ element ,$ qualifier );
24
+ protected abstract function saveMetadataValue ($ metadataDao );
25
+ abstract function getMetadataValueExists ($ metadataDao );
26
+
27
+ /** Add a metadata
28
+ * @return MetadataDao */
29
+ function addMetadata ($ type ,$ element ,$ qualifier ,$ description )
30
+ {
31
+ // Gets the metadata
32
+ $ metadata = $ this ->getMetadata ($ type ,$ element ,$ qualifier );
33
+ if ($ metadata )
34
+ {
35
+ throw new Zend_Exception ("Metadata already exists. " );
36
+ }
37
+
38
+ $ this ->loadDaoClass ('MetadataDao ' );
39
+ $ metadataDao = new MetadataDao ();
40
+ $ metadataDao ->setMetadatatype ($ type );
41
+ $ metadataDao ->setElement ($ element );
42
+ $ metadataDao ->setQualifier ($ qualifier );
43
+ $ metadataDao ->setDescription ($ description );
44
+
45
+ if (!$ this ->save ($ metadataDao ))
46
+ {
47
+ return false ;
48
+ }
49
+ return $ metadataDao ;
50
+ } // end addMetadataValue()
51
+
52
+ /** Add a metadata to an itemRevision
53
+ * @return MetadataDao */
54
+ function addMetadataValue ($ itemRevisionDao ,$ type ,$ element ,$ qualifier ,$ value )
55
+ {
56
+ if (!$ itemRevisionDao instanceof $ itemRevisionDao )
57
+ {
58
+ throw new Zend_Exception ("Error parameters. " );
59
+ }
60
+
61
+ // Gets the metadata
62
+ $ metadataDao = $ this ->getMetadata ($ type ,$ element ,$ qualifier );
63
+
64
+ if (!$ metadataDao )
65
+ {
66
+ throw new Zend_Exception ("Metadata " .$ element .". " .$ qualifier ." doesn't exist.
67
+ You should add it before adding a value. " );
68
+ }
69
+ $ metadataDao ->setItemrevisionId ($ itemRevisionDao ->getKey ());
70
+ $ metadataDao ->setValue ($ value );
71
+ if ($ this ->getMetadataValueExists ($ metadataDao ))
72
+ {
73
+ throw new Zend_Exception ("This metadata value already exists for that revision. " );
74
+ }
75
+ $ this ->saveMetadataValue ($ metadataDao );
76
+ } // end addMetadataValue()
77
+
78
+ } // end class MetadataModelBase
0 commit comments