ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.arStorage.php
Go to the documentation of this file.
1<?php
2require_once(dirname(__FILE__) . '/../class.ActiveRecord.php');
3
11abstract class arStorage extends ActiveRecord
12{
13
18
19
25 public static function getInstance(&$model)
26 {
31 arFieldCache::storeFromStorage(get_called_class(), $model);
32 $storage = self::getCalledClass();
33 $method = self::_toCamelCase('get_' . $storage->getArFieldList()->getPrimaryFieldName());
34 $storage->setExternalModelForStorage($model);
35 $storage->{$storage->getArFieldList()->getPrimaryFieldName()} = $model->{$method}();
36 if ($storage->{$storage->getArFieldList()->getPrimaryFieldName()}) {
37 $storage->read();
38 }
39 $storage->mapFromActiveRecord();
40
41 return $storage;
42 }
43
44
45 public function create()
46 {
47 $this->mapToActiveRecord();
48 parent::create();
49 }
50
51
52 public function update()
53 {
54 $this->mapToActiveRecord();
56 }
57
58
59 public function read()
60 {
61 parent::read();
62 $this->mapFromActiveRecord();
63 }
64
65
66 protected function mapToActiveRecord()
67 {
68 foreach (array_keys($this->getArFieldList()->getArrayForConnector()) as $key) {
69 $this->{$key} = $this->getValueForStorage($key);
70 }
71 }
72
73
74 protected function mapFromActiveRecord()
75 {
76 foreach (array_keys($this->getArFieldList()->getArrayForConnector()) as $key) {
77 $this->setValueToModel($key, $this->{$key});
78 }
79 }
80
81
87 public function getValueForStorage($key)
88 {
89 $method = self::_toCamelCase('get_' . $key);
90
91 return $this->getExternalModelForStorage()->{$method}();
92 }
93
94
101 public function setValueToModel($key, $value)
102 {
103 $method = self::_toCamelCase('set_' . $key);
104
105 return $this->getExternalModelForStorage()->{$method}($value);
106 }
107
108
109
110
111 //
112 // Setter & Getter
113 //
114
118 public function setExternalModelForStorage($model)
119 {
120 $this->external_model_for_storage = $model;
121 }
122
123
128 {
129 return $this->external_model_for_storage;
130 }
131}
132
133?>
134
Class ActiveRecord.
static _toCamelCase($str, $capitalise_first_char=false)
An exception for terminatinating execution or to throw for unit testing.
static storeFromStorage($storage_class_name, arStorageInterface $foreign_model)
Class arStorage.
setExternalModelForStorage($model)
getExternalModelForStorage()
getValueForStorage($key)
setValueToModel($key, $value)
$key
Definition: croninfo.php:18
update($pash, $contents, Config $config)