ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilOrgUnitTypeTranslation Class Reference

Class ilOrgUnitTypeTranslation This class represents a translation for a given ilOrgUnit object and language. More...

+ Collaboration diagram for ilOrgUnitTypeTranslation:

Public Member Functions

 __construct ($a_org_type_id=0, $a_lang_code='')
 
 getMember ($a_member)
 Get translated value for a member, returns null if no translation exists. More...
 
 setMember ($a_member, $a_value)
 Set translation value for a member, either update or add value. More...
 
 create ()
 Insert all translated member into database. More...
 
 update ()
 Update translations in database. More...
 
 delete ()
 Delete object. More...
 
 setLang ($lang)
 Getters & Setters. More...
 
 getLang ()
 
 getMembers ()
 
 getOrguTypeId ()
 
 setOrguTypeId ($id)
 

Static Public Member Functions

static getInstance ($a_orgu_type_id, $a_lang_code)
 Public. More...
 

Data Fields

const TABLE_NAME = 'orgu_types_trans'
 

Protected Member Functions

 insertMember ($member, $value)
 Protected. More...
 
 updateMember ($member, $value)
 Update a (member,value) pair in database. More...
 
 trackChange ($a_member, $is_new)
 Track a member that was either updated or added. More...
 
 resetTrackChanges ()
 Reset tracked members. More...
 
 read ()
 Read object data from database. More...
 

Protected Attributes

 $orgu_type_id
 
 $lang = ''
 
 $members = array()
 
 $changes = array()
 
 $members_new = array()
 
 $db
 
 $log
 

Static Protected Attributes

static $instances = array()
 

Detailed Description

Class ilOrgUnitTypeTranslation This class represents a translation for a given ilOrgUnit object and language.

Author
: Stefan Wanzenried sw@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 9 of file class.ilOrgUnitTypeTranslation.php.

Constructor & Destructor Documentation

◆ __construct()

ilOrgUnitTypeTranslation::__construct (   $a_org_type_id = 0,
  $a_lang_code = '' 
)

Definition at line 54 of file class.ilOrgUnitTypeTranslation.php.

References $DIC, $ilDB, $ilLog, and read().

54  {
55  global $DIC;
56  $ilDB = $DIC['ilDB'];
57  $ilLog = $DIC['ilLog'];
58  $this->db = $ilDB;
59  $this->log = $ilLog;
60  if ($a_org_type_id && $a_lang_code) {
61  $this->orgu_type_id = (int) $a_org_type_id;
62  $this->lang = $a_lang_code;
63  $this->read();
64  }
65  }
read()
Read object data from database.
global $ilDB
global $DIC
+ Here is the call graph for this function:

Member Function Documentation

◆ create()

ilOrgUnitTypeTranslation::create ( )

Insert all translated member into database.

Definition at line 170 of file class.ilOrgUnitTypeTranslation.php.

References insertMember(), and resetTrackChanges().

170  {
171  foreach ($this->members as $member => $value) {
172  $this->insertMember($member, $value);
173  }
174  $this->resetTrackChanges();
175  }
resetTrackChanges()
Reset tracked members.
insertMember($member, $value)
Protected.
+ Here is the call graph for this function:

◆ delete()

ilOrgUnitTypeTranslation::delete ( )

Delete object.

Definition at line 195 of file class.ilOrgUnitTypeTranslation.php.

References $DIC, $ilDB, getLang(), and getOrguTypeId().

195  {
196  $sql = 'DELETE FROM ' . self::TABLE_NAME . ' WHERE orgu_type_id = ' . $this->db->quote($this->getOrguTypeId(), 'integer') .
197  ' AND lang = ' . $this->db->quote($this->getLang(), 'text');
198  $this->db->manipulate($sql);
199  }
+ Here is the call graph for this function:

◆ getInstance()

static ilOrgUnitTypeTranslation::getInstance (   $a_orgu_type_id,
  $a_lang_code 
)
static

Public.

Get instance of an ilOrgUnitType object Returns object from cache or from database, returns null if no object was found

Parameters
int$a_orgu_type_idID of an ilOrgUnitType object
string$a_lang_codeLanguage code
Returns
ilOrgUnitTypeTranslation|null

Definition at line 81 of file class.ilOrgUnitTypeTranslation.php.

References $DIC, $ilDB, and array.

Referenced by ilOrgUnitType\loadTranslation().

