server/lib/private/Search/Result/File.php

117 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
2016-07-21 15:07:57 +00:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
2015-03-26 10:44:34 +00:00
* @author Andrew Brown <andrew@casabrown.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
2016-05-26 17:56:05 +00:00
* @author Lukas Reschke <lukas@statuscode.ch>
2015-03-26 10:44:34 +00:00
* @author Morris Jobke <hey@morrisjobke.de>
*
2015-03-26 10:44:34 +00:00
* @license AGPL-3.0
*
2015-03-26 10:44:34 +00:00
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
2015-03-26 10:44:34 +00:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
2015-03-26 10:44:34 +00:00
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Search\Result;
2014-07-09 12:47:43 +00:00
use OCP\Files\FileInfo;
use OCP\Files\Folder;
2014-07-09 12:47:43 +00:00
/**
* A found file
*/
class File extends \OCP\Search\Result {
2013-08-26 12:12:06 +00:00
/**
* Type name; translated in templates
* @var string
*/
public $type = 'file';
2013-08-26 12:12:06 +00:00
/**
* Path to file
* @var string
*/
public $path;
2013-08-26 12:12:06 +00:00
/**
* Size, in bytes
* @var int
*/
public $size;
2013-08-26 12:12:06 +00:00
/**
* Date modified, in human readable form
* @var string
*/
public $modified;
2013-08-26 12:12:06 +00:00
/**
* File mime type
* @var string
*/
public $mime_type;
2013-08-26 12:12:06 +00:00
/**
* File permissions:
*
* @var string
*/
public $permissions;
2013-08-26 12:12:06 +00:00
/**
* Create a new file search result
2014-07-14 15:10:52 +00:00
* @param FileInfo $data file data given by provider
2013-08-26 12:12:06 +00:00
*/
2014-07-09 12:47:43 +00:00
public function __construct(FileInfo $data) {
2014-07-14 15:10:52 +00:00
$path = $this->getRelativePath($data->getPath());
$info = pathinfo($path);
2014-07-09 12:47:43 +00:00
$this->id = $data->getId();
2013-08-26 12:12:06 +00:00
$this->name = $info['basename'];
$this->link = \OC::$server->getURLGenerator()->linkToRoute(
'files.view.index',
[
'dir' => $info['dirname'],
'scrollto' => $info['basename'],
]
2013-08-26 12:12:06 +00:00
);
2014-07-14 15:10:52 +00:00
$this->permissions = $data->getPermissions();
$this->path = $path;
2014-07-09 12:47:43 +00:00
$this->size = $data->getSize();
$this->modified = $data->getMtime();
$this->mime = $data->getMimetype();
2013-08-26 12:12:06 +00:00
}
/**
* @var Folder $userFolderCache
*/
static protected $userFolderCache = null;
2013-08-26 12:12:06 +00:00
/**
2014-07-14 15:10:52 +00:00
* converts a path relative to the users files folder
* eg /user/files/foo.txt -> /foo.txt
2013-08-26 12:12:06 +00:00
* @param string $path
2014-07-14 15:10:52 +00:00
* @return string relative path
2013-08-26 12:12:06 +00:00
*/
protected function getRelativePath ($path) {
if (!isset(self::$userFolderCache)) {
$user = \OC::$server->getUserSession()->getUser()->getUID();
self::$userFolderCache = \OC::$server->getUserFolder($user);
}
return self::$userFolderCache->getRelativePath($path);
2013-08-26 12:12:06 +00:00
}
2014-07-14 15:10:52 +00:00
2013-08-26 12:12:06 +00:00
}