1<?php 2 3/** 4 * Kolab storage cache class for file objects 5 * 6 * @author Thomas Bruederli <bruederli@kolabsys.com> 7 * 8 * Copyright (C) 2013, Kolab Systems AG <contact@kolabsys.com> 9 * 10 * This program is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Affero General Public License as 12 * published by the Free Software Foundation, either version 3 of the 13 * License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Affero General Public License for more details. 19 * 20 * You should have received a copy of the GNU Affero General Public License 21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 22 */ 23 24class kolab_storage_cache_file extends kolab_storage_cache 25{ 26 protected $extra_cols = array('filename'); 27 protected $data_props = array('type', 'size', 'filename', 'fileid'); 28 29 /** 30 * Helper method to convert the given Kolab object into a dataset to be written to cache 31 * 32 * @override 33 */ 34 protected function _serialize($object) 35 { 36 if (!empty($object['_attachments'])) { 37 reset($object['_attachments']); 38 39 $file = $object['_attachments'][key($object['_attachments'])]; 40 41 $object['type'] = $file['mimetype']; 42 $object['size'] = $file['size']; 43 $object['fileid'] = $file['id']; 44 } 45 46 $sql_data = parent::_serialize($object); 47 48 if (!empty($file)) { 49 $sql_data['filename'] = $file['name']; 50 } 51 52 return $sql_data; 53 } 54 55 /** 56 * Helper method to turn stored cache data into a valid storage object 57 * 58 * @override 59 */ 60 protected function _unserialize($sql_arr) 61 { 62 $object = parent::_unserialize($sql_arr); 63 64 if ($object && !empty($object['_attachments'])) { 65 $file = $object['_attachments'][key($object['_attachments'])]; 66 67 $object['type'] = $file['mimetype']; 68 $object['size'] = $file['size']; 69 $object['fileid'] = $file['id']; 70 } 71 72 return $object; 73 } 74} 75