ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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().

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

Member Function Documentation

◆ create()

ilOrgUnitTypeTranslation::create ( )

Insert all translated member into database.

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

References insertMember(), and resetTrackChanges().

177  {
178  foreach ($this->members as $member => $value) {
179  $this->insertMember($member, $value);
180  }
181  $this->resetTrackChanges();
182  }
resetTrackChanges()
Reset tracked members.
insertMember($member, $value)
Protected.
+ Here is the call graph for this function:

◆ delete()

ilOrgUnitTypeTranslation::delete ( )

Delete object.

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

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

204  {
205  $sql = 'DELETE FROM ' . self::TABLE_NAME . ' WHERE orgu_type_id = ' . $this->db->quote($this->getOrguTypeId(), 'integer') .
206  ' AND lang = ' . $this->db->quote($this->getLang(), 'text');
207  $this->db->manipulate($sql);
208  }
+ 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 82 of file class.ilOrgUnitTypeTranslation.php.

References $DIC, $ilDB, and array.

Referenced by ilOrgUnitType\loadTranslation().

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

◆ getLang()

ilOrgUnitTypeTranslation::getLang ( )
Returns
string

Definition at line 324 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 155 of file class.ilOrgUnitTypeTranslation.php.

References string.

Referenced by update().

156  {
157  return (isset($this->members[$a_member])) ? (string) $this->members[$a_member] : null;
158  }
Add rich text string
+ Here is the caller graph for this function:

◆ getMembers()

ilOrgUnitTypeTranslation::getMembers ( )
Returns
array

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

References $members.

◆ getOrguTypeId()

ilOrgUnitTypeTranslation::getOrguTypeId ( )
Returns
int

Definition at line 342 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 236 of file class.ilOrgUnitTypeTranslation.php.

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

Referenced by create(), and update().

237  {
238  $this->db->insert(self::TABLE_NAME, array(
239  'orgu_type_id' => array('integer', $this->getOrguTypeId()),
240  'lang' => array('text', $this->getLang()),
241  'member' => array('text', $member),
242  'value' => array('text', $value),
243  ));
244  }
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 294 of file class.ilOrgUnitTypeTranslation.php.

References string.

Referenced by __construct().

295  {
296  $sql = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE orgu_type_id = ' . $this->db->quote($this->orgu_type_id, 'integer') .
297  ' AND lang = ' . $this->db->quote($this->lang, 'text');
298  $set = $this->db->query($sql);
299  if (!$this->db->numRows($set)) {
300  throw new ilOrgUnitTypeException("OrgUnit type translation for OrgUnit type {$this->orgu_type_id} and language {$this->lang} does not exist in database");
301  }
302  while ($rec = $this->db->fetchObject($set)) {
303  $this->members[$rec->member] = (string) $rec->value;
304  }
305  }
Add rich text string
Class ilOrgUnitTypeException.
+ Here is the caller graph for this function:

◆ resetTrackChanges()

ilOrgUnitTypeTranslation::resetTrackChanges ( )
protected

Reset tracked members.

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

References array.

Referenced by create(), and update().

284  {
285  $this->changes = array();
286  $this->members_new = array();
287  }
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 316 of file class.ilOrgUnitTypeTranslation.php.

References $lang.

317  {
318  $this->lang = $lang;
319  }

◆ 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 166 of file class.ilOrgUnitTypeTranslation.php.

References string, and trackChange().

167  {
168  $is_new = !isset($this->members[$a_member]);
169  $this->members[$a_member] = (string) $a_value;
170  $this->trackChange($a_member, $is_new);
171  }
Add rich text string
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 350 of file class.ilOrgUnitTypeTranslation.php.

References $id.

351  {
352  $this->orgu_type_id = (int) $id;
353  }
if(!array_key_exists('StateId', $_REQUEST)) $id

◆ 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 270 of file class.ilOrgUnitTypeTranslation.php.

Referenced by setMember().

271  {
272  if (!in_array($a_member, $this->changes)) {
273  $this->changes[] = $a_member;
274  }
275  if ($is_new && !in_array($a_member, $this->members_new)) {
276  $this->members_new[] = $a_member;
277  }
278  }
+ Here is the caller graph for this function:

◆ update()

ilOrgUnitTypeTranslation::update ( )

Update translations in database.

Newly added members are inserted.

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

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

188  {
189  foreach ($this->changes as $changed_member) {
190  // Check if the member needs to be updated or inserted into database
191  if (in_array($changed_member, $this->members_new)) {
192  $this->insertMember($changed_member, $this->getMember($changed_member));
193  } else {
194  $this->updateMember($changed_member, $this->getMember($changed_member));
195  }
196  }
197  $this->resetTrackChanges();
198  }
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 253 of file class.ilOrgUnitTypeTranslation.php.

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

Referenced by update().

254  {
255  $this->db->update(self::TABLE_NAME, array(
256  'value' => array('text', $value),
257  ), array(
258  'orgu_type_id' => array('integer', $this->getOrguTypeId()),
259  'lang' => array('text', $this->getLang()),
260  'member' => array('text', $member),
261  ));
262  }
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: