nextcloud/lib/private/search/result/file.php

114 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
2015-03-26 13:44:34 +03:00
* @author Andrew Brown <andrew@casabrown.com>
* @author Joas Schilling <nickvergessen@owncloud.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Morris Jobke <hey@morrisjobke.de>
*
2016-01-12 17:02:16 +03:00
* @copyright Copyright (c) 2016, ownCloud, Inc.
2015-03-26 13:44:34 +03:00
* @license AGPL-3.0
*
2015-03-26 13:44:34 +03: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 13:44:34 +03:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
2015-03-26 13:44:34 +03: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 16:47:43 +04:00
use OCP\Files\FileInfo;
use OCP\Files\Folder;
2014-07-09 16:47:43 +04:00
/**
* A found file
*/
class File extends \OCP\Search\Result {
2013-08-26 16:12:06 +04:00
/**
* Type name; translated in templates
* @var string
*/
public $type = 'file';
2013-08-26 16:12:06 +04:00
/**
* Path to file
* @var string
*/
public $path;
2013-08-26 16:12:06 +04:00
/**
* Size, in bytes
* @var int
*/
public $size;
2013-08-26 16:12:06 +04:00
/**
* Date modified, in human readable form
* @var string
*/
public $modified;
2013-08-26 16:12:06 +04:00
/**
* File mime type
* @var string
*/
public $mime_type;
2013-08-26 16:12:06 +04:00
/**
* File permissions:
*
* @var string
*/
public $permissions;
2013-08-26 16:12:06 +04:00
/**
* Create a new file search result
2014-07-14 19:10:52 +04:00
* @param FileInfo $data file data given by provider
2013-08-26 16:12:06 +04:00
*/
2014-07-09 16:47:43 +04:00
public function __construct(FileInfo $data) {
2014-07-14 19:10:52 +04:00
$path = $this->getRelativePath($data->getPath());
$info = pathinfo($path);
2014-07-09 16:47:43 +04:00
$this->id = $data->getId();
2013-08-26 16:12:06 +04:00
$this->name = $info['basename'];
$this->link = \OCP\Util::linkTo(
'files',
'index.php',
array('dir' => $info['dirname'], 'scrollto' => $info['basename'])
2013-08-26 16:12:06 +04:00
);
2014-07-14 19:10:52 +04:00
$this->permissions = $data->getPermissions();
$this->path = $path;
2014-07-09 16:47:43 +04:00
$this->size = $data->getSize();
$this->modified = $data->getMtime();
$this->mime = $data->getMimetype();
2013-08-26 16:12:06 +04:00
}
/**
* @var Folder $userFolderCache
*/
static protected $userFolderCache = null;
2013-08-26 16:12:06 +04:00
/**
2014-07-14 19:10:52 +04:00
* converts a path relative to the users files folder
* eg /user/files/foo.txt -> /foo.txt
2013-08-26 16:12:06 +04:00
* @param string $path
2014-07-14 19:10:52 +04:00
* @return string relative path
2013-08-26 16:12:06 +04: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 16:12:06 +04:00
}
2014-07-14 19:10:52 +04:00
2013-08-26 16:12:06 +04:00
}