Content
extends Entity
in package
Content class
This class maps the content view.
This view shows the content_files and content_locations tables.
This class also provides helper methods, to handle files, generate thumbnails or get local content from a specific location.
[DESIGN BY CONTRACT] This class works only with the following assertions: i. Each content have EXACTLY ONE location ii. Location fields will not be modified
If a content have more than one location, only the first occurrence in content_locations table will be considered.
If a content have no location, it will be ignored.
If you edit content location, then call saveToDatabase, you will create a new location but future instances will contain first not deleted location.
Tags
Table of Contents
Properties
- $id : mixed
- $lastError : string
- $location_global : mixed
- $location_k : mixed
- $location_local : mixed
- $path : mixed
- $perso_id : mixed
- $perso_name : mixed
- $perso_nickname : mixed
- $title : mixed
- $user_id : mixed
- $db : DatabaseEngine
Methods
- __construct() : mixed
- Initializes a new Content instance
- __toString() : string
- Returns a string representation of current Content instance
- create_directory() : mixed
- Creates a directory
- generate_thumbnail() : bool
- Generates a thumbnail using ImageMagick binary
- get_local_content() : array<string|int, Content>
- Gets all content at specified location
- getDatabase() : DatabaseEngine
- getLogicalPath() : string
- getStoragePath() : string
- handle_uploaded_file() : bool
- Handles uploaded file
- is_valid_extension() : bool
- Determines if the extension is valid
- load_from_database() : bool
- Loads the object Content (ie fill the properties) from the database
- load_from_form() : mixed
- Loads the object Content (ie fill the properties) from the $_POST array
- load_from_row() : mixed
- Loads the object from row
- save_to_database() : void
- Saves to database
- setDatabase() : void
Properties
$id
public
mixed
$id
$lastError
public
string
$lastError
= ""
$location_global
public
mixed
$location_global
= null
$location_k
public
mixed
$location_k
= null
$location_local
public
mixed
$location_local
= null
$path
public
mixed
$path
$perso_id
public
mixed
$perso_id
$perso_name
public
mixed
$perso_name
$perso_nickname
public
mixed
$perso_nickname
$title
public
mixed
$title
$user_id
public
mixed
$user_id
$db
private
DatabaseEngine
$db
Methods
__construct()
Initializes a new Content instance
public
__construct(DatabaseEngine $db[, int $id = null ]) : mixed
Parameters
- $db : DatabaseEngine
- $id : int = null
-
the primary key
__toString()
Returns a string representation of current Content instance
public
__toString() : string
Return values
string —the content title or path if title is blank.
create_directory()
Creates a directory
public
create_directory(mixed $directory) : mixed
Parameters
- $directory : mixed
generate_thumbnail()
Generates a thumbnail using ImageMagick binary
public
generate_thumbnail() : bool
Return values
bool —true if the thumbnail command returns 0 as program exit code ; otherwise, false
get_local_content()
Gets all content at specified location
public
static get_local_content(DatabaseEngine $db, string $location_global, string $location_local) : array<string|int, Content>
Parameters
- $db : DatabaseEngine
- $location_global : string
- $location_local : string
Return values
array<string|int, Content> —array of Content instances
getDatabase()
public
getDatabase() : DatabaseEngine
Return values
DatabaseEnginegetLogicalPath()
public
getLogicalPath(string $name) : string
Parameters
- $name : string
-
The final destination filename
Return values
string —The URL to use to serve the file.
getStoragePath()
public
getStoragePath() : string
Return values
string —The storage path for this file on disk
handle_uploaded_file()
Handles uploaded file
public
handle_uploaded_file(mixed $fileArray) : bool
Parameters
- $fileArray : mixed
Return values
bool —true if the file have been handled
is_valid_extension()
Determines if the extension is valid
public
static is_valid_extension(string $ext) : bool
Parameters
- $ext : string
-
The extension (without dot)
Return values
bool —true if this extension is valid ; otherwise, false.
load_from_database()
Loads the object Content (ie fill the properties) from the database
public
load_from_database() : bool
Return values
boolload_from_form()
Loads the object Content (ie fill the properties) from the $_POST array
public
load_from_form([bool $allowSensibleFields = false ]) : mixed
Parameters
- $allowSensibleFields : bool = false
-
if false, allow only location_local, location_k and title to be defined ; otherwise, allow all fields.
load_from_row()
Loads the object from row
public
load_from_row(mixed $row) : mixed
Parameters
- $row : mixed
save_to_database()
Saves to database
public
save_to_database() : void
setDatabase()
public
setDatabase(DatabaseEngine $db) : void
Parameters
- $db : DatabaseEngine