ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
4require_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 if (is_file($file) && is_readable($file)) {
58 $this->content = '';
59
60 $content = file_get_contents($file);
61 if (strip_tags($content) === $content) {
62 $lines = file($file);
63 foreach ($lines as $line) {
64 $this->content .= nl2br(trim($line));
65 }
66 } else {
67 $this->content = $content;
68 }
69
70 $this->source = $file;
71 $this->has_content = (bool) strlen($this->content);
72 $this->iso2_language_code = $iso2_language_code;
73 return;
74 }
75 }
76
77 require_once 'Services/TermsOfService/exceptions/class.ilTermsOfServiceNoSignableDocumentFoundException.php';
78 throw new ilTermsOfServiceNoSignableDocumentFoundException('Could not find any terms of service document for the passed language object');
79 }
80
84 public function exists()
85 {
86 return true;
87 }
88
92 protected function initSourceFiles()
93 {
94 $this->source_files = array(
95 implode('/', array('.', 'Customizing', 'clients', CLIENT_ID, 'agreement', 'agreement_' . $this->getLanguageAdapter()->getLangKey() . '.html')) => $this->getLanguageAdapter()->getLangKey(),
96 implode('/', array('.', 'Customizing', 'clients', CLIENT_ID, 'agreement', 'agreement_' . $this->getLanguageAdapter()->getDefaultLanguage() . '.html')) => $this->getLanguageAdapter()->getDefaultLanguage(),
97 implode('/', array('.', 'Customizing', 'clients', CLIENT_ID, 'agreement', 'agreement_en.html')) => 'en',
98 implode('/', array('.', 'Customizing', 'global', 'agreement', 'agreement_' . $this->getLanguageAdapter()->getLangKey() . '.html')) => $this->getLanguageAdapter()->getLangKey(),
99 implode('/', array('.', 'Customizing', 'global', 'agreement', 'agreement_' . $this->getLanguageAdapter()->getDefaultLanguage() . '.html')) => $this->getLanguageAdapter()->getDefaultLanguage(),
100 implode('/', array('.', 'Customizing', 'global', 'agreement', 'agreement_en.html')) => 'en'
101 );
102 }
103
107 public function setLanguageAdapter($lng)
108 {
109 $this->lng = $lng;
110 }
111
115 public function getLanguageAdapter()
116 {
117 return $this->lng;
118 }
119
123 public function setSourceFiles($source_directories)
124 {
125 $this->source_files = $source_directories;
126 }
127
131 public function getSourceFiles()
132 {
133 return $this->source_files;
134 }
135
139 public function hasContent()
140 {
141 return $this->has_content;
142 }
143
147 public function getContent()
148 {
149 return $this->content;
150 }
151
155 public function getSource()
156 {
157 return $this->source;
158 }
159
163 public function getSourceType()
164 {
166 }
167
171 public function getIso2LanguageCode()
172 {
174 }
175}
An exception for terminatinating execution or to throw for unit testing.
language handling
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file