Text

Includes access methods and data layer. Do not, I repeat, do not mess with protected fields, or even try to access the database directly (unless you know what you are doing, but you most probably don't).

version 3.0.0
package contrexx
subpackage core
copyright CONTREXX CMS - COMVATION AG
author Reto Kohli

 Methods

Create a Text object

__construct(string $text, integer $lang_id, string $section, string $key, integer $id) 
access public
author Reto Kohli

Parameters

$text

string

The content

$lang_id

integer

The language ID

$section

string

The section

$key

string

The key

$id

integer

The optional Text ID. Defaults to null

OBSOLETE -- see {@see replace()} Add a new Text object directly to the database table

add(string | string $text, string $key, $lang_id) : integer
Static

Mind that this method uses the MODULE_ID global constant. This is but a handy shortcut for those in the know.

Parameters

$text

stringstring

The text string

$key

string

The key

$lang_id

Returns

integerThe object ID on success, false otherwise

Returns the text

content(string $text) : string

Optionally sets the text. The string value is used as-is, but is ignored if null. Nothing is checked, trimmed nor stripped. Mind your step! Note: This method cannot be called text() for obscure reasons. :)

author Reto Kohli

Parameters

$text

string

The optional text

Returns

stringThe text

Deletes the Text record from the database

delete(boolean $all_languages) : boolean

If the optional $all_languages parameter evaluates to boolean true, all records with the same ID are deleted. Otherwise, only the language of this object is affected.

author Reto Kohli

Parameters

$all_languages

boolean

Delete all languages if true

Returns

booleanTrue on success, false otherwise

Delete a record from the database.

deleteById(integer $id, string $section, string $key, integer $lang_id) : boolean
Static

Deletes the Text record in the selected language, if not empty. If the optional $lang_id parameter is missing or empty, all languages are removed. Note that you SHOULD NOT call this from outside the module classes as all of these SHOULD take care of cleaning up by themselves. Remark: See deleteLanguage() for details on nuking entire sections.

static
global mixed $objDatabase Database object
author Reto Kohli

Parameters

$id

integer

The ID

$section

string

The section

$key

string

The key

$lang_id

integer

The optional language ID

Returns

booleanTrue on success, false otherwise

Deletes the Text records with the given section and key from the database

deleteByKey(string $section, string $key) : boolean
Static

Use with due care! If you entirely omit the key, or set it to null, no change will take place. Explicitly set it to the empty string, zero, or false to have it ignored in the process. In that case, the complete section will be deleted! If you set $section to null, "global" entries are affected, where the section field is indeed NULL.

author Reto Kohli

Parameters

$section

string

The section

$key

string

The key to match

Returns

booleanTrue on success, false otherwise

Delete all Text with the given language ID from the database.

deleteLanguage(integer $lang_id) : boolean
Static

This is dangerous stuff -- mind your step!

static
global mixed $objDatabase Database object
author Reto Kohli

Parameters

$lang_id

integer

The language ID

Returns

booleanTrue on success, false otherwise

Handle any error occurring in this class.

errorHandler() : boolean
Static

Tries to fix known problems with the database table.

global mixed $objDatabase Database object
static
author Reto Kohli

Exceptions

\Update_DatabaseException

Returns

booleanFalse. Always.

OBSOLETE Returns an array of objects selected by language ID, section, and key, plus optional text IDs from the database.

getArrayById(integer $lang_id, string $section, string $key, integer $ids) : array
Static

You may multiply the $lang_id parameter with -1 to get a negative value, in which case this method behaves very much like getById() and returns other languages or a warning if the language with the same positive ID is unavailable. This is intended for backend use only. The array returned looks like this: array( text_id => obj_text, ... more ... )

static
global mixed $objDatabase Database object
author Reto Kohli

Parameters

$lang_id

integer

The language ID

$section

string

The section

$key

string

The key

$ids

integer

The optional comma separated list of Text IDs

Returns

arrayThe array of Text objects on success, null otherwise

Select an object by ID from the database.

getById(integer $id, string $section, string $key, integer $lang_id) : \Text
Static

Note that if the $lang_id parameter is empty, this method picks the first language of the Text that it encounters. This is useful for displaying records in languages which haven't been edited yet. If the Text cannot be found for the language ID given, the first language encountered is returned. If no record is found for the given ID, creates a new object with an empty string content, and returns it.

static
global mixed $objDatabase Database object
author Reto Kohli

Parameters

$id

integer

The ID

$section

string

The section, may be null

$key

string

The key

$lang_id

integer

The optional language ID

Returns

\TextThe Text

OBSOLETE Select an object by its key from the database

getByKey(integer $key, integer $lang_id) : \Text
Static

This method is intended to provide a means to store arbitrary texts in various languages that don't need to be referred to by an ID, but some distinct key. If the key is not unique, however, you will not be able to retrieve any particular of those records, but only the first one that is encountered. Note that if the $lang_id parameter is zero, this method picks the first language of the Text that it encounters. This is useful for displaying records in languages which haven't been edited yet. If the Text cannot be found for the language ID given, the first language encountered is returned. If no record is found for the given key, creates a new object with a warning message and returns it. Note that in the last case, neither the module nor the text ID are set and remain at their default (null) value. You should set them to the desired values before storing the object.

