0013080: Extend document preview
[tine20] / tine20 / Filemanager / Preference.php
1 <?php
2 /**
3  * Tine 2.0
4  *
5  * @package     Filemanager
6  * @subpackage  Preference
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
8  * @author      Michael Spahn <m.spahn@metaways.de>
9  * @copyright   Copyright (c) 2017 Metaways Infosystems GmbH (http://www.metaways.de)
10  */
11
12 /**
13  * backend for Filemanager preferences
14  *
15  * @package     Filemanager
16  * @subpackage  Preference
17  */
18 class Filemanager_Preference extends Tinebase_Preference_Abstract
19 {
20     /**
21      * Preference for row double click default action
22      */
23     const DB_CLICK_ACTION = 'dbClickAction';
24
25     /**
26      * Filemanager_Preference constructor.
27      * @param null $_dbAdapter
28      * @param array $_options
29      * @throws \Tinebase_Exception_Backend_Database
30      */
31     public function __construct($_dbAdapter = null, array $_options = array())
32     {
33         $this->_application = 'Filemanager';
34         parent::__construct($_dbAdapter, $_options);
35     }
36
37     /**
38      * get all possible application prefs
39      *
40      * @return  array   all application prefs
41      */
42     public function getAllApplicationPreferences()
43     {
44         $preferences = [];
45         $preferences[] = self::DB_CLICK_ACTION;
46
47         return $preferences;
48     }
49
50     /**
51      * get translated right descriptions
52      *
53      * @return  array with translated descriptions for this applications preferences
54      */
55     public function getTranslatedPreferences()
56     {
57         $translate = Tinebase_Translation::getTranslation($this->_application);
58
59         $prefDescriptions = array(
60             self::DB_CLICK_ACTION => array(
61                 'label' => $translate->_('Row double click default'),
62                 'description' => $translate->_('Defines which action should be executed on double click by default?'),
63             )
64         );
65
66         return $prefDescriptions;
67     }
68
69     /**
70      * @param string $_preferenceName
71      * @param null $_accountId
72      * @param string $_accountType
73      * @return Tinebase_Model_Preference
74      * @throws Tinebase_Exception_NotFound
75      */
76     public function getApplicationPreferenceDefaults(
77         $_preferenceName,
78         $_accountId = null,
79         $_accountType = Tinebase_Acl_Rights::ACCOUNT_TYPE_USER
80     ) {
81         $preference = $this->_getDefaultBasePreference($_preferenceName);
82         $translate = Tinebase_Translation::getTranslation($this->_application);
83
84         switch ($_preferenceName) {
85             case self::DB_CLICK_ACTION:
86                 $preference->value = 'download';
87
88                 $downloadOption = '<option>
89                             <value>download</value>
90                             <label>' . $translate->_('Download') . '</label>
91                         </option>';
92
93                 if (Tinebase_Config::getInstance()->{Tinebase_Config::FILESYSTEM}->{Tinebase_Config::FILESYSTEM_CREATE_PREVIEWS}) {
94                     $previewOption = '<option>
95                             <value>preview</value>
96                             <label>' . $translate->_('Preview') . '</label>
97                         </option>';
98                 } else {
99                     $previewOption = '';
100                 }
101
102                 $preference->options = \sprintf('<?xml version="1.0" encoding="UTF-8"?>
103                     <options>
104                     %s
105                     %s
106                     </options>', $downloadOption,  $previewOption);
107                 break;
108
109             default:
110                 throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.');
111         }
112
113         return $preference;
114     }
115 }