view.html.php
106 lines
| 1 | <?php |
| 2 | /** |
| 3 | * @package VikAppointments |
| 4 | * @subpackage core |
| 5 | * @author E4J s.r.l. |
| 6 | * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved. |
| 7 | * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 | * @link https://vikwp.com |
| 9 | */ |
| 10 | |
| 11 | // No direct access |
| 12 | defined('ABSPATH') or die('No script kiddies please!'); |
| 13 | |
| 14 | /** |
| 15 | * VikAppointments user note management view. |
| 16 | * |
| 17 | * @since 1.7 |
| 18 | */ |
| 19 | class VikAppointmentsViewmanageusernote extends JViewVAP |
| 20 | { |
| 21 | /** |
| 22 | * VikAppointments view display method. |
| 23 | * |
| 24 | * @return void |
| 25 | */ |
| 26 | function display($tpl = null) |
| 27 | { |
| 28 | $dbo = JFactory::getDbo(); |
| 29 | $app = JFactory::getApplication(); |
| 30 | $input = $app->input; |
| 31 | |
| 32 | $ids = $input->getUint('cid', array()); |
| 33 | $type = $ids ? 'edit' : 'new'; |
| 34 | |
| 35 | // set the toolbar |
| 36 | $this->addToolBar($type); |
| 37 | |
| 38 | // get model |
| 39 | $model = JModelVAP::getInstance('usernote'); |
| 40 | |
| 41 | // load user note details |
| 42 | $note = $model->getItem($ids ? $ids[0] : 0, $blank = true); |
| 43 | |
| 44 | // use user note data stored in user state |
| 45 | $this->injectUserStateData($note, 'vap.usernote.data'); |
| 46 | |
| 47 | // replace tag IDs with their names |
| 48 | $note->tags = implode(',', JModelVAP::getInstance('tag')->readTags($note->tags)); |
| 49 | |
| 50 | $this->note = $note; |
| 51 | |
| 52 | // register media model for attachments rendering |
| 53 | $this->mediaModel = JModelVAP::getInstance('media'); |
| 54 | |
| 55 | $this->isTmpl = $input->get('tmpl') === 'component'; |
| 56 | |
| 57 | if ($this->isTmpl && $this->note->id) |
| 58 | { |
| 59 | // add pretty modify date in case of blank template, so that the caller can use it |
| 60 | $this->note->modifiedon_pretty = JHtml::fetch( |
| 61 | 'date', |
| 62 | VAPDateHelper::isNull($this->note->modifiedon) ? $this->note->createdon : $this->note->modifiedon, |
| 63 | JText::translate('DATE_FORMAT_LC2') |
| 64 | ); |
| 65 | } |
| 66 | |
| 67 | // display the template |
| 68 | parent::display($tpl); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Setting the toolbar. |
| 73 | * |
| 74 | * @return void |
| 75 | */ |
| 76 | protected function addToolBar($type) |
| 77 | { |
| 78 | // add menu title and some buttons to the page |
| 79 | if ($type == 'edit') |
| 80 | { |
| 81 | JToolBarHelper::title(JText::translate('VAPMAINTITLEEDITUSERNOTE'), 'vikappointments'); |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | JToolBarHelper::title(JText::translate('VAPMAINTITLENEWUSERNOTE'), 'vikappointments'); |
| 86 | } |
| 87 | |
| 88 | $user = JFactory::getUser(); |
| 89 | |
| 90 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 91 | || $user->authorise('core.create', 'com_vikappointments')) |
| 92 | { |
| 93 | JToolbarHelper::apply('usernote.save', JText::translate('VAPSAVE')); |
| 94 | JToolbarHelper::save('usernote.saveclose', JText::translate('VAPSAVEANDCLOSE')); |
| 95 | } |
| 96 | |
| 97 | if ($user->authorise('core.edit', 'com_vikappointments') |
| 98 | && $user->authorise('core.create', 'com_vikappointments')) |
| 99 | { |
| 100 | JToolbarHelper::save2new('usernote.savenew', JText::translate('VAPSAVEANDNEW')); |
| 101 | } |
| 102 | |
| 103 | JToolBarHelper::cancel('usernote.cancel', $type == 'edit' ? 'JTOOLBAR_CLOSE' : 'JTOOLBAR_CANCEL'); |
| 104 | } |
| 105 | } |
| 106 |