81  {
82  if (!$a_orgu_type_id || !$a_lang_code) {
83  return null;
84  }
85  $cache_id = $a_orgu_type_id . $a_lang_code;
86  if (isset(self::$instances[$cache_id])) {
87  return self::$instances[$cache_id];
88  } else {
89  try {
90  $trans = new self($a_orgu_type_id, $a_lang_code);
91  self::$instances[$cache_id] = $trans;
92  return $trans;
93  } catch (ilOrgUnitTypeException $e) {
94  return null;
95  }
96  }
97  }
Class ilOrgUnitTypeException.
+ Here is the caller graph for this function:

◆ getLang()

ilOrgUnitTypeTranslation::getLang ( )
Returns
string

Definition at line 309 of file class.ilOrgUnitTypeTranslation.php.

References $lang.

Referenced by delete(), insertMember(), and updateMember().

+ Here is the caller graph for this function:

◆ getMember()

ilOrgUnitTypeTranslation::getMember (   $a_member)

Get translated value for a member, returns null if no translation exists.

Parameters
string$a_memberName of the variable, e.g. title,description
Returns
string|null

Definition at line 151 of file class.ilOrgUnitTypeTranslation.php.

References string.

Referenced by update().

151  {
152  return (isset($this->members[$a_member])) ? (string) $this->members[$a_member] : null;
153  }
Add rich text string
The name of the decorator.
+ Here is the caller graph for this function:

◆ getMembers()

ilOrgUnitTypeTranslation::getMembers ( )
Returns
array

Definition at line 318 of file class.ilOrgUnitTypeTranslation.php.

References $members.

◆ getOrguTypeId()

ilOrgUnitTypeTranslation::getOrguTypeId ( )
Returns
int

Definition at line 327 of file class.ilOrgUnitTypeTranslation.php.

References $orgu_type_id.

Referenced by delete(), insertMember(), and updateMember().

+ Here is the caller graph for this function:

◆ insertMember()

ilOrgUnitTypeTranslation::insertMember (   $member,
  $value 
)
protected

Protected.

Insert a (member,value) pair in database

Parameters
$member
$value

Definition at line 226 of file class.ilOrgUnitTypeTranslation.php.

References array, getLang(), and getOrguTypeId().

Referenced by create(), and update().

