1 | <?php |
||
25 | class Docman_MetadataComparator { |
||
26 | var $docmanIcons; |
||
27 | var $srcGo; |
||
28 | var $dstGo; |
||
29 | |||
30 | function Docman_MetadataComparator($srcGroupId, $dstGroupId, $themePath) { |
||
31 | $this->docmanIcons = new Docman_Icons($themePath.'/images/ic/'); |
||
32 | $pm = ProjectManager::instance(); |
||
33 | $this->srcGo = $pm->getProject($srcGroupId); |
||
34 | $this->dstGo = $pm->getProject($dstGroupId); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * For a five object iterator, return an array of object indexed by |
||
39 | * $func applied on object. |
||
40 | */ |
||
41 | function getArrayFromIterator($iter, $func) { |
||
42 | $a = array(); |
||
43 | while($iter->valid()) { |
||
44 | $e = $iter->current(); |
||
45 | $a[$e->$func()] = $e; |
||
46 | $iter->next(); |
||
47 | } |
||
48 | return $a; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * |
||
53 | */ |
||
54 | function checkMdDifferences($srcMd, $dstMd, $loveMap) { |
||
55 | $diffArray = array(); |
||
56 | if(!$dstMd->sameDescription($srcMd)) { |
||
57 | $diffArray[] = $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_param_desc'); |
||
58 | } |
||
59 | if(!$dstMd->sameIsEmptyAllowed($srcMd)) { |
||
60 | $diffArray[] = $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_param_allowempty', array($GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_param_'.$srcMd->getIsEmptyAllowed()))); |
||
61 | } |
||
62 | if(!$dstMd->sameIsMultipleValuesAllowed($srcMd)) { |
||
63 | $diffArray[] = $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_param_allowmultiplevalue', array($GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_param_'.$srcMd->getIsMultipleValuesAllowed()))); |
||
64 | } |
||
65 | if(!$dstMd->sameUseIt($srcMd)) { |
||
66 | $diffArray[] = $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_param_useit', array($GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_param_'.$srcMd->getUseIt()))); |
||
67 | } |
||
68 | return $diffArray; |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * Same algo used in Docman_View_ItemDetailsSectionPaste::_checkLoveToImport |
||
74 | */ |
||
75 | function getLoveCompareTable($srcMd, $dstMd, $mdMap, &$sthToImport) { |
||
76 | $html = ''; |
||
77 | |||
78 | if($srcMd->getLabel() == 'status') { |
||
79 | // No differences possible with status. |
||
80 | return $html; |
||
81 | } |
||
82 | |||
83 | // Get list of ListOfValues elements from dst project |
||
84 | $srcLoveFactory = new Docman_MetadataListOfValuesElementFactory($srcMd->getId()); |
||
85 | $srcLoveIter = $srcLoveFactory->getIteratorByFieldId($srcMd->getId(), $srcMd->getLabel(), true); |
||
86 | |||
87 | // Get list of ListOfValues elements from dst project |
||
88 | $dstLoveFactory = new Docman_MetadataListOfValuesElementFactory($dstMd->getId()); |
||
89 | $dstLoveIter = $dstLoveFactory->getIteratorByFieldId($dstMd->getId(), $dstMd->getLabel(), true); |
||
90 | $dstLoveArray = $this->getArrayFromIterator($dstLoveIter, 'getId'); |
||
91 | |||
92 | $maxRow = max($srcLoveIter->count(), $dstLoveIter->count()); |
||
93 | |||
94 | // Keep a trace of matching love |
||
95 | $matchingLove = array(); |
||
96 | while($srcLoveIter->valid()) { |
||
97 | $srcLove = $srcLoveIter->current(); |
||
98 | $rowStyle = 'missing'; |
||
99 | |||
100 | // Compute the differences |
||
101 | $dstLove = false; |
||
102 | if(isset($mdMap['love'][$srcLove->getId()])) { |
||
103 | $dstLove = $dstLoveArray[$mdMap['love'][$srcLove->getId()]]; |
||
104 | $matchingLove[$dstLove->getId()] = true; |
||
105 | $rowStyle = 'equals'; |
||
106 | } else { |
||
107 | $sthToImport = true; |
||
108 | } |
||
109 | |||
110 | $html .= "<tr>\n"; |
||
111 | |||
112 | // Name |
||
113 | $html .= "<td style=\"padding-left: 2em;\"></td>\n"; |
||
114 | $html .= "<td>".Docman_MetadataHtmlList::_getElementName($srcLove)."</td>\n"; |
||
115 | |||
116 | // Presence in source project |
||
117 | $html .= '<td align="center"><img src="'.$this->docmanIcons->getThemeIcon('tick.png').'" /></td>'; |
||
118 | |||
119 | // Presence in destination project |
||
120 | $html .= "<td align=\"center\">"; |
||
121 | switch($rowStyle) { |
||
122 | case 'equals': |
||
123 | $html .= '<img src="'.$this->docmanIcons->getThemeIcon('tick.png').'" />'; |
||
124 | break; |
||
125 | } |
||
126 | $html .= "</td>\n"; |
||
127 | |||
128 | // Differences |
||
129 | $html .= "<td class=\"docman_md_".$rowStyle."\">"; |
||
130 | switch($rowStyle) { |
||
131 | case 'missing': |
||
132 | $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_status_'.$rowStyle); |
||
133 | } |
||
134 | $html .= "</td>\n"; |
||
135 | |||
136 | // Action |
||
137 | $html .= "<td>"; |
||
138 | switch($rowStyle) { |
||
139 | case 'missing': |
||
140 | $html .= $GLOBALS['Language']->getText('plugin_docman', 'admin_md_import_tbl_act_import_love', array($srcLove->getName())); |
||
141 | } |
||
142 | $html .= "</td\n>"; |
||
143 | |||
144 | $html .= "</tr>\n"; |
||
145 | |||
146 | $srcLoveIter->next(); |
||
147 | } |
||
148 | |||
149 | // Append to the table the list of values elements in the dst project |
||
150 | // that where not present in the src project. |
||
151 | foreach($dstLoveArray as $love) { |
||
152 | if(!isset($matchingLove[$love->getId()])) { |
||
153 | $html .= "<tr>\n"; |
||
154 | // Name |
||
155 | $html .= "<td> </td>\n"; |
||
156 | $html .= "<td>".$love->getName()."</td>\n"; |
||
157 | // Presence in source project |
||
158 | $html .= "<td></td>\n"; |
||
159 | // Presence in destination project |
||
160 | $html .= '<td align="center"><img src="'.$this->docmanIcons->getThemeIcon('tick.png').'" /></td>'; |
||
161 | // Differences |
||
162 | $html .= "<td></td>\n"; |
||
163 | // Action |
||
164 | $html .= "<td></td>\n"; |
||
165 | $html .= "</tr>\n"; |
||
166 | } |
||
167 | } |
||
168 | |||
169 | return $html; |
||
170 | } |
||
171 | |||
172 | function getMetadataCompareTable(&$sthToImport) { |
||
357 | } |
||
358 | |||
359 | ?> |
||
360 |