static
global mixed $objDatabase Database object
author Reto Kohli

Parameters

$key

integer

The key, must not be empty

$lang_id

integer

The language ID

Returns

\TextThe object on success, false otherwise

OBSOLETE Returns an array of Text and language IDs of records matching the search pattern and optional section, key, language, and text IDs

getIdArrayBySearch(string $pattern, integer $section, string $key, integer $lang_id, integer $ids) : array
Static

Note that you have to add "%" signs to the pattern if you want the match to be open ended. The array returned looks like this: array( id => array( 0 => Language ID, ... 1 => more language IDs ... ), ... more ids ... )

static
global mixed $objDatabase Database object
author Reto Kohli

Parameters

$pattern

string

The search pattern

$section

integer

The optional section, or false

$key

string

The optional key, or false

$lang_id

integer

The optional language ID, or false

$ids

integer

The optional comma separated list of Text IDs, or false

Returns

arrayThe array of Text and language IDs on success, false otherwise

Returns an array of SQL snippets to include the selected Text records in the query.

getSqlSnippets(string $field_id, integer $lang_id, string $section, mixed $keys) : array
Static

Provide a single value for the $key, or an array. If you use an array, the array keys MUST contain distinct alias names for the respective text keys. The array returned looks as follows: array( 'alias' => The array of Text field aliases: array(key => field name alias, ...) Use the alias to access the text content in the resulting recordset, or if you need to sort the result by that column. 'field' => Field snippet to be included in the SQL SELECT, uses aliased field names for the id ("text_#id") and text ("text#_text") fields. No leading comma is included! 'join' => SQL JOIN snippet, the LEFT JOIN with the core_text table and conditions ) The '#' is replaced by a unique integer number. The '*' may be any descriptive part of the name that disambiguates multiple foreign keys in a single table, like 'name', or 'value'. Note that the $lang_id parameter is mandatory and *MUST NOT* be emtpy. $alias may be null (or omitted), in which case it is ignored, and the default form "text_" is used, where is an integer incremented on each use.

static
author Reto Kohli

Parameters

$field_id

string

The name of the text ID foreign key field. Note that this is not part of the SELECTed fields, but used in the JOIN only.

$lang_id

integer

The language ID

$section

string

The section

$keys

mixed

A single key, or an array thereof

Returns

arrayThe array with SQL code parts

Get the ID

id() : integer
author Reto Kohli

Returns

integerThe Text ID

Insert this object into the database.

insert() : boolean

Fails if either the ID or lang_id is empty.

global mixed $objDatabase Database object
author Reto Kohli

Returns

booleanTrue on success, false otherwise

Returns the key

key() : string
author Reto Kohli

Returns

stringThe key

Returns the language ID

lang_id(integer $lang_id) : integer

Optionally sets the language ID. Returns null on invalid values.

author Reto Kohli

Parameters

$lang_id

integer

The optional language ID

Returns

integerThe language ID, or null

Clone the object

makeClone() 

Note that this does NOT create a copy in any way, but simply clears the Text ID. Upon storing this Text, a new ID is created.

author Reto Kohli

If the language ID given is different from the language of this Text object, the content may be marked here.

markDifferentLanguage() 

Customize as desired.

author Reto Kohli

OBSOLETE Returns the next available ID

nextId() : integer
Static

Called by insert().

global mixed $objDatabase Database object
author Reto Kohli

Returns

integerThe next ID on success, false otherwise

Test whether a record of this is already present in the database.

recordExists() : boolean
global mixed $objDatabase Database object
author Reto Kohli

Returns

booleanTrue if the record exists, false otherwise

Replace or insert the Text record

replace(integer $id, integer $lang_id, integer $section, string $key, string $strText) : integer
Static

If the Text ID is specified, looks for the same record in the given language, or any other language if that is not found. If no record to update is found, a new one is created. The parameters are applied, and the Text is then stored.

author Reto Kohli

Parameters

$id

integer

The Text ID

$lang_id

integer

The language ID

$section

integer

The section

$key

string

The key

$strText

string

The text

Returns

integerThe Text ID on success, null otherwise

Returns the section

section() : string
author Reto Kohli

Returns

stringThe section

Stores the object in the database.

store() : boolean

Either updates or inserts the object, depending on the outcome of the call to recordExists(). Calling recordExists() is necessary, as there may be no record in the current language, although the Text ID is valid.

author Reto Kohli

Returns

booleanTrue on success, false otherwise

Update this object in the database.

update() : boolean
global mixed $objDatabase Database object
author Reto Kohli

Returns

booleanTrue on success, false otherwise

 Properties

 

The object ID

$id : integer
 

The optional key

$key : string
 

The language ID

$lang_id : integer
 

True if a replacement language was used

$replacement : boolean
 

The optional section

$section : string
 

The content

$text : string
© Copyright 2014 by Comvation AG
Generated on 2014-07-11T08:39:24+02:00.