CMS  Version 3.9
TextLookup Class Reference

Inherits DataItem.

Public Member Functions

 Translations ($constraint="")
 
 getTranslationOptions ()
 Given a text record, find the remaining languages for which this text has NOT yet been translated. More...
 

Static Public Member Functions

static getText ($code, $obj=null, $blank=false)
 Retrieves text for display on a page, given the code. More...
 
static getValue ($code, $obj=null, $blank=false)
 
static getPlainText ($code, $obj=null, $blank=false)
 Retrieve the plain text value of the text field, with any HTML and leading or trailing whitespace removed. More...
 
static setDefaultValue ($code, $value, $class_name="")
 Called from a component manager fired event setDefaults to set the default value for a text lookup code. More...
 
static setValue ($code, $value, $class_name="")
 Set the string (or html) value of a lookup text code. More...
 

Public Attributes

 $primary_key = "text_id"
 
 $table = "text_lookup"
 
 $fields
 
 $versioned_fields = array("code", "text", "editable", "enabled")
 
 $relations
 

Detailed Description

Definition at line 41 of file text_lookup.inc.

Member Function Documentation

◆ getPlainText()

static TextLookup::getPlainText (   $code,
  $obj = null,
  $blank = false 
)
static

Retrieve the plain text value of the text field, with any HTML and leading or trailing whitespace removed.

Parameters
string$codethe lookup code for the text item
DataItem$objoptional DataItem object to use as a merge code value source
boolean$blanktrue to return an empty string when blank, false to return the item's code

Definition at line 146 of file text_lookup.inc.

147  {
148  return trim(stripHTML(TextLookup::getText($code, $obj, $blank)));
149  }
static getText($code, $obj=null, $blank=false)
Retrieves text for display on a page, given the code.
Definition: text_lookup.inc:85
$code
Definition: hide_hint.inc:36

◆ getText()

static TextLookup::getText (   $code,
  $obj = null,
  $blank = false 
)
static

Retrieves text for display on a page, given the code.

If an object is passed, then attempt to retrieve any merge codes values for codes used in the text that have been saved to merge_code table under the same class name as the $obj.

Parameters
string$codethe value of the code field of the text object
DataItem$obja data item instance that can retrieve values for merge codes used in the block of text (the text field value of table text_lookup.
$blankwhether blank is ok; if ok, then return blank when no match found; if not, return the text string to signal to the developer the value is missing from the db.

Definition at line 85 of file text_lookup.inc.

86  {
87  $texts = Query::create(TextLookup, "WHERE code=:c AND enabled=1")
88  ->bind(":c", $code)
89  ->execute();
90 
91  if(count($texts) > 0)
92  {
93  $text = $texts[0];
94 
96 
98  if(isset($obj))
99  {
100  $text = $obj->format($text->text);
102  $out = $mgr->searchAndReplace($text);
103 
104  }
105  else
106  {
107  $out = $text->text;
108  }
109 
110  if ($text->editable && Settings::getValue("settings", "enable_inline_editing") && Settings::checkPermission("settings", "editor_roles"))
111  {
112  $versioningControls = ComponentManager::fireEvent("RenderVersioningControls", $text);
113  //$versioningEnabled = Settings::getValue("settings", "enable_content_versioning") ? "1" : "0";
114 
115  $out .= $text->format("<p id='inline_editing_{code}' class='inline_editor_toolbar'>".
116  "<a href='#' class='edit' onclick='TextLookupManager.editText({text_id}); return false;'>Edit</a>".
117  "{$versioningControls}</p>");
118  //AJG - must wrap text output if inline editing is enabled
119  $out = "<div>{$out}</div>";
120  }
121 
122  return $out;
123  }
124  else if($blank = false) // return the code to signal that no value was found.
125  {
126  return $code;
127  }
128  else
129  {
130  return "";
131  }
132  }
$out
Definition: page.inc:66
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static checkPermission($component, $name, $account=null)
Check whether a user has a specific permission.
Definition: settings.inc:241
static getTranslation($text)
static selectDisplayVersion($target, $param="version")

◆ getTranslationOptions()

TextLookup::getTranslationOptions ( )

Given a text record, find the remaining languages for which this text has NOT yet been translated.

Definition at line 155 of file text_lookup.inc.

156  {
157  $translations = $this->Translations();
158  if(count($translations) > 0)
159  $indexed = regroupList($translations, "language");
160  else
161  $index = array();
162 
163  $options = array();
164  foreach(TextTranslation::$languageOptions as $language)
165  {
166  if($language != "English" && !array_key_exists($language, $indexed))
167  $options[$language] = $language;
168  }
169 
170  return $options;
171  }
Translations($constraint="")
Definition: text_lookup.inc:63
static $languageOptions

◆ getValue()

static TextLookup::getValue (   $code,
  $obj = null,
  $blank = false 
)
static

Definition at line 134 of file text_lookup.inc.

135  {
136  return TextLookup::getText($code, $obj, $blank);
137  }

◆ setDefaultValue()

static TextLookup::setDefaultValue (   $code,
  $value,
  $class_name = "" 
)
static

Called from a component manager fired event setDefaults to set the default value for a text lookup code.

If the value has already been set, then return.

Parameters
string$code
string$value
string$class_name

Definition at line 182 of file text_lookup.inc.

183  {
184  $texts = Query::create(TextLookup, "WHERE code=:c")
185  ->bind(":c", $code)
186  ->execute();
187 
188  if(count($texts)) return;
189 
191  }
static setValue($code, $value, $class_name="")
Set the string (or html) value of a lookup text code.

◆ setValue()

static TextLookup::setValue (   $code,
  $value,
  $class_name = "" 
)
static

Set the string (or html) value of a lookup text code.

Parameters
string$code
string$value
string$class_name

Definition at line 200 of file text_lookup.inc.

201  {
202  $text = new TextLookup();
203  $text->code = $code;
204  $text->text = $value;
205  $text->class_name = $class_name;
206  $text->save();
207  }

◆ Translations()

TextLookup::Translations (   $constraint = "")

Definition at line 63 of file text_lookup.inc.

64  {
65  return $this->getRelatedList(TextTranslation, "", $constraint);
66  }
$constraint

Member Data Documentation

◆ $fields

TextLookup::$fields
Initial value:
= array(
"text_id" => Number,
"code" => String,
"text" => HTML,
"editable" => Boolean,
"category" => String,
"class_name" => String,
"enabled" => Boolean
)

Definition at line 46 of file text_lookup.inc.

◆ $primary_key

TextLookup::$primary_key = "text_id"

Definition at line 43 of file text_lookup.inc.

◆ $relations

TextLookup::$relations
Initial value:
= array(
"Translations" => TextTranslation
)

Definition at line 58 of file text_lookup.inc.

◆ $table

TextLookup::$table = "text_lookup"

Definition at line 44 of file text_lookup.inc.

◆ $versioned_fields

TextLookup::$versioned_fields = array("code", "text", "editable", "enabled")

Definition at line 56 of file text_lookup.inc.


The documentation for this class was generated from the following file: