Files
FHC-Core/application/core/FS_Model.php
T
bison-paolo 8e0ca12deb - All permission functionalities now are in the library PermissionLib
- All return messages functions are in the message helper and it is loaded by the core classes
- Added the missing constant FHC_NOPK
- Updated all the interested classes with the new permission method
- Updated all the interested classes with the new return message functions
2016-10-13 17:53:12 +02:00

175 lines
4.4 KiB
PHP

<?php
class FS_Model extends FHC_Model
{
protected $filepath; // Path of the file
protected $acl; // Name of the permissions array index for FS writing, reading...
function __construct($filepath = null)
{
parent::__construct();
// Load the filesystem library
$this->load->library('FilesystemLib');
// Load return message helper
$this->load->helper('message');
$this->filepath = $filepath;
}
/** ---------------------------------------------------------------
* Read data from file system
*
* @return array
*/
public function read($filename)
{
// Check Class-Attributes
if (is_null($this->filepath))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check method parameters
if (is_null($filename))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check rights
if (($chkRights = $this->isEntitled($this->filepath, PermissionLib::SELECT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
if (!is_null($data = $this->filesystemlib->read($this->filepath, $filename)))
{
return success(base64_encode($data));
}
else
{
return error(FHC_MODEL_ERROR, FHC_ERROR);
}
}
/** ---------------------------------------------------------------
* Writing data to file system
*
* @param string $fileContent File content
* @return object
*/
public function write($filename, $content)
{
// Check Class-Attributes
if (is_null($this->filepath))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check method parameters
if (is_null($filename))
return error(FHC_MODEL_ERROR, FHC_ERROR);
if (is_null($content))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check rights
if (($chkRights = $this->isEntitled($this->filepath, PermissionLib::INSERT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
if ($this->filesystemlib->write($this->filepath, $filename, base64_decode($content)) === true)
{
return success(FHC_SUCCESS);
}
else
{
return error(FHC_MODEL_ERROR, FHC_ERROR);
}
}
/** ---------------------------------------------------------------
* Append data to a file
*
* @param array $data File content
* @return array
*/
public function append($filename, $content)
{
// Check Class-Attributes
if (is_null($this->filepath))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check method parameters
if (is_null($filename))
return error(FHC_MODEL_ERROR, FHC_ERROR);
if (is_null($content))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check rights
if (($chkRights = $this->isEntitled($this->filepath, PermissionLib::INSERT_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
if ($this->filesystemlib->append($this->filepath, $filename, base64_decode($content)) === true)
{
return success(FHC_SUCCESS);
}
else
{
return error(FHC_MODEL_ERROR, FHC_ERROR);
}
}
/** ---------------------------------------------------------------
* Delete data from file system
*
* @param string $id Primary Key for DELETE
* @return array
*/
public function remove($filename)
{
// Check Class-Attributes
if (is_null($this->filepath))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check method parameters
if (is_null($filename))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check rights
if (($chkRights = $this->isEntitled($this->filepath, PermissionLib::DELETE_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
if ($this->filesystemlib->remove($this->filepath, $filename) === true)
{
return success(FHC_SUCCESS);
}
else
{
return error(FHC_MODEL_ERROR, FHC_ERROR);
}
}
/** ---------------------------------------------------------------
* Rename a file
*
* @param string $id Primary Key for DELETE
* @return array
*/
public function rename($filename, $newFilename)
{
// Check Class-Attributes
if (is_null($this->filepath))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check method parameters
if (is_null($filename))
return error(FHC_MODEL_ERROR, FHC_ERROR);
if (is_null($newFilename))
return error(FHC_MODEL_ERROR, FHC_ERROR);
// Check rights
if (($chkRights = $this->isEntitled($this->filepath, PermissionLib::UPDATE_RIGHT, FHC_NORIGHT, FHC_MODEL_ERROR)) !== true)
return $chkRights;
if ($this->filesystemlib->rename($this->filepath, $filename, $this->filepath, $newFilename) === true)
{
return success(FHC_SUCCESS);
}
else
{
return error(FHC_MODEL_ERROR, FHC_ERROR);
}
}
}