ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTermsOfServiceFileSystemDocument.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/TermsOfService/interfaces/interface.ilTermsOfServiceSignableDocument.php';
5 
11 {
15  protected $lng;
16 
20  protected $has_content = false;
21 
25  protected $content = '';
26 
30  protected $iso2_language_code = '';
31 
35  protected $source = '';
36 
40  protected $source_files = array();
41 
45  public function __construct(ilLanguage $lng)
46  {
47  $this->setLanguageAdapter($lng);
48  $this->initSourceFiles();
49  }
50 
54  public function determine()
55  {
56  foreach($this->getSourceFiles() as $file => $iso2_language_code)
57  {
58  if(is_file($file) && is_readable($file))
59  {
60  $this->content = '';
61 
62  $content = file_get_contents($file);
63  if(strip_tags($content) === $content)
64  {
65  $lines = file($file);
66  foreach($lines as $line)
67  {
68  $this->content .= nl2br(trim($line));
69  }
70  }
71  else
72  {
73  $this->content = $content;
74  }
75 
76  $this->source = $file;
77  $this->has_content = (bool)strlen($this->content);
78  $this->iso2_language_code = $iso2_language_code;
79  return;
80  }
81  }
82 
83  require_once 'Services/TermsOfService/exceptions/class.ilTermsOfServiceNoSignableDocumentFoundException.php';
84  throw new ilTermsOfServiceNoSignableDocumentFoundException('Could not find any terms of service document for the passed language object');
85  }
86 
90  protected function initSourceFiles()
91  {
92  $this->source_files = array(
93  implode('/', array('.', 'Customizing', 'clients', CLIENT_ID, 'agreement', 'agreement_' . $this->getLanguageAdapter()->getLangKey() . '.html')) => $this->getLanguageAdapter()->getLangKey(),
94  implode('/', array('.', 'Customizing', 'clients', CLIENT_ID, 'agreement', 'agreement_' . $this->getLanguageAdapter()->getDefaultLanguage() . '.html')) => $this->getLanguageAdapter()->getDefaultLanguage(),
95  implode('/', array('.', 'Customizing', 'clients', CLIENT_ID, 'agreement', 'agreement_en.html')) => 'en',
96  implode('/', array('.', 'Customizing', 'global', 'agreement', 'agreement_' . $this->getLanguageAdapter()->getLangKey() . '.html')) => $this->getLanguageAdapter()->getLangKey(),
97  implode('/', array('.', 'Customizing', 'global', 'agreement', 'agreement_' . $this->getLanguageAdapter()->getDefaultLanguage() . '.html')) => $this->getLanguageAdapter()->getDefaultLanguage(),
98  implode('/', array('.', 'Customizing', 'global', 'agreement', 'agreement_en.html')) => 'en'
99  );
100  }
101 
105  public function setLanguageAdapter($lng)
106  {
107  $this->lng = $lng;
108  }
109 
113  public function getLanguageAdapter()
114  {
115  return $this->lng;
116  }
117 
121  public function setSourceFiles($source_directories)
122  {
123  $this->source_files = $source_directories;
124  }
125 
129  public function getSourceFiles()
130  {
131  return $this->source_files;
132  }
133 
137  public function hasContent()
138  {
139  return $this->has_content;
140  }
141 
145  public function getContent()
146  {
147  return $this->content;
148  }
149 
153  public function getSource()
154  {
155  return $this->source;
156  }
157 
161  public function getSourceType()
162  {
163  return self::SRC_TYPE_FILE_SYSTEM_PATH;
164  }
165 
169  public function getIso2LanguageCode()
170  {
172  }
173 }
print $file
language handling