1: <?php
2:
3: namespace Alpha\View;
4:
5: use Alpha\Util\Config\ConfigProvider;
6: use Alpha\Util\Extension\MarkdownFacade;
7: use Alpha\Util\Security\SecurityUtils;
8: use Alpha\View\Widget\Button;
9: use Alpha\Controller\Front\FrontController;
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: class ArticleView extends View
54: {
55: 56: 57: 58: 59: 60: 61: 62: 63:
64: public function markdownView($fields = array())
65: {
66: $config = ConfigProvider::getInstance();
67:
68: $markdown = new MarkdownFacade($this->BO);
69:
70: $fields['markdownContent'] = $markdown->getContent();
71:
72: return $this->loadTemplate($this->BO, 'markdown', $fields);
73: }
74:
75: 76: 77: 78: 79: 80: 81:
82: protected function after_createView_callback()
83: {
84: return '<p><strong>Please note</strong> that you will only be able to attach files to the article once it has been created.</p><br>';
85: }
86:
87: 88: 89: 90: 91: 92: 93: 94: 95:
96: public function listView($fields = array())
97: {
98: $fields['dateAdded'] = $this->BO->getCreateTS()->getDate();
99: $fields['editButtonURL'] = FrontController::generateSecureURL('act=Alpha\Controller\ArticleController&ActiveRecordType='.get_class($this->BO).'&ActiveRecordOID='.$this->BO->getOID().'&view=edit');
100:
101: return parent::listView($fields);
102: }
103:
104: 105: 106: 107: 108: 109: 110: 111: 112:
113: public function adminView($fields = array())
114: {
115: $fields['createButtonURL'] = FrontController::generateSecureURL('act=Alpha\Controller\ArticleController&ActiveRecordType='.get_class($this->BO).'&view=create');
116:
117: return parent::adminView($fields);
118: }
119:
120: 121: 122: 123: 124: 125: 126: 127: 128:
129: public function detailedView($fields = array())
130: {
131: $fields['editButtonURL'] = FrontController::generateSecureURL('act=Alpha\Controller\ArticleController&ActiveRecordType='.get_class($this->BO).'&ActiveRecordOID='.$this->BO->getOID().'&view=edit');
132:
133: return parent::detailedView($fields);
134: }
135:
136: 137: 138: 139: 140: 141: 142: 143: 144:
145: public function editView($fields = array())
146: {
147: if (method_exists($this, 'before_editView_callback')) {
148: $this->before_editView_callback();
149: }
150:
151: $config = ConfigProvider::getInstance();
152:
153:
154: if (isset($fields['URI'])) {
155: $fields['formAction'] = $fields['URI'];
156: }
157:
158:
159: $fields['formID'] = stripslashes(get_class($this->BO)).'_'.$this->BO->getID();
160:
161:
162: $fields['formFields'] = $this->renderAllFields('edit');
163:
164:
165: $button = new Button('submit', 'Save', 'saveBut');
166: $fields['saveButton'] = $button->render();
167:
168: $js = "if(window.jQuery) {
169: BootstrapDialog.show({
170: title: 'Confirmation',
171: message: 'Are you sure you wish to delete this item?',
172: buttons: [
173: {
174: icon: 'glyphicon glyphicon-remove',
175: label: 'Cancel',
176: cssClass: 'btn btn-default btn-xs',
177: action: function(dialogItself){
178: dialogItself.close();
179: }
180: },
181: {
182: icon: 'glyphicon glyphicon-ok',
183: label: 'Okay',
184: cssClass: 'btn btn-default btn-xs',
185: action: function(dialogItself) {
186: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('ActiveRecordOID')) : 'ActiveRecordOID')."\"]').attr('value', '".$this->BO->getOID()."');
187: $('#deleteForm').submit();
188: dialogItself.close();
189: }
190: }
191: ]
192: });
193: }";
194:
195: $button = new Button($js, 'Delete', 'deleteBut');
196: $fields['deleteButton'] = $button->render();
197:
198: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.get_class($this->BO).'&start=0&limit='.$config->get('app.list.page.amount'))."'", 'Back to List', 'cancelBut');
199: $fields['cancelButton'] = $button->render();
200:
201: $tags = array();
202:
203: if (is_object($this->BO->getPropObject('tags'))) {
204: $tags = $this->BO->getPropObject('tags')->getRelatedObjects();
205: }
206:
207: if (count($tags) > 0) {
208: $button = new Button("document.location = '".FrontController::generateSecureURL('act=Alpha\Controller\TagController&ActiveRecordType='.get_class($this->BO).'&ActiveRecordOID='.$this->BO->getOID())."'", 'Edit Tags', 'tagsBut');
209: $fields['tagsButton'] = $button->render();
210: }
211:
212:
213: $fields['formSecurityFields'] = $this->renderSecurityFields();
214:
215:
216: $fields['version_num'] = $this->BO->getVersionNumber();
217:
218:
219: $fields['fileAttachments'] = $this->renderFileUploadSection();
220:
221: if (method_exists($this, 'after_editView_callback')) {
222: $this->after_editView_callback();
223: }
224:
225: return $this->loadTemplate($this->BO, 'edit', $fields);
226: }
227:
228: 229: 230: 231: 232: 233: 234:
235: protected function renderFileUploadSection()
236: {
237: $config = ConfigProvider::getInstance();
238:
239: $html = '<div class="form-group">';
240: $html .= ' <h3>File Attachments:</h3>';
241:
242: if (is_dir($this->BO->getAttachmentsLocation())) {
243: $handle = opendir($this->BO->getAttachmentsLocation());
244:
245: $fileCount = 0;
246:
247: $html .= '<table class="table table-bordered">';
248:
249:
250: while (false !== ($file = readdir($handle))) {
251: if ($file != '.' && $file != '..') {
252: ++$fileCount;
253:
254: $html .= '<tr>';
255:
256: $html .= '<td>'.$file.' <em>('.number_format(filesize($this->BO->getAttachmentsLocation().'/'.$file) / 1024).' KB)</em></td>';
257:
258: $js = "if(window.jQuery) {
259: BootstrapDialog.show({
260: title: 'Confirmation',
261: message: 'Are you sure you wish to delete this item?',
262: buttons: [
263: {
264: icon: 'glyphicon glyphicon-remove',
265: label: 'Cancel',
266: cssClass: 'btn btn-default btn-xs',
267: action: function(dialogItself){
268: dialogItself.close();
269: }
270: },
271: {
272: icon: 'glyphicon glyphicon-ok',
273: label: 'Okay',
274: cssClass: 'btn btn-default btn-xs',
275: action: function(dialogItself) {
276: $('[id=\"".($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('deletefile')) : 'deletefile')."\"]').attr('value', '".$file."');
277: $('[id=\"".stripslashes(get_class($this->BO)).'_'.$this->BO->getID()."\"]').submit();
278: dialogItself.close();
279: }
280: }
281: ]
282: });
283: }";
284: $button = new Button($js, 'Delete', 'delete'.$fileCount.'But');
285: $html .= '<td>'.$button->render().'</td>';
286: $html .= '</tr>';
287: }
288: }
289:
290: $html .= '</table>';
291: } else {
292:
293:
294: $this->BO->createAttachmentsFolder();
295: }
296:
297: $html .= '<span class="btn btn-default btn-file">';
298: $html .= '<input name="userfile" type="file" value="Browse..."/>';
299: $html .= '</span>';
300:
301: $temp = new Button('submit', 'Upload', 'uploadBut');
302: $html .= $temp->render();
303:
304: $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt('deletefile')) : 'deletefile');
305: $html .= '<input type="hidden" name="'.$fieldname.'" id="'.$fieldname.'" value=""/>';
306:
307: $html .= '</div>';
308:
309: return $html;
310: }
311: }