226  {
227  $this->db->insert(self::TABLE_NAME, array(
228  'orgu_type_id' => array('integer', $this->getOrguTypeId()),
229  'lang' => array('text', $this->getLang()),
230  'member' => array('text', $member),
231  'value' => array('text', $value),
232  ));
233  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilOrgUnitTypeTranslation::read ( )
protected

Read object data from database.

Exceptions
ilOrgUnitTypeException

Definition at line 280 of file class.ilOrgUnitTypeTranslation.php.

References string.

Referenced by __construct().

280  {
281  $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE orgu_type_id = ' . $this->db->quote($this->orgu_type_id, 'integer') .
282  ' AND lang = ' . $this->db->quote($this->lang, 'text');
283  $set = $this->db->query($sql);
284  if (!$this->db->numRows($set)) {
285  throw new ilOrgUnitTypeException("OrgUnit type translation for OrgUnit type {$this->orgu_type_id} and language {$this->lang} does not exist in database");
286  }
287  while ($rec = $this->db->fetchObject($set)) {
288  $this->members[$rec->member] = (string) $rec->value;
289  }
290  }
Class ilOrgUnitTypeException.
Add rich text string
The name of the decorator.
+ Here is the caller graph for this function:

◆ resetTrackChanges()

ilOrgUnitTypeTranslation::resetTrackChanges ( )
protected

Reset tracked members.

Definition at line 270 of file class.ilOrgUnitTypeTranslation.php.

References array.

Referenced by create(), and update().

270  {
271  $this->changes = array();
272  $this->members_new = array();
273  }
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ setLang()

ilOrgUnitTypeTranslation::setLang (   $lang)

Getters & Setters.

Parameters
string$lang

Definition at line 301 of file class.ilOrgUnitTypeTranslation.php.

References $lang.

302  {
303  $this->lang = $lang;
304  }

◆ setMember()

ilOrgUnitTypeTranslation::setMember (   $a_member,
  $a_value 
)

Set translation value for a member, either update or add value.

Parameters
string$a_memberName of the variable, e.g. title,description
string$a_valueValue of the translation

Definition at line 161 of file class.ilOrgUnitTypeTranslation.php.

References string, and trackChange().

161  {
162  $is_new = !isset($this->members[$a_member]);
163  $this->members[$a_member] = (string) $a_value;
164  $this->trackChange($a_member, $is_new);
165  }
Add rich text string
The name of the decorator.
trackChange($a_member, $is_new)
Track a member that was either updated or added.
+ Here is the call graph for this function:

◆ setOrguTypeId()

ilOrgUnitTypeTranslation::setOrguTypeId (   $id)
Parameters
int$id

Definition at line 335 of file class.ilOrgUnitTypeTranslation.php.

335  {
336  $this->orgu_type_id = (int) $id;
337  }

◆ trackChange()

ilOrgUnitTypeTranslation::trackChange (   $a_member,
  $is_new 
)
protected

Track a member that was either updated or added.

Parameters
string$a_memberName of a variable, e.g. title,description
bool$is_newTrue if the member did not exist before

Definition at line 258 of file class.ilOrgUnitTypeTranslation.php.

Referenced by setMember().

258  {
259  if (!in_array($a_member, $this->changes)) {
260  $this->changes[] = $a_member;
261  }
262  if ($is_new && !in_array($a_member, $this->members_new)) {
263  $this->members_new[] = $a_member;
264  }
265  }
+ Here is the caller graph for this function:

◆ update()

ilOrgUnitTypeTranslation::update ( )

Update translations in database.

Newly added members are inserted.

Definition at line 180 of file class.ilOrgUnitTypeTranslation.php.

References getMember(), insertMember(), resetTrackChanges(), and updateMember().

180  {
181  foreach ($this->changes as $changed_member) {
182  // Check if the member needs to be updated or inserted into database
183  if (in_array($changed_member, $this->members_new)) {
184  $this->insertMember($changed_member, $this->getMember($changed_member));
185  } else {
186  $this->updateMember($changed_member, $this->getMember($changed_member));
187  }
188  }
189  $this->resetTrackChanges();
190  }
resetTrackChanges()
Reset tracked members.
updateMember($member, $value)
Update a (member,value) pair in database.
getMember($a_member)
Get translated value for a member, returns null if no translation exists.
insertMember($member, $value)
Protected.
+ Here is the call graph for this function:

◆ updateMember()

ilOrgUnitTypeTranslation::updateMember (   $member,
  $value 
)
protected

Update a (member,value) pair in database.

Parameters
$member
$value

Definition at line 242 of file class.ilOrgUnitTypeTranslation.php.

References array, getLang(), and getOrguTypeId().

Referenced by update().

242  {
243  $this->db->update(self::TABLE_NAME, array(
244  'value' => array('text', $value),
245  ), array(
246  'orgu_type_id' => array('integer', $this->getOrguTypeId()),
247  'lang' => array('text', $this->getLang()),
248  'member' => array('text', $member),
249  ));
250  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $changes

ilOrgUnitTypeTranslation::$changes = array()
protected

Definition at line 31 of file class.ilOrgUnitTypeTranslation.php.

◆ $db

ilOrgUnitTypeTranslation::$db
protected

Definition at line 41 of file class.ilOrgUnitTypeTranslation.php.

◆ $instances

ilOrgUnitTypeTranslation::$instances = array()
staticprotected

Definition at line 51 of file class.ilOrgUnitTypeTranslation.php.

◆ $lang

ilOrgUnitTypeTranslation::$lang = ''
protected

Definition at line 21 of file class.ilOrgUnitTypeTranslation.php.

Referenced by getLang(), and setLang().

◆ $log

ilOrgUnitTypeTranslation::$log
protected

Definition at line 46 of file class.ilOrgUnitTypeTranslation.php.

◆ $members

ilOrgUnitTypeTranslation::$members = array()
protected

Definition at line 26 of file class.ilOrgUnitTypeTranslation.php.

Referenced by getMembers().

◆ $members_new

ilOrgUnitTypeTranslation::$members_new = array()
protected

Definition at line 36 of file class.ilOrgUnitTypeTranslation.php.

◆ $orgu_type_id

ilOrgUnitTypeTranslation::$orgu_type_id
protected

Definition at line 16 of file class.ilOrgUnitTypeTranslation.php.

Referenced by getOrguTypeId().

◆ TABLE_NAME

const ilOrgUnitTypeTranslation::TABLE_NAME = 'orgu_types_trans'

Definition at line 11 of file class.ilOrgUnitTypeTranslation.php.


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