@@ -44,167 +44,167 @@ |
||
44 | 44 | |
45 | 45 | class PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorage |
|
49 | - * @{ |
|
50 | - */ |
|
51 | - |
|
52 | - // ######################################################################## |
|
53 | - // CONSTRUCTOR |
|
54 | - // ######################################################################## |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorage |
|
49 | + * @{ |
|
50 | + */ |
|
51 | + |
|
52 | + // ######################################################################## |
|
53 | + // CONSTRUCTOR |
|
54 | + // ######################################################################## |
|
55 | 55 | |
56 | - /** |
|
57 | - * The constructor of the class, should be called only by inherited classes. |
|
58 | - * |
|
59 | - * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | - * |
|
61 | - * @protected |
|
62 | - */ |
|
63 | - function PGTStorage($cas_parent) |
|
56 | + /** |
|
57 | + * The constructor of the class, should be called only by inherited classes. |
|
58 | + * |
|
59 | + * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | + * |
|
61 | + * @protected |
|
62 | + */ |
|
63 | + function PGTStorage($cas_parent) |
|
64 | 64 | { |
65 | - phpCAS::traceBegin(); |
|
66 | - if ( !$cas_parent->isProxy() ) { |
|
67 | - phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | - } |
|
69 | - phpCAS::traceEnd(); |
|
65 | + phpCAS::traceBegin(); |
|
66 | + if ( !$cas_parent->isProxy() ) { |
|
67 | + phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | + } |
|
69 | + phpCAS::traceEnd(); |
|
70 | 70 | } |
71 | 71 | |
72 | - // ######################################################################## |
|
73 | - // DEBUGGING |
|
74 | - // ######################################################################## |
|
72 | + // ######################################################################## |
|
73 | + // DEBUGGING |
|
74 | + // ######################################################################## |
|
75 | 75 | |
76 | - /** |
|
77 | - * This virtual method returns an informational string giving the type of storage |
|
78 | - * used by the object (used for debugging purposes). |
|
79 | - * |
|
80 | - * @public |
|
81 | - */ |
|
82 | - function getStorageType() |
|
76 | + /** |
|
77 | + * This virtual method returns an informational string giving the type of storage |
|
78 | + * used by the object (used for debugging purposes). |
|
79 | + * |
|
80 | + * @public |
|
81 | + */ |
|
82 | + function getStorageType() |
|
83 | 83 | { |
84 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
84 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
85 | 85 | } |
86 | 86 | |
87 | - /** |
|
88 | - * This virtual method returns an informational string giving informations on the |
|
89 | - * parameters of the storage.(used for debugging purposes). |
|
90 | - * |
|
91 | - * @public |
|
92 | - */ |
|
93 | - function getStorageInfo() |
|
87 | + /** |
|
88 | + * This virtual method returns an informational string giving informations on the |
|
89 | + * parameters of the storage.(used for debugging purposes). |
|
90 | + * |
|
91 | + * @public |
|
92 | + */ |
|
93 | + function getStorageInfo() |
|
94 | 94 | { |
95 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
95 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
96 | 96 | } |
97 | 97 | |
98 | - // ######################################################################## |
|
99 | - // ERROR HANDLING |
|
100 | - // ######################################################################## |
|
98 | + // ######################################################################## |
|
99 | + // ERROR HANDLING |
|
100 | + // ######################################################################## |
|
101 | 101 | |
102 | - /** |
|
103 | - * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | - * read by PGTStorage::getErrorMessage(). |
|
105 | - * |
|
106 | - * @hideinitializer |
|
107 | - * @private |
|
108 | - * @deprecated not used. |
|
109 | - */ |
|
110 | - var $_error_message=FALSE; |
|
111 | - |
|
112 | - /** |
|
113 | - * This method sets en error message, which can be read later by |
|
114 | - * PGTStorage::getErrorMessage(). |
|
115 | - * |
|
116 | - * @param $error_message an error message |
|
117 | - * |
|
118 | - * @protected |
|
119 | - * @deprecated not used. |
|
120 | - */ |
|
121 | - function setErrorMessage($error_message) |
|
102 | + /** |
|
103 | + * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | + * read by PGTStorage::getErrorMessage(). |
|
105 | + * |
|
106 | + * @hideinitializer |
|
107 | + * @private |
|
108 | + * @deprecated not used. |
|
109 | + */ |
|
110 | + var $_error_message=FALSE; |
|
111 | + |
|
112 | + /** |
|
113 | + * This method sets en error message, which can be read later by |
|
114 | + * PGTStorage::getErrorMessage(). |
|
115 | + * |
|
116 | + * @param $error_message an error message |
|
117 | + * |
|
118 | + * @protected |
|
119 | + * @deprecated not used. |
|
120 | + */ |
|
121 | + function setErrorMessage($error_message) |
|
122 | 122 | { |
123 | - $this->_error_message = $error_message; |
|
123 | + $this->_error_message = $error_message; |
|
124 | 124 | } |
125 | 125 | |
126 | - /** |
|
127 | - * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | - * |
|
129 | - * @return boolean error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | - * otherwise. |
|
131 | - * |
|
132 | - * @public |
|
133 | - * @deprecated not used. |
|
134 | - */ |
|
135 | - function getErrorMessage() |
|
126 | + /** |
|
127 | + * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | + * |
|
129 | + * @return boolean error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | + * otherwise. |
|
131 | + * |
|
132 | + * @public |
|
133 | + * @deprecated not used. |
|
134 | + */ |
|
135 | + function getErrorMessage() |
|
136 | 136 | { |
137 | - return $this->_error_message; |
|
137 | + return $this->_error_message; |
|
138 | 138 | } |
139 | 139 | |
140 | - // ######################################################################## |
|
141 | - // INITIALIZATION |
|
142 | - // ######################################################################## |
|
143 | - |
|
144 | - /** |
|
145 | - * a boolean telling if the storage has already been initialized. Written by |
|
146 | - * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | - * |
|
148 | - * @hideinitializer |
|
149 | - * @private |
|
150 | - */ |
|
151 | - var $_initialized = FALSE; |
|
152 | - |
|
153 | - /** |
|
154 | - * This method tells if the storage has already been intialized. |
|
155 | - * |
|
156 | - * @return boolean boolean |
|
157 | - * |
|
158 | - * @protected |
|
159 | - */ |
|
160 | - function isInitialized() |
|
140 | + // ######################################################################## |
|
141 | + // INITIALIZATION |
|
142 | + // ######################################################################## |
|
143 | + |
|
144 | + /** |
|
145 | + * a boolean telling if the storage has already been initialized. Written by |
|
146 | + * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | + * |
|
148 | + * @hideinitializer |
|
149 | + * @private |
|
150 | + */ |
|
151 | + var $_initialized = FALSE; |
|
152 | + |
|
153 | + /** |
|
154 | + * This method tells if the storage has already been intialized. |
|
155 | + * |
|
156 | + * @return boolean boolean |
|
157 | + * |
|
158 | + * @protected |
|
159 | + */ |
|
160 | + function isInitialized() |
|
161 | 161 | { |
162 | - return $this->_initialized; |
|
162 | + return $this->_initialized; |
|
163 | 163 | } |
164 | 164 | |
165 | - /** |
|
166 | - * This virtual method initializes the object. |
|
167 | - * |
|
168 | - * @protected |
|
169 | - */ |
|
170 | - function init() |
|
165 | + /** |
|
166 | + * This virtual method initializes the object. |
|
167 | + * |
|
168 | + * @protected |
|
169 | + */ |
|
170 | + function init() |
|
171 | 171 | { |
172 | - $this->_initialized = TRUE; |
|
172 | + $this->_initialized = TRUE; |
|
173 | 173 | } |
174 | 174 | |
175 | - // ######################################################################## |
|
176 | - // PGT I/O |
|
177 | - // ######################################################################## |
|
178 | - |
|
179 | - /** |
|
180 | - * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | - * @note Should never be called. |
|
182 | - * |
|
183 | - * @param $pgt the PGT |
|
184 | - * @param $pgt_iou the PGT iou |
|
185 | - * |
|
186 | - * @protected |
|
187 | - */ |
|
188 | - function write($pgt,$pgt_iou) |
|
175 | + // ######################################################################## |
|
176 | + // PGT I/O |
|
177 | + // ######################################################################## |
|
178 | + |
|
179 | + /** |
|
180 | + * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | + * @note Should never be called. |
|
182 | + * |
|
183 | + * @param $pgt the PGT |
|
184 | + * @param $pgt_iou the PGT iou |
|
185 | + * |
|
186 | + * @protected |
|
187 | + */ |
|
188 | + function write($pgt,$pgt_iou) |
|
189 | 189 | { |
190 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
190 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | - * the corresponding storage entry. |
|
196 | - * @note Should never be called. |
|
197 | - * |
|
198 | - * @param $pgt_iou the PGT iou |
|
199 | - * |
|
200 | - * @protected |
|
201 | - */ |
|
202 | - function read($pgt_iou) |
|
193 | + /** |
|
194 | + * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | + * the corresponding storage entry. |
|
196 | + * @note Should never be called. |
|
197 | + * |
|
198 | + * @param $pgt_iou the PGT iou |
|
199 | + * |
|
200 | + * @protected |
|
201 | + */ |
|
202 | + function read($pgt_iou) |
|
203 | 203 | { |
204 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
204 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
205 | 205 | } |
206 | 206 | |
207 | - /** @} */ |
|
207 | + /** @} */ |
|
208 | 208 | |
209 | 209 | } |
210 | 210 |
@@ -44,231 +44,231 @@ |
||
44 | 44 | |
45 | 45 | class PGTStorageFile extends PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorageFile |
|
49 | - * @{ |
|
50 | - */ |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorageFile |
|
49 | + * @{ |
|
50 | + */ |
|
51 | 51 | |
52 | - /** |
|
53 | - * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | - * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | - * |
|
56 | - * @private |
|
57 | - */ |
|
58 | - var $_path; |
|
52 | + /** |
|
53 | + * a string telling where PGT's should be stored on the filesystem. Written by |
|
54 | + * PGTStorageFile::PGTStorageFile(), read by getPath(). |
|
55 | + * |
|
56 | + * @private |
|
57 | + */ |
|
58 | + var $_path; |
|
59 | 59 | |
60 | - /** |
|
61 | - * This method returns the name of the directory where PGT's should be stored |
|
62 | - * on the filesystem. |
|
63 | - * |
|
64 | - * @return the name of a directory (with leading and trailing '/') |
|
65 | - * |
|
66 | - * @private |
|
67 | - */ |
|
68 | - function getPath() |
|
60 | + /** |
|
61 | + * This method returns the name of the directory where PGT's should be stored |
|
62 | + * on the filesystem. |
|
63 | + * |
|
64 | + * @return the name of a directory (with leading and trailing '/') |
|
65 | + * |
|
66 | + * @private |
|
67 | + */ |
|
68 | + function getPath() |
|
69 | 69 | { |
70 | - return $this->_path; |
|
70 | + return $this->_path; |
|
71 | 71 | } |
72 | 72 | |
73 | - /** |
|
74 | - * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | - * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | - * |
|
77 | - * @private |
|
78 | - */ |
|
79 | - var $_format; |
|
73 | + /** |
|
74 | + * a string telling the format to use to store PGT's (plain or xml). Written by |
|
75 | + * PGTStorageFile::PGTStorageFile(), read by getFormat(). |
|
76 | + * |
|
77 | + * @private |
|
78 | + */ |
|
79 | + var $_format; |
|
80 | 80 | |
81 | - /** |
|
82 | - * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | - * |
|
84 | - * @return a string corresponding to the format used (plain or xml). |
|
85 | - * |
|
86 | - * @private |
|
87 | - */ |
|
88 | - function getFormat() |
|
81 | + /** |
|
82 | + * This method returns the format to use when storing PGT's on the filesystem. |
|
83 | + * |
|
84 | + * @return a string corresponding to the format used (plain or xml). |
|
85 | + * |
|
86 | + * @private |
|
87 | + */ |
|
88 | + function getFormat() |
|
89 | 89 | { |
90 | - return $this->_format; |
|
90 | + return $this->_format; |
|
91 | 91 | } |
92 | 92 | |
93 | - // ######################################################################## |
|
94 | - // DEBUGGING |
|
95 | - // ######################################################################## |
|
93 | + // ######################################################################## |
|
94 | + // DEBUGGING |
|
95 | + // ######################################################################## |
|
96 | 96 | |
97 | - /** |
|
98 | - * This method returns an informational string giving the type of storage |
|
99 | - * used by the object (used for debugging purposes). |
|
100 | - * |
|
101 | - * @return string informational string. |
|
102 | - * @public |
|
103 | - */ |
|
104 | - function getStorageType() |
|
97 | + /** |
|
98 | + * This method returns an informational string giving the type of storage |
|
99 | + * used by the object (used for debugging purposes). |
|
100 | + * |
|
101 | + * @return string informational string. |
|
102 | + * @public |
|
103 | + */ |
|
104 | + function getStorageType() |
|
105 | 105 | { |
106 | - return "file"; |
|
106 | + return "file"; |
|
107 | 107 | } |
108 | 108 | |
109 | - /** |
|
110 | - * This method returns an informational string giving informations on the |
|
111 | - * parameters of the storage.(used for debugging purposes). |
|
112 | - * |
|
113 | - * @return string informational string. |
|
114 | - * @public |
|
115 | - */ |
|
116 | - function getStorageInfo() |
|
109 | + /** |
|
110 | + * This method returns an informational string giving informations on the |
|
111 | + * parameters of the storage.(used for debugging purposes). |
|
112 | + * |
|
113 | + * @return string informational string. |
|
114 | + * @public |
|
115 | + */ |
|
116 | + function getStorageInfo() |
|
117 | 117 | { |
118 | - return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
118 | + return 'path=`'.$this->getPath().'\', format=`'.$this->getFormat().'\''; |
|
119 | 119 | } |
120 | 120 | |
121 | - // ######################################################################## |
|
122 | - // CONSTRUCTOR |
|
123 | - // ######################################################################## |
|
121 | + // ######################################################################## |
|
122 | + // CONSTRUCTOR |
|
123 | + // ######################################################################## |
|
124 | 124 | |
125 | - /** |
|
126 | - * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | - * |
|
128 | - * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
129 | - * @param string $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | - * @param string $path the path where the PGT's should be stored |
|
131 | - * |
|
132 | - * @public |
|
133 | - */ |
|
134 | - function PGTStorageFile($cas_parent,$format,$path) |
|
125 | + /** |
|
126 | + * The class constructor, called by CASClient::SetPGTStorageFile(). |
|
127 | + * |
|
128 | + * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
129 | + * @param string $format the format used to store the PGT's (`plain' and `xml' allowed). |
|
130 | + * @param string $path the path where the PGT's should be stored |
|
131 | + * |
|
132 | + * @public |
|
133 | + */ |
|
134 | + function PGTStorageFile($cas_parent,$format,$path) |
|
135 | 135 | { |
136 | - phpCAS::traceBegin(); |
|
137 | - // call the ancestor's constructor |
|
138 | - $this->PGTStorage($cas_parent); |
|
136 | + phpCAS::traceBegin(); |
|
137 | + // call the ancestor's constructor |
|
138 | + $this->PGTStorage($cas_parent); |
|
139 | 139 | |
140 | - if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | - if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
140 | + if (empty($format) ) $format = CAS_PGT_STORAGE_FILE_DEFAULT_FORMAT; |
|
141 | + if (empty($path) ) $path = CAS_PGT_STORAGE_FILE_DEFAULT_PATH; |
|
142 | 142 | |
143 | - // check that the path is an absolute path |
|
144 | - if (getenv("OS")=="Windows_NT"){ |
|
143 | + // check that the path is an absolute path |
|
144 | + if (getenv("OS")=="Windows_NT"){ |
|
145 | 145 | |
146 | - if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | - } |
|
146 | + if (!preg_match('`^[a-zA-Z]:`', $path)) { |
|
147 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
148 | + } |
|
149 | 149 | |
150 | - } |
|
151 | - else |
|
152 | - { |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
153 | 153 | |
154 | - if ( $path[0] != '/' ) { |
|
155 | - phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | - } |
|
154 | + if ( $path[0] != '/' ) { |
|
155 | + phpCAS::error('an absolute path is needed for PGT storage to file'); |
|
156 | + } |
|
157 | 157 | |
158 | - // store the path (with a leading and trailing '/') |
|
159 | - $path = preg_replace('|[/]*$|','/',$path); |
|
160 | - $path = preg_replace('|^[/]*|','/',$path); |
|
161 | - } |
|
158 | + // store the path (with a leading and trailing '/') |
|
159 | + $path = preg_replace('|[/]*$|','/',$path); |
|
160 | + $path = preg_replace('|^[/]*|','/',$path); |
|
161 | + } |
|
162 | 162 | |
163 | - $this->_path = $path; |
|
164 | - // check the format and store it |
|
165 | - switch ($format) { |
|
166 | - case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
163 | + $this->_path = $path; |
|
164 | + // check the format and store it |
|
165 | + switch ($format) { |
|
166 | + case CAS_PGT_STORAGE_FILE_FORMAT_PLAIN: |
|
167 | 167 | case CAS_PGT_STORAGE_FILE_FORMAT_XML: |
168 | - $this->_format = $format; |
|
169 | - break; |
|
170 | - default: |
|
171 | - phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | - } |
|
173 | - phpCAS::traceEnd(); |
|
168 | + $this->_format = $format; |
|
169 | + break; |
|
170 | + default: |
|
171 | + phpCAS::error('unknown PGT file storage format (`'.CAS_PGT_STORAGE_FILE_FORMAT_PLAIN.'\' and `'.CAS_PGT_STORAGE_FILE_FORMAT_XML.'\' allowed)'); |
|
172 | + } |
|
173 | + phpCAS::traceEnd(); |
|
174 | 174 | } |
175 | 175 | |
176 | - // ######################################################################## |
|
177 | - // INITIALIZATION |
|
178 | - // ######################################################################## |
|
176 | + // ######################################################################## |
|
177 | + // INITIALIZATION |
|
178 | + // ######################################################################## |
|
179 | 179 | |
180 | - /** |
|
181 | - * This method is used to initialize the storage. Halts on error. |
|
182 | - * |
|
183 | - * @public |
|
184 | - */ |
|
185 | - function init() |
|
180 | + /** |
|
181 | + * This method is used to initialize the storage. Halts on error. |
|
182 | + * |
|
183 | + * @public |
|
184 | + */ |
|
185 | + function init() |
|
186 | 186 | { |
187 | - phpCAS::traceBegin(); |
|
188 | - // if the storage has already been initialized, return immediatly |
|
189 | - if ( $this->isInitialized() ) |
|
190 | - return; |
|
191 | - // call the ancestor's method (mark as initialized) |
|
192 | - parent::init(); |
|
193 | - phpCAS::traceEnd(); |
|
187 | + phpCAS::traceBegin(); |
|
188 | + // if the storage has already been initialized, return immediatly |
|
189 | + if ( $this->isInitialized() ) |
|
190 | + return; |
|
191 | + // call the ancestor's method (mark as initialized) |
|
192 | + parent::init(); |
|
193 | + phpCAS::traceEnd(); |
|
194 | 194 | } |
195 | 195 | |
196 | - // ######################################################################## |
|
197 | - // PGT I/O |
|
198 | - // ######################################################################## |
|
196 | + // ######################################################################## |
|
197 | + // PGT I/O |
|
198 | + // ######################################################################## |
|
199 | 199 | |
200 | - /** |
|
201 | - * This method returns the filename corresponding to a PGT Iou. |
|
202 | - * |
|
203 | - * @param $pgt_iou the PGT iou. |
|
204 | - * |
|
205 | - * @return string filename |
|
206 | - * @private |
|
207 | - */ |
|
208 | - function getPGTIouFilename($pgt_iou) |
|
200 | + /** |
|
201 | + * This method returns the filename corresponding to a PGT Iou. |
|
202 | + * |
|
203 | + * @param $pgt_iou the PGT iou. |
|
204 | + * |
|
205 | + * @return string filename |
|
206 | + * @private |
|
207 | + */ |
|
208 | + function getPGTIouFilename($pgt_iou) |
|
209 | 209 | { |
210 | - phpCAS::traceBegin(); |
|
211 | - $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | - phpCAS::traceEnd($filename); |
|
213 | - return $filename; |
|
210 | + phpCAS::traceBegin(); |
|
211 | + $filename = $this->getPath().$pgt_iou.'.'.$this->getFormat(); |
|
212 | + phpCAS::traceEnd($filename); |
|
213 | + return $filename; |
|
214 | 214 | } |
215 | 215 | |
216 | - /** |
|
217 | - * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | - * warning on error. |
|
219 | - * |
|
220 | - * @param $pgt the PGT |
|
221 | - * @param $pgt_iou the PGT iou |
|
222 | - * |
|
223 | - * @public |
|
224 | - */ |
|
225 | - function write($pgt,$pgt_iou) |
|
216 | + /** |
|
217 | + * This method stores a PGT and its corresponding PGT Iou into a file. Echoes a |
|
218 | + * warning on error. |
|
219 | + * |
|
220 | + * @param $pgt the PGT |
|
221 | + * @param $pgt_iou the PGT iou |
|
222 | + * |
|
223 | + * @public |
|
224 | + */ |
|
225 | + function write($pgt,$pgt_iou) |
|
226 | 226 | { |
227 | - phpCAS::traceBegin(); |
|
228 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | - if ( $f=fopen($fname,"w") ) { |
|
230 | - if ( fputs($f,$pgt) === FALSE ) { |
|
231 | - phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | - } |
|
233 | - fclose($f); |
|
234 | - } else { |
|
235 | - phpCAS::error('could not open `'.$fname.'\''); |
|
236 | - } |
|
237 | - phpCAS::traceEnd(); |
|
227 | + phpCAS::traceBegin(); |
|
228 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
229 | + if ( $f=fopen($fname,"w") ) { |
|
230 | + if ( fputs($f,$pgt) === FALSE ) { |
|
231 | + phpCAS::error('could not write PGT to `'.$fname.'\''); |
|
232 | + } |
|
233 | + fclose($f); |
|
234 | + } else { |
|
235 | + phpCAS::error('could not open `'.$fname.'\''); |
|
236 | + } |
|
237 | + phpCAS::traceEnd(); |
|
238 | 238 | } |
239 | 239 | |
240 | - /** |
|
241 | - * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | - * corresponding file. |
|
243 | - * |
|
244 | - * @param $pgt_iou the PGT iou |
|
245 | - * |
|
246 | - * @return false|string corresponding PGT, or FALSE on error |
|
247 | - * |
|
248 | - * @public |
|
249 | - */ |
|
250 | - function read($pgt_iou) |
|
240 | + /** |
|
241 | + * This method reads a PGT corresponding to a PGT Iou and deletes the |
|
242 | + * corresponding file. |
|
243 | + * |
|
244 | + * @param $pgt_iou the PGT iou |
|
245 | + * |
|
246 | + * @return false|string corresponding PGT, or FALSE on error |
|
247 | + * |
|
248 | + * @public |
|
249 | + */ |
|
250 | + function read($pgt_iou) |
|
251 | 251 | { |
252 | - phpCAS::traceBegin(); |
|
253 | - $pgt = FALSE; |
|
254 | - $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | - if ( !($f=fopen($fname,"r")) ) { |
|
256 | - phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | - } else { |
|
258 | - if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | - phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | - } |
|
261 | - fclose($f); |
|
262 | - } |
|
252 | + phpCAS::traceBegin(); |
|
253 | + $pgt = FALSE; |
|
254 | + $fname = $this->getPGTIouFilename($pgt_iou); |
|
255 | + if ( !($f=fopen($fname,"r")) ) { |
|
256 | + phpCAS::trace('could not open `'.$fname.'\''); |
|
257 | + } else { |
|
258 | + if ( ($pgt=fgets($f)) === FALSE ) { |
|
259 | + phpCAS::trace('could not read PGT from `'.$fname.'\''); |
|
260 | + } |
|
261 | + fclose($f); |
|
262 | + } |
|
263 | 263 | |
264 | - // delete the PGT file |
|
265 | - @unlink($fname); |
|
264 | + // delete the PGT file |
|
265 | + @unlink($fname); |
|
266 | 266 | |
267 | - phpCAS::traceEnd($pgt); |
|
268 | - return $pgt; |
|
267 | + phpCAS::traceEnd($pgt); |
|
268 | + return $pgt; |
|
269 | 269 | } |
270 | 270 | |
271 | - /** @} */ |
|
271 | + /** @} */ |
|
272 | 272 | |
273 | 273 | } |
274 | 274 |
@@ -45,175 +45,175 @@ |
||
45 | 45 | |
46 | 46 | class PGTStorageDB extends PGTStorage |
47 | 47 | { |
48 | - /** |
|
49 | - * @addtogroup internalPGTStorageDB |
|
50 | - * @{ |
|
51 | - */ |
|
52 | - |
|
53 | - /** |
|
54 | - * a string representing a PEAR DB URL to connect to the database. Written by |
|
55 | - * PGTStorageDB::PGTStorageDB(), read by getURL(). |
|
56 | - * |
|
57 | - * @hideinitializer |
|
58 | - * @private |
|
59 | - */ |
|
60 | - var $_url=''; |
|
61 | - |
|
62 | - /** |
|
63 | - * This method returns the PEAR DB URL to use to connect to the database. |
|
64 | - * |
|
65 | - * @return string PEAR DB URL |
|
66 | - * |
|
67 | - * @private |
|
68 | - */ |
|
69 | - function getURL() |
|
48 | + /** |
|
49 | + * @addtogroup internalPGTStorageDB |
|
50 | + * @{ |
|
51 | + */ |
|
52 | + |
|
53 | + /** |
|
54 | + * a string representing a PEAR DB URL to connect to the database. Written by |
|
55 | + * PGTStorageDB::PGTStorageDB(), read by getURL(). |
|
56 | + * |
|
57 | + * @hideinitializer |
|
58 | + * @private |
|
59 | + */ |
|
60 | + var $_url=''; |
|
61 | + |
|
62 | + /** |
|
63 | + * This method returns the PEAR DB URL to use to connect to the database. |
|
64 | + * |
|
65 | + * @return string PEAR DB URL |
|
66 | + * |
|
67 | + * @private |
|
68 | + */ |
|
69 | + function getURL() |
|
70 | 70 | { |
71 | - return $this->_url; |
|
71 | + return $this->_url; |
|
72 | 72 | } |
73 | 73 | |
74 | - /** |
|
75 | - * The handle of the connection to the database where PGT's are stored. Written by |
|
76 | - * PGTStorageDB::init(), read by getLink(). |
|
77 | - * |
|
78 | - * @hideinitializer |
|
79 | - * @private |
|
80 | - */ |
|
81 | - var $_link = null; |
|
82 | - |
|
83 | - /** |
|
84 | - * This method returns the handle of the connection to the database where PGT's are |
|
85 | - * stored. |
|
86 | - * |
|
87 | - * @return a handle of connection. |
|
88 | - * |
|
89 | - * @private |
|
90 | - */ |
|
91 | - function getLink() |
|
74 | + /** |
|
75 | + * The handle of the connection to the database where PGT's are stored. Written by |
|
76 | + * PGTStorageDB::init(), read by getLink(). |
|
77 | + * |
|
78 | + * @hideinitializer |
|
79 | + * @private |
|
80 | + */ |
|
81 | + var $_link = null; |
|
82 | + |
|
83 | + /** |
|
84 | + * This method returns the handle of the connection to the database where PGT's are |
|
85 | + * stored. |
|
86 | + * |
|
87 | + * @return a handle of connection. |
|
88 | + * |
|
89 | + * @private |
|
90 | + */ |
|
91 | + function getLink() |
|
92 | 92 | { |
93 | - return $this->_link; |
|
93 | + return $this->_link; |
|
94 | 94 | } |
95 | 95 | |
96 | - /** |
|
97 | - * The name of the table where PGT's are stored. Written by |
|
98 | - * PGTStorageDB::PGTStorageDB(), read by getTable(). |
|
99 | - * |
|
100 | - * @hideinitializer |
|
101 | - * @private |
|
102 | - */ |
|
103 | - var $_table = ''; |
|
104 | - |
|
105 | - /** |
|
106 | - * This method returns the name of the table where PGT's are stored. |
|
107 | - * |
|
108 | - * @return string name of a table. |
|
109 | - * |
|
110 | - * @private |
|
111 | - */ |
|
112 | - function getTable() |
|
96 | + /** |
|
97 | + * The name of the table where PGT's are stored. Written by |
|
98 | + * PGTStorageDB::PGTStorageDB(), read by getTable(). |
|
99 | + * |
|
100 | + * @hideinitializer |
|
101 | + * @private |
|
102 | + */ |
|
103 | + var $_table = ''; |
|
104 | + |
|
105 | + /** |
|
106 | + * This method returns the name of the table where PGT's are stored. |
|
107 | + * |
|
108 | + * @return string name of a table. |
|
109 | + * |
|
110 | + * @private |
|
111 | + */ |
|
112 | + function getTable() |
|
113 | 113 | { |
114 | - return $this->_table; |
|
114 | + return $this->_table; |
|
115 | 115 | } |
116 | 116 | |
117 | - // ######################################################################## |
|
118 | - // DEBUGGING |
|
119 | - // ######################################################################## |
|
117 | + // ######################################################################## |
|
118 | + // DEBUGGING |
|
119 | + // ######################################################################## |
|
120 | 120 | |
121 | - /** |
|
122 | - * This method returns an informational string giving the type of storage |
|
123 | - * used by the object (used for debugging purposes). |
|
124 | - * |
|
125 | - * @return string informational string. |
|
126 | - * @public |
|
127 | - */ |
|
128 | - function getStorageType() |
|
121 | + /** |
|
122 | + * This method returns an informational string giving the type of storage |
|
123 | + * used by the object (used for debugging purposes). |
|
124 | + * |
|
125 | + * @return string informational string. |
|
126 | + * @public |
|
127 | + */ |
|
128 | + function getStorageType() |
|
129 | 129 | { |
130 | - return "database"; |
|
130 | + return "database"; |
|
131 | 131 | } |
132 | 132 | |
133 | - /** |
|
134 | - * This method returns an informational string giving informations on the |
|
135 | - * parameters of the storage.(used for debugging purposes). |
|
136 | - * |
|
137 | - * @public |
|
138 | - */ |
|
139 | - function getStorageInfo() |
|
133 | + /** |
|
134 | + * This method returns an informational string giving informations on the |
|
135 | + * parameters of the storage.(used for debugging purposes). |
|
136 | + * |
|
137 | + * @public |
|
138 | + */ |
|
139 | + function getStorageInfo() |
|
140 | 140 | { |
141 | - return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; |
|
141 | + return 'url=`'.$this->getURL().'\', table=`'.$this->getTable().'\''; |
|
142 | 142 | } |
143 | 143 | |
144 | - // ######################################################################## |
|
145 | - // CONSTRUCTOR |
|
146 | - // ######################################################################## |
|
144 | + // ######################################################################## |
|
145 | + // CONSTRUCTOR |
|
146 | + // ######################################################################## |
|
147 | 147 | |
148 | - /** |
|
149 | - * The class constructor, called by CASClient::SetPGTStorageDB(). |
|
150 | - * |
|
151 | - * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
152 | - * @param $user the user to access the data with |
|
153 | - * @param $password the user's password |
|
154 | - * @param $database_type the type of the database hosting the data |
|
155 | - * @param $hostname the server hosting the database |
|
156 | - * @param $port the port the server is listening on |
|
157 | - * @param $database the name of the database |
|
158 | - * @param $table the name of the table storing the data |
|
159 | - * |
|
160 | - * @public |
|
161 | - */ |
|
162 | - function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) |
|
148 | + /** |
|
149 | + * The class constructor, called by CASClient::SetPGTStorageDB(). |
|
150 | + * |
|
151 | + * @param CASClient $cas_parent the CASClient instance that creates the object. |
|
152 | + * @param $user the user to access the data with |
|
153 | + * @param $password the user's password |
|
154 | + * @param $database_type the type of the database hosting the data |
|
155 | + * @param $hostname the server hosting the database |
|
156 | + * @param $port the port the server is listening on |
|
157 | + * @param $database the name of the database |
|
158 | + * @param $table the name of the table storing the data |
|
159 | + * |
|
160 | + * @public |
|
161 | + */ |
|
162 | + function PGTStorageDB($cas_parent,$user,$password,$database_type,$hostname,$port,$database,$table) |
|
163 | 163 | { |
164 | - phpCAS::traceBegin(); |
|
164 | + phpCAS::traceBegin(); |
|
165 | 165 | |
166 | - // call the ancestor's constructor |
|
167 | - $this->PGTStorage($cas_parent); |
|
166 | + // call the ancestor's constructor |
|
167 | + $this->PGTStorage($cas_parent); |
|
168 | 168 | |
169 | - if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | - if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | - if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | - if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | - if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
169 | + if ( empty($database_type) ) $database_type = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE_TYPE; |
|
170 | + if ( empty($hostname) ) $hostname = CAS_PGT_STORAGE_DB_DEFAULT_HOSTNAME; |
|
171 | + if ( $port==0 ) $port = CAS_PGT_STORAGE_DB_DEFAULT_PORT; |
|
172 | + if ( empty($database) ) $database = CAS_PGT_STORAGE_DB_DEFAULT_DATABASE; |
|
173 | + if ( empty($table) ) $table = CAS_PGT_STORAGE_DB_DEFAULT_TABLE; |
|
174 | 174 | |
175 | - // build and store the PEAR DB URL |
|
176 | - $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
|
175 | + // build and store the PEAR DB URL |
|
176 | + $this->_url = $database_type.':'.'//'.$user.':'.$password.'@'.$hostname.':'.$port.'/'.$database; |
|
177 | 177 | |
178 | - // XXX should use setURL and setTable |
|
179 | - phpCAS::traceEnd(); |
|
178 | + // XXX should use setURL and setTable |
|
179 | + phpCAS::traceEnd(); |
|
180 | 180 | } |
181 | 181 | |
182 | - // ######################################################################## |
|
183 | - // INITIALIZATION |
|
184 | - // ######################################################################## |
|
182 | + // ######################################################################## |
|
183 | + // INITIALIZATION |
|
184 | + // ######################################################################## |
|
185 | 185 | |
186 | - /** |
|
187 | - * This method is used to initialize the storage. Halts on error. |
|
188 | - * |
|
189 | - * @public |
|
190 | - */ |
|
191 | - function init() |
|
186 | + /** |
|
187 | + * This method is used to initialize the storage. Halts on error. |
|
188 | + * |
|
189 | + * @public |
|
190 | + */ |
|
191 | + function init() |
|
192 | 192 | { |
193 | - phpCAS::traceBegin(); |
|
194 | - // if the storage has already been initialized, return immediatly |
|
195 | - if ( $this->isInitialized() ) |
|
196 | - return; |
|
197 | - // call the ancestor's method (mark as initialized) |
|
198 | - parent::init(); |
|
193 | + phpCAS::traceBegin(); |
|
194 | + // if the storage has already been initialized, return immediatly |
|
195 | + if ( $this->isInitialized() ) |
|
196 | + return; |
|
197 | + // call the ancestor's method (mark as initialized) |
|
198 | + parent::init(); |
|
199 | 199 | |
200 | - //include phpDB library (the test was introduced in release 0.4.8 for |
|
201 | - //the integration into Tikiwiki). |
|
202 | - if (!class_exists('DB')) { |
|
203 | - include_once('DB.php'); |
|
204 | - } |
|
205 | - |
|
206 | - // try to connect to the database |
|
207 | - $this->_link = DB::connect($this->getURL()); |
|
208 | - if ( DB::isError($this->_link) ) { |
|
209 | - phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); |
|
210 | - } |
|
211 | - // Dump into trace |
|
212 | - var_dump($this->_link); |
|
213 | - phpCAS::traceBEnd(); |
|
200 | + //include phpDB library (the test was introduced in release 0.4.8 for |
|
201 | + //the integration into Tikiwiki). |
|
202 | + if (!class_exists('DB')) { |
|
203 | + include_once('DB.php'); |
|
204 | + } |
|
205 | + |
|
206 | + // try to connect to the database |
|
207 | + $this->_link = DB::connect($this->getURL()); |
|
208 | + if ( DB::isError($this->_link) ) { |
|
209 | + phpCAS::error('could not connect to database ('.DB::errorMessage($this->_link).')'); |
|
210 | + } |
|
211 | + // Dump into trace |
|
212 | + var_dump($this->_link); |
|
213 | + phpCAS::traceBEnd(); |
|
214 | 214 | } |
215 | 215 | |
216 | - /** @} */ |
|
216 | + /** @} */ |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | ?> |
220 | 220 | \ No newline at end of file |
@@ -33,99 +33,99 @@ discard block |
||
33 | 33 | class SignedRequest |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $rawSignedRequest; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $payload; |
|
45 | - |
|
46 | - /** |
|
47 | - * Instantiate a new SignedRequest entity. |
|
48 | - * |
|
49 | - * @param string|null $rawSignedRequest The raw signed request. |
|
50 | - * @param string|null $state random string to prevent CSRF. |
|
51 | - * @param string|null $appSecret |
|
52 | - */ |
|
53 | - public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | - { |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $rawSignedRequest; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $payload; |
|
45 | + |
|
46 | + /** |
|
47 | + * Instantiate a new SignedRequest entity. |
|
48 | + * |
|
49 | + * @param string|null $rawSignedRequest The raw signed request. |
|
50 | + * @param string|null $state random string to prevent CSRF. |
|
51 | + * @param string|null $appSecret |
|
52 | + */ |
|
53 | + public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | + { |
|
55 | 55 | if (!$rawSignedRequest) { |
56 | - return; |
|
56 | + return; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->rawSignedRequest = $rawSignedRequest; |
60 | 60 | $this->payload = static::parse($rawSignedRequest, $state, $appSecret); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns the raw signed request data. |
|
65 | - * |
|
66 | - * @return string |
|
67 | - */ |
|
68 | - public function getRawSignedRequest() |
|
69 | - { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns the raw signed request data. |
|
65 | + * |
|
66 | + * @return string |
|
67 | + */ |
|
68 | + public function getRawSignedRequest() |
|
69 | + { |
|
70 | 70 | return $this->rawSignedRequest; |
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the parsed signed request data. |
|
75 | - * |
|
76 | - * @return array|null |
|
77 | - */ |
|
78 | - public function getPayload() |
|
79 | - { |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the parsed signed request data. |
|
75 | + * |
|
76 | + * @return array|null |
|
77 | + */ |
|
78 | + public function getPayload() |
|
79 | + { |
|
80 | 80 | return $this->payload; |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns a property from the signed request data if available. |
|
85 | - * |
|
86 | - * @param string $key |
|
87 | - * @param integer $default |
|
88 | - * |
|
89 | - * @return mixed|null |
|
90 | - */ |
|
91 | - public function get($key, $default = null) |
|
92 | - { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns a property from the signed request data if available. |
|
85 | + * |
|
86 | + * @param string $key |
|
87 | + * @param integer $default |
|
88 | + * |
|
89 | + * @return mixed|null |
|
90 | + */ |
|
91 | + public function get($key, $default = null) |
|
92 | + { |
|
93 | 93 | if (isset($this->payload[$key])) { |
94 | - return $this->payload[$key]; |
|
94 | + return $this->payload[$key]; |
|
95 | 95 | } |
96 | 96 | return $default; |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns user_id from signed request data if available. |
|
101 | - * |
|
102 | - * @return string|null |
|
103 | - */ |
|
104 | - public function getUserId() |
|
105 | - { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns user_id from signed request data if available. |
|
101 | + * |
|
102 | + * @return string|null |
|
103 | + */ |
|
104 | + public function getUserId() |
|
105 | + { |
|
106 | 106 | return $this->get('user_id'); |
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Checks for OAuth data in the payload. |
|
111 | - * |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function hasOAuthData() |
|
115 | - { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Checks for OAuth data in the payload. |
|
111 | + * |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function hasOAuthData() |
|
115 | + { |
|
116 | 116 | return isset($this->payload['oauth_token']) || isset($this->payload['code']); |
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Creates a signed request from an array of data. |
|
121 | - * |
|
122 | - * @param array $payload |
|
123 | - * @param string|null $appSecret |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function make(array $payload, $appSecret = null) |
|
128 | - { |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Creates a signed request from an array of data. |
|
121 | + * |
|
122 | + * @param array $payload |
|
123 | + * @param string|null $appSecret |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function make(array $payload, $appSecret = null) |
|
128 | + { |
|
129 | 129 | $payload['algorithm'] = 'HMAC-SHA256'; |
130 | 130 | $payload['issued_at'] = time(); |
131 | 131 | $encodedPayload = static::base64UrlEncode(json_encode($payload)); |
@@ -134,20 +134,20 @@ discard block |
||
134 | 134 | $encodedSig = static::base64UrlEncode($hashedSig); |
135 | 135 | |
136 | 136 | return $encodedSig.'.'.$encodedPayload; |
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Validates and decodes a signed request and returns |
|
141 | - * the payload as an array. |
|
142 | - * |
|
143 | - * @param string $signedRequest |
|
144 | - * @param string|null $state |
|
145 | - * @param string|null $appSecret |
|
146 | - * |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | - { |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Validates and decodes a signed request and returns |
|
141 | + * the payload as an array. |
|
142 | + * |
|
143 | + * @param string $signedRequest |
|
144 | + * @param string|null $state |
|
145 | + * @param string|null $appSecret |
|
146 | + * |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | + { |
|
151 | 151 | list($encodedSig, $encodedPayload) = static::split($signedRequest); |
152 | 152 | |
153 | 153 | // Signature validation |
@@ -159,228 +159,228 @@ discard block |
||
159 | 159 | $data = static::decodePayload($encodedPayload); |
160 | 160 | static::validateAlgorithm($data); |
161 | 161 | if ($state) { |
162 | - static::validateCsrf($data, $state); |
|
162 | + static::validateCsrf($data, $state); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $data; |
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Validates the format of a signed request. |
|
170 | - * |
|
171 | - * @param string $signedRequest |
|
172 | - * |
|
173 | - * @throws FacebookSDKException |
|
174 | - */ |
|
175 | - public static function validateFormat($signedRequest) |
|
176 | - { |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Validates the format of a signed request. |
|
170 | + * |
|
171 | + * @param string $signedRequest |
|
172 | + * |
|
173 | + * @throws FacebookSDKException |
|
174 | + */ |
|
175 | + public static function validateFormat($signedRequest) |
|
176 | + { |
|
177 | 177 | if (strpos($signedRequest, '.') !== false) { |
178 | - return; |
|
178 | + return; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | throw new FacebookSDKException( |
182 | - 'Malformed signed request.', 606 |
|
182 | + 'Malformed signed request.', 606 |
|
183 | 183 | ); |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Decodes a raw valid signed request. |
|
188 | - * |
|
189 | - * @param string $signedRequest |
|
190 | - * |
|
191 | - * @returns array |
|
192 | - */ |
|
193 | - public static function split($signedRequest) |
|
194 | - { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Decodes a raw valid signed request. |
|
188 | + * |
|
189 | + * @param string $signedRequest |
|
190 | + * |
|
191 | + * @returns array |
|
192 | + */ |
|
193 | + public static function split($signedRequest) |
|
194 | + { |
|
195 | 195 | static::validateFormat($signedRequest); |
196 | 196 | |
197 | 197 | return explode('.', $signedRequest, 2); |
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Decodes the raw signature from a signed request. |
|
202 | - * |
|
203 | - * @param string $encodedSig |
|
204 | - * |
|
205 | - * @returns string |
|
206 | - * |
|
207 | - * @throws FacebookSDKException |
|
208 | - */ |
|
209 | - public static function decodeSignature($encodedSig) |
|
210 | - { |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Decodes the raw signature from a signed request. |
|
202 | + * |
|
203 | + * @param string $encodedSig |
|
204 | + * |
|
205 | + * @returns string |
|
206 | + * |
|
207 | + * @throws FacebookSDKException |
|
208 | + */ |
|
209 | + public static function decodeSignature($encodedSig) |
|
210 | + { |
|
211 | 211 | $sig = static::base64UrlDecode($encodedSig); |
212 | 212 | |
213 | 213 | if ($sig) { |
214 | - return $sig; |
|
214 | + return $sig; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | throw new FacebookSDKException( |
218 | - 'Signed request has malformed encoded signature data.', 607 |
|
218 | + 'Signed request has malformed encoded signature data.', 607 |
|
219 | 219 | ); |
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Decodes the raw payload from a signed request. |
|
224 | - * |
|
225 | - * @param string $encodedPayload |
|
226 | - * |
|
227 | - * @returns array |
|
228 | - * |
|
229 | - * @throws FacebookSDKException |
|
230 | - */ |
|
231 | - public static function decodePayload($encodedPayload) |
|
232 | - { |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Decodes the raw payload from a signed request. |
|
224 | + * |
|
225 | + * @param string $encodedPayload |
|
226 | + * |
|
227 | + * @returns array |
|
228 | + * |
|
229 | + * @throws FacebookSDKException |
|
230 | + */ |
|
231 | + public static function decodePayload($encodedPayload) |
|
232 | + { |
|
233 | 233 | $payload = static::base64UrlDecode($encodedPayload); |
234 | 234 | |
235 | 235 | if ($payload) { |
236 | - $payload = json_decode($payload, true); |
|
236 | + $payload = json_decode($payload, true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | if (is_array($payload)) { |
240 | - return $payload; |
|
240 | + return $payload; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | throw new FacebookSDKException( |
244 | - 'Signed request has malformed encoded payload data.', 607 |
|
244 | + 'Signed request has malformed encoded payload data.', 607 |
|
245 | 245 | ); |
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Validates the algorithm used in a signed request. |
|
250 | - * |
|
251 | - * @param array $data |
|
252 | - * |
|
253 | - * @throws FacebookSDKException |
|
254 | - */ |
|
255 | - public static function validateAlgorithm(array $data) |
|
256 | - { |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Validates the algorithm used in a signed request. |
|
250 | + * |
|
251 | + * @param array $data |
|
252 | + * |
|
253 | + * @throws FacebookSDKException |
|
254 | + */ |
|
255 | + public static function validateAlgorithm(array $data) |
|
256 | + { |
|
257 | 257 | if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') { |
258 | - return; |
|
258 | + return; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | throw new FacebookSDKException( |
262 | - 'Signed request is using the wrong algorithm.', 605 |
|
262 | + 'Signed request is using the wrong algorithm.', 605 |
|
263 | 263 | ); |
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Hashes the signature used in a signed request. |
|
268 | - * |
|
269 | - * @param string $encodedData |
|
270 | - * @param string|null $appSecret |
|
271 | - * |
|
272 | - * @return string |
|
273 | - * |
|
274 | - * @throws FacebookSDKException |
|
275 | - */ |
|
276 | - public static function hashSignature($encodedData, $appSecret = null) |
|
277 | - { |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Hashes the signature used in a signed request. |
|
268 | + * |
|
269 | + * @param string $encodedData |
|
270 | + * @param string|null $appSecret |
|
271 | + * |
|
272 | + * @return string |
|
273 | + * |
|
274 | + * @throws FacebookSDKException |
|
275 | + */ |
|
276 | + public static function hashSignature($encodedData, $appSecret = null) |
|
277 | + { |
|
278 | 278 | $hashedSig = hash_hmac( |
279 | - 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
279 | + 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | if ($hashedSig) { |
283 | - return $hashedSig; |
|
283 | + return $hashedSig; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | throw new FacebookSDKException( |
287 | - 'Unable to hash signature from encoded payload data.', 602 |
|
287 | + 'Unable to hash signature from encoded payload data.', 602 |
|
288 | 288 | ); |
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Validates the signature used in a signed request. |
|
293 | - * |
|
294 | - * @param string $hashedSig |
|
295 | - * @param string $sig |
|
296 | - * |
|
297 | - * @throws FacebookSDKException |
|
298 | - */ |
|
299 | - public static function validateSignature($hashedSig, $sig) |
|
300 | - { |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Validates the signature used in a signed request. |
|
293 | + * |
|
294 | + * @param string $hashedSig |
|
295 | + * @param string $sig |
|
296 | + * |
|
297 | + * @throws FacebookSDKException |
|
298 | + */ |
|
299 | + public static function validateSignature($hashedSig, $sig) |
|
300 | + { |
|
301 | 301 | if (mb_strlen($hashedSig) === mb_strlen($sig)) { |
302 | - $validate = 0; |
|
303 | - for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
302 | + $validate = 0; |
|
303 | + for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
304 | 304 | $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]); |
305 | - } |
|
306 | - if ($validate === 0) { |
|
305 | + } |
|
306 | + if ($validate === 0) { |
|
307 | 307 | return; |
308 | - } |
|
308 | + } |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | throw new FacebookSDKException( |
312 | - 'Signed request has an invalid signature.', 602 |
|
312 | + 'Signed request has an invalid signature.', 602 |
|
313 | 313 | ); |
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Validates a signed request against CSRF. |
|
318 | - * |
|
319 | - * @param array $data |
|
320 | - * @param string $state |
|
321 | - * |
|
322 | - * @throws FacebookSDKException |
|
323 | - */ |
|
324 | - public static function validateCsrf(array $data, $state) |
|
325 | - { |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Validates a signed request against CSRF. |
|
318 | + * |
|
319 | + * @param array $data |
|
320 | + * @param string $state |
|
321 | + * |
|
322 | + * @throws FacebookSDKException |
|
323 | + */ |
|
324 | + public static function validateCsrf(array $data, $state) |
|
325 | + { |
|
326 | 326 | if (isset($data['state']) && $data['state'] === $state) { |
327 | - return; |
|
327 | + return; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | throw new FacebookSDKException( |
331 | - 'Signed request did not pass CSRF validation.', 604 |
|
331 | + 'Signed request did not pass CSRF validation.', 604 |
|
332 | 332 | ); |
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Base64 decoding which replaces characters: |
|
337 | - * + instead of - |
|
338 | - * / instead of _ |
|
339 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | - * |
|
341 | - * @param string $input base64 url encoded input |
|
342 | - * |
|
343 | - * @return string decoded string |
|
344 | - */ |
|
345 | - public static function base64UrlDecode($input) |
|
346 | - { |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Base64 decoding which replaces characters: |
|
337 | + * + instead of - |
|
338 | + * / instead of _ |
|
339 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | + * |
|
341 | + * @param string $input base64 url encoded input |
|
342 | + * |
|
343 | + * @return string decoded string |
|
344 | + */ |
|
345 | + public static function base64UrlDecode($input) |
|
346 | + { |
|
347 | 347 | $urlDecodedBase64 = strtr($input, '-_', '+/'); |
348 | 348 | static::validateBase64($urlDecodedBase64); |
349 | 349 | return base64_decode($urlDecodedBase64); |
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Base64 encoding which replaces characters: |
|
354 | - * + instead of - |
|
355 | - * / instead of _ |
|
356 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | - * |
|
358 | - * @param string $input string to encode |
|
359 | - * |
|
360 | - * @return string base64 url encoded input |
|
361 | - */ |
|
362 | - public static function base64UrlEncode($input) |
|
363 | - { |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Base64 encoding which replaces characters: |
|
354 | + * + instead of - |
|
355 | + * / instead of _ |
|
356 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | + * |
|
358 | + * @param string $input string to encode |
|
359 | + * |
|
360 | + * @return string base64 url encoded input |
|
361 | + */ |
|
362 | + public static function base64UrlEncode($input) |
|
363 | + { |
|
364 | 364 | return strtr(base64_encode($input), '+/', '-_'); |
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Validates a base64 string. |
|
369 | - * |
|
370 | - * @param string $input base64 value to validate |
|
371 | - * |
|
372 | - * @throws FacebookSDKException |
|
373 | - */ |
|
374 | - public static function validateBase64($input) |
|
375 | - { |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Validates a base64 string. |
|
369 | + * |
|
370 | + * @param string $input base64 value to validate |
|
371 | + * |
|
372 | + * @throws FacebookSDKException |
|
373 | + */ |
|
374 | + public static function validateBase64($input) |
|
375 | + { |
|
376 | 376 | $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/'; |
377 | 377 | if (preg_match($pattern, $input)) { |
378 | - return; |
|
378 | + return; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | throw new FacebookSDKException( |
382 | - 'Signed request contains malformed base64 encoding.', 608 |
|
382 | + 'Signed request contains malformed base64 encoding.', 608 |
|
383 | 383 | ); |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | } |
@@ -35,120 +35,120 @@ discard block |
||
35 | 35 | class AccessToken |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * The access token. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $accessToken; |
|
44 | - |
|
45 | - /** |
|
46 | - * A unique ID to identify a client. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $machineId; |
|
51 | - |
|
52 | - /** |
|
53 | - * Date when token expires. |
|
54 | - * |
|
55 | - * @var \DateTime|null |
|
56 | - */ |
|
57 | - protected $expiresAt; |
|
58 | - |
|
59 | - /** |
|
60 | - * Create a new access token entity. |
|
61 | - * |
|
62 | - * @param string $accessToken |
|
63 | - * @param int $expiresAt |
|
64 | - * @param string|null machineId |
|
65 | - * @param string $machineId |
|
66 | - */ |
|
67 | - public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
68 | - { |
|
38 | + /** |
|
39 | + * The access token. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $accessToken; |
|
44 | + |
|
45 | + /** |
|
46 | + * A unique ID to identify a client. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $machineId; |
|
51 | + |
|
52 | + /** |
|
53 | + * Date when token expires. |
|
54 | + * |
|
55 | + * @var \DateTime|null |
|
56 | + */ |
|
57 | + protected $expiresAt; |
|
58 | + |
|
59 | + /** |
|
60 | + * Create a new access token entity. |
|
61 | + * |
|
62 | + * @param string $accessToken |
|
63 | + * @param int $expiresAt |
|
64 | + * @param string|null machineId |
|
65 | + * @param string $machineId |
|
66 | + */ |
|
67 | + public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
68 | + { |
|
69 | 69 | $this->accessToken = $accessToken; |
70 | 70 | if ($expiresAt) { |
71 | - $this->setExpiresAtFromTimeStamp($expiresAt); |
|
71 | + $this->setExpiresAtFromTimeStamp($expiresAt); |
|
72 | 72 | } |
73 | 73 | $this->machineId = $machineId; |
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Setter for expires_at. |
|
78 | - * |
|
79 | - * @param int $timeStamp |
|
80 | - */ |
|
81 | - protected function setExpiresAtFromTimeStamp($timeStamp) |
|
82 | - { |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Setter for expires_at. |
|
78 | + * |
|
79 | + * @param int $timeStamp |
|
80 | + */ |
|
81 | + protected function setExpiresAtFromTimeStamp($timeStamp) |
|
82 | + { |
|
83 | 83 | $dt = new \DateTime(); |
84 | 84 | $dt->setTimestamp($timeStamp); |
85 | 85 | $this->expiresAt = $dt; |
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Getter for expiresAt. |
|
90 | - * |
|
91 | - * @return \DateTime|null |
|
92 | - */ |
|
93 | - public function getExpiresAt() |
|
94 | - { |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Getter for expiresAt. |
|
90 | + * |
|
91 | + * @return \DateTime|null |
|
92 | + */ |
|
93 | + public function getExpiresAt() |
|
94 | + { |
|
95 | 95 | return $this->expiresAt; |
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Getter for machineId. |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function getMachineId() |
|
104 | - { |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Getter for machineId. |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function getMachineId() |
|
104 | + { |
|
105 | 105 | return $this->machineId; |
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Determines whether or not this is a long-lived token. |
|
110 | - * |
|
111 | - * @return bool |
|
112 | - */ |
|
113 | - public function isLongLived() |
|
114 | - { |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Determines whether or not this is a long-lived token. |
|
110 | + * |
|
111 | + * @return bool |
|
112 | + */ |
|
113 | + public function isLongLived() |
|
114 | + { |
|
115 | 115 | if ($this->expiresAt) { |
116 | - return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
116 | + return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
117 | 117 | } |
118 | 118 | return false; |
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Checks the validity of the access token. |
|
123 | - * |
|
124 | - * @param string|null $appId Application ID to use |
|
125 | - * @param string|null $appSecret App secret value to use |
|
126 | - * @param string|null $machineId |
|
127 | - * |
|
128 | - * @return boolean |
|
129 | - */ |
|
130 | - public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
131 | - { |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Checks the validity of the access token. |
|
123 | + * |
|
124 | + * @param string|null $appId Application ID to use |
|
125 | + * @param string|null $appSecret App secret value to use |
|
126 | + * @param string|null $machineId |
|
127 | + * |
|
128 | + * @return boolean |
|
129 | + */ |
|
130 | + public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
131 | + { |
|
132 | 132 | $accessTokenInfo = $this->getInfo($appId, $appSecret); |
133 | 133 | $machineId = $machineId ?: $this->machineId; |
134 | 134 | return static::validateAccessToken($accessTokenInfo, $appId, $machineId); |
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Ensures the provided GraphSessionInfo object is valid, |
|
139 | - * throwing an exception if not. Ensures the appId matches, |
|
140 | - * that the machineId matches if it's being used, |
|
141 | - * that the token is valid and has not expired. |
|
142 | - * |
|
143 | - * @param GraphSessionInfo $tokenInfo |
|
144 | - * @param string|null $appId Application ID to use |
|
145 | - * @param string|null $machineId |
|
146 | - * |
|
147 | - * @return boolean |
|
148 | - */ |
|
149 | - public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
150 | - $appId = null, $machineId = null) |
|
151 | - { |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Ensures the provided GraphSessionInfo object is valid, |
|
139 | + * throwing an exception if not. Ensures the appId matches, |
|
140 | + * that the machineId matches if it's being used, |
|
141 | + * that the token is valid and has not expired. |
|
142 | + * |
|
143 | + * @param GraphSessionInfo $tokenInfo |
|
144 | + * @param string|null $appId Application ID to use |
|
145 | + * @param string|null $machineId |
|
146 | + * |
|
147 | + * @return boolean |
|
148 | + */ |
|
149 | + public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
150 | + $appId = null, $machineId = null) |
|
151 | + { |
|
152 | 152 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
153 | 153 | |
154 | 154 | $appIdIsValid = $tokenInfo->getAppId() == $targetAppId; |
@@ -157,90 +157,90 @@ discard block |
||
157 | 157 | |
158 | 158 | // Not all access tokens return an expiration. E.g. an app access token. |
159 | 159 | if ($tokenInfo->getExpiresAt() instanceof \DateTime) { |
160 | - $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
160 | + $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
161 | 161 | } else { |
162 | - $accessTokenIsStillAlive = true; |
|
162 | + $accessTokenIsStillAlive = true; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive; |
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Get a valid access token from a code. |
|
170 | - * |
|
171 | - * @param string $code |
|
172 | - * @param string|null $appId |
|
173 | - * @param string|null $appSecret |
|
174 | - * @param string|null $machineId |
|
175 | - * |
|
176 | - * @return AccessToken |
|
177 | - */ |
|
178 | - public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
179 | - { |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Get a valid access token from a code. |
|
170 | + * |
|
171 | + * @param string $code |
|
172 | + * @param string|null $appId |
|
173 | + * @param string|null $appSecret |
|
174 | + * @param string|null $machineId |
|
175 | + * |
|
176 | + * @return AccessToken |
|
177 | + */ |
|
178 | + public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
179 | + { |
|
180 | 180 | $params = array( |
181 | - 'code' => $code, |
|
182 | - 'redirect_uri' => '', |
|
181 | + 'code' => $code, |
|
182 | + 'redirect_uri' => '', |
|
183 | 183 | ); |
184 | 184 | |
185 | 185 | if ($machineId) { |
186 | - $params['machine_id'] = $machineId; |
|
186 | + $params['machine_id'] = $machineId; |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | return static::requestAccessToken($params, $appId, $appSecret); |
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Get a valid code from an access token. |
|
194 | - * |
|
195 | - * @param AccessToken $accessToken |
|
196 | - * @param string|null $appId |
|
197 | - * @param string|null $appSecret |
|
198 | - * |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
202 | - { |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Get a valid code from an access token. |
|
194 | + * |
|
195 | + * @param AccessToken $accessToken |
|
196 | + * @param string|null $appId |
|
197 | + * @param string|null $appSecret |
|
198 | + * |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
202 | + { |
|
203 | 203 | $accessToken = (string) $accessToken; |
204 | 204 | |
205 | 205 | $params = array( |
206 | - 'access_token' => $accessToken, |
|
207 | - 'redirect_uri' => '', |
|
206 | + 'access_token' => $accessToken, |
|
207 | + 'redirect_uri' => '', |
|
208 | 208 | ); |
209 | 209 | |
210 | 210 | return static::requestCode($params, $appId, $appSecret); |
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * Exchanges a short lived access token with a long lived access token. |
|
215 | - * |
|
216 | - * @param string|null $appId |
|
217 | - * @param string|null $appSecret |
|
218 | - * |
|
219 | - * @return AccessToken |
|
220 | - */ |
|
221 | - public function extend($appId = null, $appSecret = null) |
|
222 | - { |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * Exchanges a short lived access token with a long lived access token. |
|
215 | + * |
|
216 | + * @param string|null $appId |
|
217 | + * @param string|null $appSecret |
|
218 | + * |
|
219 | + * @return AccessToken |
|
220 | + */ |
|
221 | + public function extend($appId = null, $appSecret = null) |
|
222 | + { |
|
223 | 223 | $params = array( |
224 | - 'grant_type' => 'fb_exchange_token', |
|
225 | - 'fb_exchange_token' => $this->accessToken, |
|
224 | + 'grant_type' => 'fb_exchange_token', |
|
225 | + 'fb_exchange_token' => $this->accessToken, |
|
226 | 226 | ); |
227 | 227 | |
228 | 228 | return static::requestAccessToken($params, $appId, $appSecret); |
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Request an access token based on a set of params. |
|
233 | - * |
|
234 | - * @param array $params |
|
235 | - * @param string|null $appId |
|
236 | - * @param string|null $appSecret |
|
237 | - * |
|
238 | - * @return AccessToken |
|
239 | - * |
|
240 | - * @throws FacebookRequestException |
|
241 | - */ |
|
242 | - public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
243 | - { |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Request an access token based on a set of params. |
|
233 | + * |
|
234 | + * @param array $params |
|
235 | + * @param string|null $appId |
|
236 | + * @param string|null $appSecret |
|
237 | + * |
|
238 | + * @return AccessToken |
|
239 | + * |
|
240 | + * @throws FacebookRequestException |
|
241 | + */ |
|
242 | + public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
243 | + { |
|
244 | 244 | $response = static::request('/oauth/access_token', $params, $appId, $appSecret); |
245 | 245 | $data = $response->getResponse(); |
246 | 246 | |
@@ -249,133 +249,133 @@ discard block |
||
249 | 249 | * @see https://github.com/facebook/facebook-php-sdk-v4/issues/36 |
250 | 250 | */ |
251 | 251 | if (is_array($data)) { |
252 | - if (isset($data['access_token'])) { |
|
252 | + if (isset($data['access_token'])) { |
|
253 | 253 | $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0; |
254 | 254 | return new static($data['access_token'], $expiresAt); |
255 | - } |
|
255 | + } |
|
256 | 256 | } elseif($data instanceof \stdClass) { |
257 | - if (isset($data->access_token)) { |
|
257 | + if (isset($data->access_token)) { |
|
258 | 258 | $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0; |
259 | 259 | $machineId = isset($data->machine_id) ? (string) $data->machine_id : null; |
260 | 260 | return new static((string) $data->access_token, $expiresAt, $machineId); |
261 | - } |
|
261 | + } |
|
262 | 262 | } |
263 | 263 | |
264 | 264 | throw FacebookRequestException::create( |
265 | - $response->getRawResponse(), |
|
266 | - $data, |
|
267 | - 401 |
|
265 | + $response->getRawResponse(), |
|
266 | + $data, |
|
267 | + 401 |
|
268 | 268 | ); |
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Request a code from a long lived access token. |
|
273 | - * |
|
274 | - * @param array $params |
|
275 | - * @param string|null $appId |
|
276 | - * @param string|null $appSecret |
|
277 | - * |
|
278 | - * @return string |
|
279 | - * |
|
280 | - * @throws FacebookRequestException |
|
281 | - */ |
|
282 | - public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
283 | - { |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Request a code from a long lived access token. |
|
273 | + * |
|
274 | + * @param array $params |
|
275 | + * @param string|null $appId |
|
276 | + * @param string|null $appSecret |
|
277 | + * |
|
278 | + * @return string |
|
279 | + * |
|
280 | + * @throws FacebookRequestException |
|
281 | + */ |
|
282 | + public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
283 | + { |
|
284 | 284 | $response = static::request('/oauth/client_code', $params, $appId, $appSecret); |
285 | 285 | $data = $response->getResponse(); |
286 | 286 | |
287 | 287 | if (isset($data->code)) { |
288 | - return (string) $data->code; |
|
288 | + return (string) $data->code; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | throw FacebookRequestException::create( |
292 | - $response->getRawResponse(), |
|
293 | - $data, |
|
294 | - 401 |
|
292 | + $response->getRawResponse(), |
|
293 | + $data, |
|
294 | + 401 |
|
295 | 295 | ); |
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Send a request to Graph with an app access token. |
|
300 | - * |
|
301 | - * @param string $endpoint |
|
302 | - * @param array $params |
|
303 | - * @param string|null $appId |
|
304 | - * @param string|null $appSecret |
|
305 | - * |
|
306 | - * @return \Facebook\FacebookResponse |
|
307 | - * |
|
308 | - * @throws FacebookRequestException |
|
309 | - */ |
|
310 | - protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
311 | - { |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Send a request to Graph with an app access token. |
|
300 | + * |
|
301 | + * @param string $endpoint |
|
302 | + * @param array $params |
|
303 | + * @param string|null $appId |
|
304 | + * @param string|null $appSecret |
|
305 | + * |
|
306 | + * @return \Facebook\FacebookResponse |
|
307 | + * |
|
308 | + * @throws FacebookRequestException |
|
309 | + */ |
|
310 | + protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
311 | + { |
|
312 | 312 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
313 | 313 | $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret); |
314 | 314 | |
315 | 315 | if (!isset($params['client_id'])) { |
316 | - $params['client_id'] = $targetAppId; |
|
316 | + $params['client_id'] = $targetAppId; |
|
317 | 317 | } |
318 | 318 | if (!isset($params['client_secret'])) { |
319 | - $params['client_secret'] = $targetAppSecret; |
|
319 | + $params['client_secret'] = $targetAppSecret; |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | // The response for this endpoint is not JSON, so it must be handled |
323 | 323 | // differently, not as a GraphObject. |
324 | 324 | $request = new FacebookRequest( |
325 | - FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
326 | - 'GET', |
|
327 | - $endpoint, |
|
328 | - $params |
|
325 | + FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
326 | + 'GET', |
|
327 | + $endpoint, |
|
328 | + $params |
|
329 | 329 | ); |
330 | 330 | return $request->execute(); |
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Get more info about an access token. |
|
335 | - * |
|
336 | - * @param string|null $appId |
|
337 | - * @param string|null $appSecret |
|
338 | - * |
|
339 | - * @return GraphSessionInfo |
|
340 | - */ |
|
341 | - public function getInfo($appId = null, $appSecret = null) |
|
342 | - { |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Get more info about an access token. |
|
335 | + * |
|
336 | + * @param string|null $appId |
|
337 | + * @param string|null $appSecret |
|
338 | + * |
|
339 | + * @return GraphSessionInfo |
|
340 | + */ |
|
341 | + public function getInfo($appId = null, $appSecret = null) |
|
342 | + { |
|
343 | 343 | $params = array('input_token' => $this->accessToken); |
344 | 344 | |
345 | 345 | $request = new FacebookRequest( |
346 | - FacebookSession::newAppSession($appId, $appSecret), |
|
347 | - 'GET', |
|
348 | - '/debug_token', |
|
349 | - $params |
|
346 | + FacebookSession::newAppSession($appId, $appSecret), |
|
347 | + 'GET', |
|
348 | + '/debug_token', |
|
349 | + $params |
|
350 | 350 | ); |
351 | 351 | $response = $request->execute()->getGraphObject(GraphSessionInfo::className()); |
352 | 352 | |
353 | 353 | // Update the data on this token |
354 | 354 | if ($response->getExpiresAt()) { |
355 | - $this->expiresAt = $response->getExpiresAt(); |
|
355 | + $this->expiresAt = $response->getExpiresAt(); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | return $response; |
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Returns the access token as a string. |
|
363 | - * |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public function __toString() |
|
367 | - { |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Returns the access token as a string. |
|
363 | + * |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public function __toString() |
|
367 | + { |
|
368 | 368 | return $this->accessToken; |
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Returns true if the access token is an app session token. |
|
373 | - * |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - public function isAppSession() |
|
377 | - { |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Returns true if the access token is an app session token. |
|
373 | + * |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + public function isAppSession() |
|
377 | + { |
|
378 | 378 | return strpos($this->accessToken, "|") !== false; |
379 | - } |
|
379 | + } |
|
380 | 380 | |
381 | 381 | } |
@@ -17,25 +17,25 @@ discard block |
||
17 | 17 | */ |
18 | 18 | class ExerciseShowFunctions |
19 | 19 | { |
20 | - /** |
|
21 | - * Shows the answer to a fill-in-the-blanks question, as HTML |
|
20 | + /** |
|
21 | + * Shows the answer to a fill-in-the-blanks question, as HTML |
|
22 | 22 | * @param int $feedbackType |
23 | - * @param string $answer |
|
24 | - * @param int $id Exercise ID |
|
25 | - * @param int $questionId Question ID |
|
23 | + * @param string $answer |
|
24 | + * @param int $id Exercise ID |
|
25 | + * @param int $questionId Question ID |
|
26 | 26 | * @param int $resultsDisabled |
27 | 27 | * @param string $originalStudentAnswer |
28 | - * |
|
29 | - * @return void |
|
30 | - */ |
|
31 | - public static function display_fill_in_blanks_answer( |
|
32 | - $feedbackType, |
|
33 | - $answer, |
|
34 | - $id, |
|
35 | - $questionId, |
|
36 | - $resultsDisabled, |
|
37 | - $originalStudentAnswer = '', |
|
38 | - $showTotalScoreAndUserChoices |
|
28 | + * |
|
29 | + * @return void |
|
30 | + */ |
|
31 | + public static function display_fill_in_blanks_answer( |
|
32 | + $feedbackType, |
|
33 | + $answer, |
|
34 | + $id, |
|
35 | + $questionId, |
|
36 | + $resultsDisabled, |
|
37 | + $originalStudentAnswer = '', |
|
38 | + $showTotalScoreAndUserChoices |
|
39 | 39 | ) { |
40 | 40 | $answerHTML = FillBlanks::getHtmlDisplayForAnswer($answer, $resultsDisabled, $showTotalScoreAndUserChoices); |
41 | 41 | if (strpos($originalStudentAnswer, 'font color') !== false) { |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | </tr> |
65 | 65 | <?php |
66 | 66 | } |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | 69 | /** |
70 | 70 | * Shows the answer to a calculated question, as HTML |
@@ -105,20 +105,20 @@ discard block |
||
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | - /** |
|
109 | - * Shows the answer to a free-answer question, as HTML |
|
110 | - * @param string Answer text |
|
111 | - * @param int Exercise ID |
|
112 | - * @param int Question ID |
|
113 | - * @return void |
|
114 | - */ |
|
115 | - public static function display_free_answer( |
|
116 | - $feedback_type, |
|
117 | - $answer, |
|
118 | - $exe_id, |
|
119 | - $questionId, |
|
120 | - $questionScore = null, |
|
121 | - $results_disabled = 0 |
|
108 | + /** |
|
109 | + * Shows the answer to a free-answer question, as HTML |
|
110 | + * @param string Answer text |
|
111 | + * @param int Exercise ID |
|
112 | + * @param int Question ID |
|
113 | + * @return void |
|
114 | + */ |
|
115 | + public static function display_free_answer( |
|
116 | + $feedback_type, |
|
117 | + $answer, |
|
118 | + $exe_id, |
|
119 | + $questionId, |
|
120 | + $questionScore = null, |
|
121 | + $results_disabled = 0 |
|
122 | 122 | ) { |
123 | 123 | $comments = Event::get_comments($exe_id, $questionId); |
124 | 124 | |
@@ -136,21 +136,21 @@ discard block |
||
136 | 136 | echo '</tr>'; |
137 | 137 | } |
138 | 138 | } |
139 | - } |
|
139 | + } |
|
140 | 140 | |
141 | 141 | /** |
142 | - * @param $feedback_type |
|
143 | - * @param $answer |
|
144 | - * @param $id |
|
145 | - * @param $questionId |
|
146 | - * @param null $nano |
|
147 | - * @param int $results_disabled |
|
142 | + * @param $feedback_type |
|
143 | + * @param $answer |
|
144 | + * @param $id |
|
145 | + * @param $questionId |
|
146 | + * @param null $nano |
|
147 | + * @param int $results_disabled |
|
148 | 148 | */ |
149 | - public static function display_oral_expression_answer( |
|
150 | - $feedback_type, |
|
151 | - $answer, |
|
152 | - $id, |
|
153 | - $questionId, |
|
149 | + public static function display_oral_expression_answer( |
|
150 | + $feedback_type, |
|
151 | + $answer, |
|
152 | + $id, |
|
153 | + $questionId, |
|
154 | 154 | $nano = null, |
155 | 155 | $results_disabled = 0 |
156 | 156 | ) { |
@@ -186,8 +186,8 @@ discard block |
||
186 | 186 | } |
187 | 187 | } |
188 | 188 | |
189 | - /** |
|
190 | - * Displays the answer to a hotspot question |
|
189 | + /** |
|
190 | + * Displays the answer to a hotspot question |
|
191 | 191 | * @param int $feedback_type |
192 | 192 | * @param int $answerId |
193 | 193 | * @param string $answer |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | * @param int $resultsDisabled |
197 | 197 | * @param int $orderColor |
198 | 198 | */ |
199 | - public static function display_hotspot_answer( |
|
199 | + public static function display_hotspot_answer( |
|
200 | 200 | $feedback_type, |
201 | 201 | $answerId, |
202 | 202 | $answer, |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | - $hotspot_colors = array( |
|
222 | + $hotspot_colors = array( |
|
223 | 223 | "", // $i starts from 1 on next loop (ugly fix) |
224 | 224 | "#4271B5", |
225 | 225 | "#FE8E16", |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | "#F7BDE2" |
237 | 237 | ); |
238 | 238 | |
239 | - ?> |
|
239 | + ?> |
|
240 | 240 | <table class="data_table"> |
241 | 241 | <tr> |
242 | 242 | <td class="text-center" width="5%"> |
@@ -248,10 +248,10 @@ discard block |
||
248 | 248 | <td class="text-left" width="10%"> |
249 | 249 | <?php |
250 | 250 | if (!$hide_expected_answer) { |
251 | - $my_choice = $studentChoice ? get_lang('Correct') : get_lang('Fault'); |
|
252 | - echo $my_choice; |
|
251 | + $my_choice = $studentChoice ? get_lang('Correct') : get_lang('Fault'); |
|
252 | + echo $my_choice; |
|
253 | 253 | } |
254 | - ?> |
|
254 | + ?> |
|
255 | 255 | </td> |
256 | 256 | <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?> |
257 | 257 | <td class="text-left" width="60%"> |
@@ -259,29 +259,29 @@ discard block |
||
259 | 259 | if ($studentChoice) { |
260 | 260 | echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>'; |
261 | 261 | } |
262 | - ?> |
|
262 | + ?> |
|
263 | 263 | </td> |
264 | 264 | <?php } else { ?> |
265 | 265 | <td class="text-left" width="60%"> </td> |
266 | 266 | <?php } ?> |
267 | 267 | </tr> |
268 | 268 | <?php |
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Display the answers to a multiple choice question |
|
273 | - * @param int $feedback_type Feedback type |
|
274 | - * @param integer Answer type |
|
275 | - * @param integer Student choice |
|
276 | - * @param string Textual answer |
|
277 | - * @param string Comment on answer |
|
278 | - * @param string Correct answer comment |
|
279 | - * @param integer Exercise ID |
|
280 | - * @param integer Question ID |
|
281 | - * @param boolean Whether to show the answer comment or not |
|
282 | - * @return void |
|
283 | - */ |
|
284 | - public static function display_unique_or_multiple_answer( |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Display the answers to a multiple choice question |
|
273 | + * @param int $feedback_type Feedback type |
|
274 | + * @param integer Answer type |
|
275 | + * @param integer Student choice |
|
276 | + * @param string Textual answer |
|
277 | + * @param string Comment on answer |
|
278 | + * @param string Correct answer comment |
|
279 | + * @param integer Exercise ID |
|
280 | + * @param integer Question ID |
|
281 | + * @param boolean Whether to show the answer comment or not |
|
282 | + * @return void |
|
283 | + */ |
|
284 | + public static function display_unique_or_multiple_answer( |
|
285 | 285 | $feedback_type, |
286 | 286 | $answerType, |
287 | 287 | $studentChoice, |
@@ -309,14 +309,14 @@ discard block |
||
309 | 309 | } |
310 | 310 | |
311 | 311 | $icon = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox'; |
312 | - $icon .= $studentChoice?'_on':'_off'; |
|
313 | - $icon .= '.gif'; |
|
312 | + $icon .= $studentChoice?'_on':'_off'; |
|
313 | + $icon .= '.gif'; |
|
314 | 314 | |
315 | - $iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox'; |
|
316 | - $iconAnswer .= $answerCorrect ? '_on' : '_off'; |
|
317 | - $iconAnswer .= '.gif'; |
|
315 | + $iconAnswer = in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_NO_OPTION)) ? 'radio':'checkbox'; |
|
316 | + $iconAnswer .= $answerCorrect ? '_on' : '_off'; |
|
317 | + $iconAnswer .= '.gif'; |
|
318 | 318 | |
319 | - ?> |
|
319 | + ?> |
|
320 | 320 | <tr> |
321 | 321 | <td width="5%"> |
322 | 322 | <?php echo Display::return_icon($icon); ?> |
@@ -330,39 +330,39 @@ discard block |
||
330 | 330 | </td> |
331 | 331 | <td width="40%"> |
332 | 332 | <?php |
333 | - echo $answer; |
|
334 | - ?> |
|
333 | + echo $answer; |
|
334 | + ?> |
|
335 | 335 | </td> |
336 | 336 | |
337 | 337 | <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?> |
338 | 338 | <td width="20%"> |
339 | 339 | <?php |
340 | 340 | if ($studentChoice) { |
341 | - if ($answerCorrect) { |
|
341 | + if ($answerCorrect) { |
|
342 | 342 | $color = 'green'; |
343 | - //echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>'; |
|
344 | - } else { |
|
343 | + //echo '<span style="font-weight: bold; color: #008000;">'.nl2br($answerComment).'</span>'; |
|
344 | + } else { |
|
345 | 345 | $color = 'black'; |
346 | 346 | //echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br($answerComment).'</span>'; |
347 | - } |
|
348 | - if ($hide_expected_answer) { |
|
349 | - $color = ''; |
|
350 | - } |
|
347 | + } |
|
348 | + if ($hide_expected_answer) { |
|
349 | + $color = ''; |
|
350 | + } |
|
351 | 351 | echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>'; |
352 | - } |
|
353 | - ?> |
|
352 | + } |
|
353 | + ?> |
|
354 | 354 | </td> |
355 | 355 | <?php |
356 | - if ($ans==1) { |
|
357 | - $comm = Event::get_comments($id,$questionId); |
|
358 | - } |
|
359 | - ?> |
|
356 | + if ($ans==1) { |
|
357 | + $comm = Event::get_comments($id,$questionId); |
|
358 | + } |
|
359 | + ?> |
|
360 | 360 | <?php } else { ?> |
361 | 361 | <td> </td> |
362 | 362 | <?php } ?> |
363 | 363 | </tr> |
364 | 364 | <?php |
365 | - } |
|
365 | + } |
|
366 | 366 | |
367 | 367 | /** |
368 | 368 | * Display the answers to a multiple choice question |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | if (isset($new_options[$studentChoice])) { |
416 | 416 | echo get_lang($new_options[$studentChoice]['name']); |
417 | 417 | } else { |
418 | - echo '-'; |
|
418 | + echo '-'; |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | ?> |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | <td width="5%"> |
424 | 424 | <?php |
425 | 425 | |
426 | - // Expected choice |
|
426 | + // Expected choice |
|
427 | 427 | if (!$hide_expected_answer) { |
428 | 428 | if (isset($new_options[$answerCorrect])) { |
429 | 429 | echo get_lang($new_options[$answerCorrect]['name']); |
@@ -449,8 +449,8 @@ discard block |
||
449 | 449 | } |
450 | 450 | |
451 | 451 | if ($hide_expected_answer) { |
452 | - $color = ''; |
|
453 | - } |
|
452 | + $color = ''; |
|
453 | + } |
|
454 | 454 | |
455 | 455 | echo '<span style="font-weight: bold; color: '.$color.';">'.nl2br($answerComment).'</span>'; |
456 | 456 | } |
@@ -468,19 +468,19 @@ discard block |
||
468 | 468 | <?php |
469 | 469 | } |
470 | 470 | |
471 | - /** |
|
472 | - * Display the answers to a multiple choice question |
|
473 | - * |
|
474 | - * @param integer Answer type |
|
475 | - * @param integer Student choice |
|
476 | - * @param string Textual answer |
|
477 | - * @param string Comment on answer |
|
478 | - * @param string Correct answer comment |
|
479 | - * @param integer Exercise ID |
|
480 | - * @param integer Question ID |
|
481 | - * @param boolean Whether to show the answer comment or not |
|
482 | - * @return void |
|
483 | - */ |
|
471 | + /** |
|
472 | + * Display the answers to a multiple choice question |
|
473 | + * |
|
474 | + * @param integer Answer type |
|
475 | + * @param integer Student choice |
|
476 | + * @param string Textual answer |
|
477 | + * @param string Comment on answer |
|
478 | + * @param string Correct answer comment |
|
479 | + * @param integer Exercise ID |
|
480 | + * @param integer Question ID |
|
481 | + * @param boolean Whether to show the answer comment or not |
|
482 | + * @return void |
|
483 | + */ |
|
484 | 484 | public static function display_multiple_answer_combination_true_false( |
485 | 485 | $feedback_type, |
486 | 486 | $answerType, |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | <tr> |
512 | 512 | <td width="5%"> |
513 | 513 | <?php |
514 | - //Your choice |
|
514 | + //Your choice |
|
515 | 515 | $question = new MultipleAnswerCombinationTrueFalse(); |
516 | 516 | if (isset($question->options[$studentChoice])) { |
517 | 517 | echo $question->options[$studentChoice]; |
@@ -522,7 +522,7 @@ discard block |
||
522 | 522 | </td> |
523 | 523 | <td width="5%"> |
524 | 524 | <?php |
525 | - // Expected choice |
|
525 | + // Expected choice |
|
526 | 526 | if (!$hide_expected_answer) { |
527 | 527 | if (isset($question->options[$answerCorrect])) { |
528 | 528 | echo $question->options[$answerCorrect]; |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | <?php |
548 | 548 | //@todo replace this harcoded value |
549 | 549 | if ($studentChoice) { |
550 | - $color = "black"; |
|
550 | + $color = "black"; |
|
551 | 551 | if ($studentChoice == $answerCorrect) { |
552 | 552 | $color = "green"; |
553 | 553 | } |
@@ -10,133 +10,133 @@ |
||
10 | 10 | */ |
11 | 11 | class LinkForm extends FormValidator |
12 | 12 | { |
13 | - const TYPE_CREATE = 1; |
|
14 | - const TYPE_MOVE = 2; |
|
15 | - /** @var Category */ |
|
16 | - private $category_object; |
|
17 | - private $link_object; |
|
18 | - private $extra; |
|
13 | + const TYPE_CREATE = 1; |
|
14 | + const TYPE_MOVE = 2; |
|
15 | + /** @var Category */ |
|
16 | + private $category_object; |
|
17 | + private $link_object; |
|
18 | + private $extra; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Builds a form containing form items based on a given parameter |
|
22 | - * @param int form_type 1=choose link |
|
23 | - * @param obj cat_obj the category object |
|
24 | - * @param string form name |
|
25 | - * @param method |
|
26 | - * @param action |
|
27 | - */ |
|
28 | - public function LinkForm( |
|
29 | - $form_type, |
|
30 | - $category_object, |
|
31 | - $link_object, |
|
32 | - $form_name, |
|
33 | - $method = 'post', |
|
34 | - $action = null, |
|
35 | - $extra = null |
|
36 | - ) { |
|
37 | - parent :: __construct($form_name, $method, $action); |
|
20 | + /** |
|
21 | + * Builds a form containing form items based on a given parameter |
|
22 | + * @param int form_type 1=choose link |
|
23 | + * @param obj cat_obj the category object |
|
24 | + * @param string form name |
|
25 | + * @param method |
|
26 | + * @param action |
|
27 | + */ |
|
28 | + public function LinkForm( |
|
29 | + $form_type, |
|
30 | + $category_object, |
|
31 | + $link_object, |
|
32 | + $form_name, |
|
33 | + $method = 'post', |
|
34 | + $action = null, |
|
35 | + $extra = null |
|
36 | + ) { |
|
37 | + parent :: __construct($form_name, $method, $action); |
|
38 | 38 | |
39 | - if (isset ($category_object)) { |
|
40 | - $this->category_object = $category_object; |
|
41 | - } else { |
|
42 | - if (isset($link_object)) { |
|
43 | - $this->link_object = $link_object; |
|
44 | - } |
|
45 | - } |
|
39 | + if (isset ($category_object)) { |
|
40 | + $this->category_object = $category_object; |
|
41 | + } else { |
|
42 | + if (isset($link_object)) { |
|
43 | + $this->link_object = $link_object; |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | - if (isset ($extra)) { |
|
48 | - $this->extra = $extra; |
|
49 | - } |
|
50 | - if ($form_type == self :: TYPE_CREATE) { |
|
51 | - $this->build_create(); |
|
52 | - } elseif ($form_type == self :: TYPE_MOVE) { |
|
53 | - $this->build_move(); |
|
54 | - } |
|
55 | - } |
|
47 | + if (isset ($extra)) { |
|
48 | + $this->extra = $extra; |
|
49 | + } |
|
50 | + if ($form_type == self :: TYPE_CREATE) { |
|
51 | + $this->build_create(); |
|
52 | + } elseif ($form_type == self :: TYPE_MOVE) { |
|
53 | + $this->build_move(); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - protected function build_move() |
|
58 | - { |
|
59 | - $renderer =& $this->defaultRenderer(); |
|
60 | - $renderer->setCustomElementTemplate('<span>{element}</span> '); |
|
61 | - $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" '); |
|
62 | - $this->addElement('static',null,null,get_lang('MoveTo').' : '); |
|
63 | - $select = $this->addElement('select','move_cat',null,null); |
|
64 | - $line = ''; |
|
65 | - foreach ($this->link_object->get_target_categories() as $cat) { |
|
66 | - for ($i=0;$i<$cat[2];$i++) { |
|
67 | - $line .= '—'; |
|
68 | - } |
|
69 | - $select->addoption($line.' '.$cat[1],$cat[0]); |
|
70 | - $line = ''; |
|
71 | - } |
|
72 | - $this->addElement('submit', null, get_lang('Ok')); |
|
73 | - } |
|
57 | + protected function build_move() |
|
58 | + { |
|
59 | + $renderer =& $this->defaultRenderer(); |
|
60 | + $renderer->setCustomElementTemplate('<span>{element}</span> '); |
|
61 | + $this->addElement('static',null,null,'"'.$this->link_object->get_name().'" '); |
|
62 | + $this->addElement('static',null,null,get_lang('MoveTo').' : '); |
|
63 | + $select = $this->addElement('select','move_cat',null,null); |
|
64 | + $line = ''; |
|
65 | + foreach ($this->link_object->get_target_categories() as $cat) { |
|
66 | + for ($i=0;$i<$cat[2];$i++) { |
|
67 | + $line .= '—'; |
|
68 | + } |
|
69 | + $select->addoption($line.' '.$cat[1],$cat[0]); |
|
70 | + $line = ''; |
|
71 | + } |
|
72 | + $this->addElement('submit', null, get_lang('Ok')); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Builds the form |
|
77 | - */ |
|
78 | - protected function build_create() |
|
79 | - { |
|
80 | - $this->addElement('header', get_lang('MakeLink')); |
|
81 | - $select = $this->addElement( |
|
82 | - 'select', |
|
83 | - 'select_link', |
|
84 | - get_lang('ChooseLink'), |
|
85 | - null, |
|
86 | - array('onchange' => 'document.create_link.submit()') |
|
87 | - ); |
|
75 | + /** |
|
76 | + * Builds the form |
|
77 | + */ |
|
78 | + protected function build_create() |
|
79 | + { |
|
80 | + $this->addElement('header', get_lang('MakeLink')); |
|
81 | + $select = $this->addElement( |
|
82 | + 'select', |
|
83 | + 'select_link', |
|
84 | + get_lang('ChooseLink'), |
|
85 | + null, |
|
86 | + array('onchange' => 'document.create_link.submit()') |
|
87 | + ); |
|
88 | 88 | |
89 | - $linkTypes = LinkFactory::get_all_types(); |
|
89 | + $linkTypes = LinkFactory::get_all_types(); |
|
90 | 90 | |
91 | - $select->addoption('['.get_lang('ChooseLink').']', 0); |
|
91 | + $select->addoption('['.get_lang('ChooseLink').']', 0); |
|
92 | 92 | |
93 | - $courseCode = $this->category_object->get_course_code(); |
|
93 | + $courseCode = $this->category_object->get_course_code(); |
|
94 | 94 | |
95 | - foreach ($linkTypes as $linkType) { |
|
96 | - // The hot potatoe link will be added "inside" the exercise option. |
|
97 | - if ($linkType == LINK_HOTPOTATOES) { |
|
98 | - continue; |
|
99 | - } |
|
100 | - $link = $this->createLink($linkType, $courseCode); |
|
101 | - // disable this element if the link works with a dropdownlist |
|
102 | - // and if there are no links left |
|
103 | - if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') { |
|
104 | - $select->addoption($link->get_type_name(), $linkType, 'disabled'); |
|
105 | - } else { |
|
106 | - if ($link->get_type() == LINK_EXERCISE) { |
|
107 | - // Adding exercise |
|
108 | - $select->addoption($link->get_type_name(), $linkType); |
|
109 | - // Adding hot potatoes |
|
110 | - $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode); |
|
111 | - $select->addoption( |
|
112 | - ' '.$linkHot->get_type_name(), |
|
113 | - LINK_HOTPOTATOES |
|
114 | - ); |
|
115 | - } else { |
|
116 | - $select->addoption($link->get_type_name(), $linkType); |
|
117 | - } |
|
118 | - } |
|
119 | - } |
|
95 | + foreach ($linkTypes as $linkType) { |
|
96 | + // The hot potatoe link will be added "inside" the exercise option. |
|
97 | + if ($linkType == LINK_HOTPOTATOES) { |
|
98 | + continue; |
|
99 | + } |
|
100 | + $link = $this->createLink($linkType, $courseCode); |
|
101 | + // disable this element if the link works with a dropdownlist |
|
102 | + // and if there are no links left |
|
103 | + if (!$link->needs_name_and_description() && count($link->get_all_links()) == '0') { |
|
104 | + $select->addoption($link->get_type_name(), $linkType, 'disabled'); |
|
105 | + } else { |
|
106 | + if ($link->get_type() == LINK_EXERCISE) { |
|
107 | + // Adding exercise |
|
108 | + $select->addoption($link->get_type_name(), $linkType); |
|
109 | + // Adding hot potatoes |
|
110 | + $linkHot = $this->createLink(LINK_HOTPOTATOES, $courseCode); |
|
111 | + $select->addoption( |
|
112 | + ' '.$linkHot->get_type_name(), |
|
113 | + LINK_HOTPOTATOES |
|
114 | + ); |
|
115 | + } else { |
|
116 | + $select->addoption($link->get_type_name(), $linkType); |
|
117 | + } |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | - if (isset($this->extra)) { |
|
122 | - $this->setDefaults(array('select_link' => $this->extra)); |
|
123 | - } |
|
124 | - } |
|
121 | + if (isset($this->extra)) { |
|
122 | + $this->setDefaults(array('select_link' => $this->extra)); |
|
123 | + } |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * @param integer $link |
|
128 | - * @param null|string $courseCode |
|
129 | - * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink |
|
130 | - */ |
|
131 | - private function createLink($link, $courseCode) |
|
132 | - { |
|
133 | - $link = LinkFactory::create($link); |
|
134 | - if (!empty($courseCode)) { |
|
135 | - $link->set_course_code($courseCode); |
|
136 | - } elseif(!empty($_GET['course_code'])) { |
|
137 | - $link->set_course_code(Database::escape_string($_GET['course_code'], null, false)); |
|
138 | - } |
|
126 | + /** |
|
127 | + * @param integer $link |
|
128 | + * @param null|string $courseCode |
|
129 | + * @return AttendanceLink|DropboxLink|ExerciseLink|ForumThreadLink|LearnpathLink|null|StudentPublicationLink|SurveyLink |
|
130 | + */ |
|
131 | + private function createLink($link, $courseCode) |
|
132 | + { |
|
133 | + $link = LinkFactory::create($link); |
|
134 | + if (!empty($courseCode)) { |
|
135 | + $link->set_course_code($courseCode); |
|
136 | + } elseif(!empty($_GET['course_code'])) { |
|
137 | + $link->set_course_code(Database::escape_string($_GET['course_code'], null, false)); |
|
138 | + } |
|
139 | 139 | |
140 | - return $link; |
|
141 | - } |
|
140 | + return $link; |
|
141 | + } |
|
142 | 142 | } |
@@ -10,54 +10,54 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ForumThreadLink extends AbstractLink |
12 | 12 | { |
13 | - private $forum_thread_table = null; |
|
14 | - private $itemprop_table = null; |
|
15 | - |
|
16 | - /** |
|
17 | - * Constructor |
|
18 | - */ |
|
19 | - public function __construct() |
|
20 | - { |
|
21 | - parent::__construct(); |
|
22 | - $this->set_type(LINK_FORUM_THREAD); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * @return string |
|
27 | - */ |
|
28 | - public function get_type_name() |
|
29 | - { |
|
30 | - return get_lang('ForumThreads'); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return bool |
|
35 | - */ |
|
36 | - public function is_allowed_to_change_name() |
|
37 | - { |
|
38 | - return false; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | - */ |
|
45 | - public function get_not_created_links() |
|
46 | - { |
|
47 | - if (empty($this->course_code)) { |
|
48 | - die('Error in get_not_created_links() : course code not set'); |
|
49 | - } |
|
50 | - |
|
51 | - $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | - |
|
53 | - $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | - .' forum_thread WHERE thread_id NOT IN' |
|
55 | - .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | - .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | - ." AND c_id = ".intval($this->course_id) |
|
58 | - .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | - |
|
60 | - $result = Database::query($sql); |
|
13 | + private $forum_thread_table = null; |
|
14 | + private $itemprop_table = null; |
|
15 | + |
|
16 | + /** |
|
17 | + * Constructor |
|
18 | + */ |
|
19 | + public function __construct() |
|
20 | + { |
|
21 | + parent::__construct(); |
|
22 | + $this->set_type(LINK_FORUM_THREAD); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + */ |
|
28 | + public function get_type_name() |
|
29 | + { |
|
30 | + return get_lang('ForumThreads'); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return bool |
|
35 | + */ |
|
36 | + public function is_allowed_to_change_name() |
|
37 | + { |
|
38 | + return false; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Generate an array of exercises that a teacher hasn't created a link for. |
|
43 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
44 | + */ |
|
45 | + public function get_not_created_links() |
|
46 | + { |
|
47 | + if (empty($this->course_code)) { |
|
48 | + die('Error in get_not_created_links() : course code not set'); |
|
49 | + } |
|
50 | + |
|
51 | + $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
|
52 | + |
|
53 | + $sql = 'SELECT thread_id,thread_title,thread_title_qualify FROM '.$this->get_forum_thread_table() |
|
54 | + .' forum_thread WHERE thread_id NOT IN' |
|
55 | + .' (SELECT ref_id FROM '.$tbl_grade_links |
|
56 | + .' WHERE type = '.LINK_FORUM_THREAD |
|
57 | + ." AND c_id = ".intval($this->course_id) |
|
58 | + .') AND forum_thread.session_id='.api_get_session_id().''; |
|
59 | + |
|
60 | + $result = Database::query($sql); |
|
61 | 61 | |
62 | 62 | $cats = array(); |
63 | 63 | while ($data = Database::fetch_array($result)) { |
@@ -72,29 +72,29 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | return $cats; |
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Generate an array of all exercises available. |
|
79 | - * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | - */ |
|
81 | - public function get_all_links() |
|
82 | - { |
|
83 | - if (empty($this->course_code)) { |
|
84 | - die('Error in get_not_created_links() : course code not set'); |
|
85 | - } |
|
86 | - |
|
87 | - $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | - $session_id = api_get_session_id(); |
|
90 | - |
|
91 | - if ($session_id) { |
|
92 | - $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | - } else { |
|
94 | - $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | - } |
|
96 | - |
|
97 | - $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Generate an array of all exercises available. |
|
79 | + * @return array 2-dimensional array - every element contains 2 subelements (id, name) |
|
80 | + */ |
|
81 | + public function get_all_links() |
|
82 | + { |
|
83 | + if (empty($this->course_code)) { |
|
84 | + die('Error in get_not_created_links() : course code not set'); |
|
85 | + } |
|
86 | + |
|
87 | + $tbl_grade_links = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
88 | + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY); |
|
89 | + $session_id = api_get_session_id(); |
|
90 | + |
|
91 | + if ($session_id) { |
|
92 | + $session_condition = 'tl.session_id='.api_get_session_id(); |
|
93 | + } else { |
|
94 | + $session_condition = '(tl.session_id = 0 OR tl.session_id IS NULL)'; |
|
95 | + } |
|
96 | + |
|
97 | + $sql = 'SELECT tl.thread_id, tl.thread_title, tl.thread_title_qualify |
|
98 | 98 | FROM '.$tbl_grade_links.' tl INNER JOIN '.$tbl_item_property.' ip |
99 | 99 | ON (tl.thread_id = ip.ref AND tl.c_id = ip.c_id ) |
100 | 100 | WHERE |
@@ -105,24 +105,24 @@ discard block |
||
105 | 105 | '.$session_condition.' |
106 | 106 | '; |
107 | 107 | |
108 | - $result = Database::query($sql); |
|
108 | + $result = Database::query($sql); |
|
109 | 109 | |
110 | - while ($data = Database::fetch_array($result)) { |
|
111 | - if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | - $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | - } else { |
|
114 | - $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | - } |
|
116 | - } |
|
117 | - $my_cats = isset($cats) ? $cats : null; |
|
110 | + while ($data = Database::fetch_array($result)) { |
|
111 | + if ( isset($data['thread_title_qualify']) and $data['thread_title_qualify']!=""){ |
|
112 | + $cats[] = array ($data['thread_id'], $data['thread_title_qualify']); |
|
113 | + } else { |
|
114 | + $cats[] = array ($data['thread_id'], $data['thread_title']); |
|
115 | + } |
|
116 | + } |
|
117 | + $my_cats = isset($cats) ? $cats : null; |
|
118 | 118 | |
119 | - return $my_cats; |
|
120 | - } |
|
119 | + return $my_cats; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | /** |
123 | - * Has anyone done this exercise yet ? |
|
124 | - * @return boolean |
|
125 | - */ |
|
123 | + * Has anyone done this exercise yet ? |
|
124 | + * @return boolean |
|
125 | + */ |
|
126 | 126 | public function has_results() |
127 | 127 | { |
128 | 128 | $table = Database :: get_course_table(TABLE_FORUM_POST); |
@@ -134,40 +134,40 @@ discard block |
||
134 | 134 | $number = Database::fetch_row($result); |
135 | 135 | |
136 | 136 | return $number[0] != 0; |
137 | - } |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * @param int $stud_id |
|
139 | + /** |
|
140 | + * @param int $stud_id |
|
141 | 141 | * @param string $type |
142 | 142 | * |
143 | - * @return array|null |
|
144 | - */ |
|
145 | - public function calc_score($stud_id = null, $type = null) |
|
146 | - { |
|
143 | + * @return array|null |
|
144 | + */ |
|
145 | + public function calc_score($stud_id = null, $type = null) |
|
146 | + { |
|
147 | 147 | require_once api_get_path(SYS_CODE_PATH).'forum/forumfunction.inc.php'; |
148 | 148 | $threadInfo = get_thread_information($this->get_ref_id()); |
149 | 149 | |
150 | - $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
150 | + $thread_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY); |
|
151 | 151 | |
152 | - $sql = 'SELECT thread_qualify_max |
|
152 | + $sql = 'SELECT thread_qualify_max |
|
153 | 153 | FROM '.Database :: get_course_table(TABLE_FORUM_THREAD)." |
154 | 154 | WHERE c_id = ".$this->course_id." AND thread_id = '".$this->get_ref_id()."'"; |
155 | - $query = Database::query($sql); |
|
156 | - $assignment = Database::fetch_array($query); |
|
155 | + $query = Database::query($sql); |
|
156 | + $assignment = Database::fetch_array($query); |
|
157 | 157 | |
158 | - $sql = "SELECT * FROM $thread_qualify |
|
158 | + $sql = "SELECT * FROM $thread_qualify |
|
159 | 159 | WHERE c_id = ".$this->course_id." AND thread_id = ".$this->get_ref_id(); |
160 | - if (isset($stud_id)) { |
|
161 | - $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | - } |
|
160 | + if (isset($stud_id)) { |
|
161 | + $sql .= ' AND user_id = '.intval($stud_id); |
|
162 | + } |
|
163 | 163 | |
164 | - // order by id, that way the student's first attempt is accessed first |
|
165 | - $sql .= ' ORDER BY qualify_time DESC'; |
|
164 | + // order by id, that way the student's first attempt is accessed first |
|
165 | + $sql .= ' ORDER BY qualify_time DESC'; |
|
166 | 166 | |
167 | - $scores = Database::query($sql); |
|
167 | + $scores = Database::query($sql); |
|
168 | 168 | |
169 | - // for 1 student |
|
170 | - if (isset($stud_id)) { |
|
169 | + // for 1 student |
|
170 | + if (isset($stud_id)) { |
|
171 | 171 | if ($threadInfo['thread_peer_qualify'] == 0) { |
172 | 172 | // Classic way of calculate score |
173 | 173 | if ($data = Database::fetch_array($scores)) { |
@@ -195,174 +195,174 @@ discard block |
||
195 | 195 | } |
196 | 196 | return [$score/$counter, $assignment['thread_qualify_max']]; |
197 | 197 | } |
198 | - } else { |
|
199 | - // All students -> get average |
|
200 | - $students = array(); // user list, needed to make sure we only |
|
201 | - // take first attempts into account |
|
202 | - $counter = 0; |
|
203 | - $sum = 0; |
|
204 | - $bestResult = 0; |
|
205 | - $weight = 0; |
|
206 | - $sumResult = 0; |
|
207 | - |
|
208 | - while ($data = Database::fetch_array($scores)) { |
|
209 | - if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | - if ($assignment['thread_qualify_max'] != 0) { |
|
211 | - $students[$data['user_id']] = $data['qualify']; |
|
212 | - $counter++; |
|
213 | - $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | - $sumResult += $data['qualify']; |
|
215 | - if ($data['qualify'] > $bestResult) { |
|
216 | - $bestResult = $data['qualify']; |
|
217 | - } |
|
218 | - $weight = $assignment['thread_qualify_max']; |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
222 | - |
|
223 | - if ($counter == 0) { |
|
224 | - return null; |
|
225 | - } else { |
|
226 | - switch ($type) { |
|
227 | - case 'best': |
|
228 | - return array($bestResult, $weight); |
|
229 | - break; |
|
230 | - case 'average': |
|
231 | - return array($sumResult/$counter, $weight); |
|
232 | - break; |
|
233 | - case 'ranking': |
|
234 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | - break; |
|
236 | - default: |
|
237 | - return array($sum, $counter); |
|
238 | - break; |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Lazy load function to get the database table of the student publications |
|
246 | - */ |
|
247 | - private function get_forum_thread_table() |
|
248 | - { |
|
249 | - return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | - } |
|
251 | - |
|
252 | - public function needs_name_and_description() |
|
253 | - { |
|
254 | - return false; |
|
255 | - } |
|
256 | - |
|
257 | - public function needs_max() |
|
258 | - { |
|
259 | - return false; |
|
260 | - } |
|
261 | - |
|
262 | - public function needs_results() |
|
263 | - { |
|
264 | - return false; |
|
265 | - } |
|
198 | + } else { |
|
199 | + // All students -> get average |
|
200 | + $students = array(); // user list, needed to make sure we only |
|
201 | + // take first attempts into account |
|
202 | + $counter = 0; |
|
203 | + $sum = 0; |
|
204 | + $bestResult = 0; |
|
205 | + $weight = 0; |
|
206 | + $sumResult = 0; |
|
207 | + |
|
208 | + while ($data = Database::fetch_array($scores)) { |
|
209 | + if (!(array_key_exists($data['user_id'], $students))) { |
|
210 | + if ($assignment['thread_qualify_max'] != 0) { |
|
211 | + $students[$data['user_id']] = $data['qualify']; |
|
212 | + $counter++; |
|
213 | + $sum += $data['qualify'] / $assignment['thread_qualify_max']; |
|
214 | + $sumResult += $data['qualify']; |
|
215 | + if ($data['qualify'] > $bestResult) { |
|
216 | + $bestResult = $data['qualify']; |
|
217 | + } |
|
218 | + $weight = $assignment['thread_qualify_max']; |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | + |
|
223 | + if ($counter == 0) { |
|
224 | + return null; |
|
225 | + } else { |
|
226 | + switch ($type) { |
|
227 | + case 'best': |
|
228 | + return array($bestResult, $weight); |
|
229 | + break; |
|
230 | + case 'average': |
|
231 | + return array($sumResult/$counter, $weight); |
|
232 | + break; |
|
233 | + case 'ranking': |
|
234 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
235 | + break; |
|
236 | + default: |
|
237 | + return array($sum, $counter); |
|
238 | + break; |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Lazy load function to get the database table of the student publications |
|
246 | + */ |
|
247 | + private function get_forum_thread_table() |
|
248 | + { |
|
249 | + return $this->forum_thread_table = Database :: get_course_table(TABLE_FORUM_THREAD); |
|
250 | + } |
|
251 | + |
|
252 | + public function needs_name_and_description() |
|
253 | + { |
|
254 | + return false; |
|
255 | + } |
|
256 | + |
|
257 | + public function needs_max() |
|
258 | + { |
|
259 | + return false; |
|
260 | + } |
|
261 | + |
|
262 | + public function needs_results() |
|
263 | + { |
|
264 | + return false; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | /** |
268 | 268 | * @return string |
269 | 269 | */ |
270 | - public function get_name() |
|
271 | - { |
|
272 | - $this->get_exercise_data(); |
|
273 | - $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | - $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | - if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | - return $this->exercise_data['thread_title_qualify']; |
|
277 | - } else { |
|
278 | - return $thread_title; |
|
279 | - } |
|
280 | - } |
|
270 | + public function get_name() |
|
271 | + { |
|
272 | + $this->get_exercise_data(); |
|
273 | + $thread_title=isset($this->exercise_data['thread_title']) ? $this->exercise_data['thread_title'] : ''; |
|
274 | + $thread_title_qualify=isset($this->exercise_data['thread_title_qualify']) ? $this->exercise_data['thread_title_qualify'] : ''; |
|
275 | + if ( isset($thread_title_qualify) && $thread_title_qualify!="") { |
|
276 | + return $this->exercise_data['thread_title_qualify']; |
|
277 | + } else { |
|
278 | + return $thread_title; |
|
279 | + } |
|
280 | + } |
|
281 | 281 | |
282 | 282 | /** |
283 | 283 | * @return string |
284 | 284 | */ |
285 | - public function get_description() |
|
286 | - { |
|
287 | - return '';//$this->exercise_data['description']; |
|
288 | - } |
|
289 | - |
|
290 | - /** |
|
291 | - * Check if this still links to an exercise |
|
292 | - */ |
|
293 | - public function is_valid_link() |
|
294 | - { |
|
295 | - $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
285 | + public function get_description() |
|
286 | + { |
|
287 | + return '';//$this->exercise_data['description']; |
|
288 | + } |
|
289 | + |
|
290 | + /** |
|
291 | + * Check if this still links to an exercise |
|
292 | + */ |
|
293 | + public function is_valid_link() |
|
294 | + { |
|
295 | + $sql = 'SELECT count(id) from '.$this->get_forum_thread_table().' |
|
296 | 296 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND session_id='.api_get_session_id().''; |
297 | - $result = Database::query($sql); |
|
298 | - $number = Database::fetch_row($result); |
|
299 | - return ($number[0] != 0); |
|
300 | - } |
|
301 | - |
|
302 | - public function get_test_id() |
|
303 | - { |
|
304 | - return 'DEBUG:ID'; |
|
305 | - } |
|
306 | - |
|
307 | - public function get_link() |
|
308 | - { |
|
309 | - //it was extracts the forum id |
|
310 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
297 | + $result = Database::query($sql); |
|
298 | + $number = Database::fetch_row($result); |
|
299 | + return ($number[0] != 0); |
|
300 | + } |
|
301 | + |
|
302 | + public function get_test_id() |
|
303 | + { |
|
304 | + return 'DEBUG:ID'; |
|
305 | + } |
|
306 | + |
|
307 | + public function get_link() |
|
308 | + { |
|
309 | + //it was extracts the forum id |
|
310 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table()." |
|
311 | 311 | WHERE c_id = '.$this->course_id.' AND thread_id = '".$this->get_ref_id()."' AND session_id = ".api_get_session_id().""; |
312 | - $result = Database::query($sql); |
|
313 | - $row = Database::fetch_array($result,'ASSOC'); |
|
314 | - $forum_id=$row['forum_id']; |
|
315 | - |
|
316 | - $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | - return $url; |
|
318 | - } |
|
319 | - |
|
320 | - private function get_exercise_data() |
|
321 | - { |
|
322 | - $session_id = api_get_session_id(); |
|
323 | - if ($session_id) { |
|
324 | - $session_condition = 'session_id='.api_get_session_id(); |
|
325 | - } else { |
|
326 | - $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | - } |
|
328 | - |
|
329 | - if (!isset($this->exercise_data)) { |
|
330 | - $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
312 | + $result = Database::query($sql); |
|
313 | + $row = Database::fetch_array($result,'ASSOC'); |
|
314 | + $forum_id=$row['forum_id']; |
|
315 | + |
|
316 | + $url = api_get_path(WEB_PATH).'main/forum/viewthread.php?cidReq='.$this->get_course_code().'&thread='.$this->get_ref_id().'&gradebook=view&forum='.$forum_id; |
|
317 | + return $url; |
|
318 | + } |
|
319 | + |
|
320 | + private function get_exercise_data() |
|
321 | + { |
|
322 | + $session_id = api_get_session_id(); |
|
323 | + if ($session_id) { |
|
324 | + $session_condition = 'session_id='.api_get_session_id(); |
|
325 | + } else { |
|
326 | + $session_condition = '(session_id = 0 OR session_id IS NULL)'; |
|
327 | + } |
|
328 | + |
|
329 | + if (!isset($this->exercise_data)) { |
|
330 | + $sql = 'SELECT * FROM '.$this->get_forum_thread_table().' |
|
331 | 331 | WHERE c_id = '.$this->course_id.' AND thread_id = '.$this->get_ref_id().' AND '.$session_condition; |
332 | - $query = Database::query($sql); |
|
333 | - $this->exercise_data = Database::fetch_array($query); |
|
334 | - } |
|
335 | - return $this->exercise_data; |
|
336 | - } |
|
337 | - |
|
338 | - public function get_icon_name() |
|
339 | - { |
|
340 | - return 'forum'; |
|
341 | - } |
|
342 | - |
|
343 | - function save_linked_data() |
|
344 | - { |
|
345 | - $weight = (float)$this->get_weight(); |
|
346 | - $ref_id = $this->get_ref_id(); |
|
347 | - |
|
348 | - if (!empty($ref_id)) { |
|
349 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
332 | + $query = Database::query($sql); |
|
333 | + $this->exercise_data = Database::fetch_array($query); |
|
334 | + } |
|
335 | + return $this->exercise_data; |
|
336 | + } |
|
337 | + |
|
338 | + public function get_icon_name() |
|
339 | + { |
|
340 | + return 'forum'; |
|
341 | + } |
|
342 | + |
|
343 | + function save_linked_data() |
|
344 | + { |
|
345 | + $weight = (float)$this->get_weight(); |
|
346 | + $ref_id = $this->get_ref_id(); |
|
347 | + |
|
348 | + if (!empty($ref_id)) { |
|
349 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.' |
|
350 | 350 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
351 | - Database::query($sql); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - function delete_linked_data() |
|
356 | - { |
|
357 | - $ref_id = $this->get_ref_id(); |
|
358 | - if (!empty($ref_id)) { |
|
359 | - //Cleans forum |
|
360 | - $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
351 | + Database::query($sql); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + function delete_linked_data() |
|
356 | + { |
|
357 | + $ref_id = $this->get_ref_id(); |
|
358 | + if (!empty($ref_id)) { |
|
359 | + //Cleans forum |
|
360 | + $sql = 'UPDATE '.$this->get_forum_thread_table().' SET |
|
361 | 361 | thread_qualify_max = 0, |
362 | 362 | thread_weight = 0, |
363 | 363 | thread_title_qualify = "" |
364 | 364 | WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id; |
365 | - Database::query($sql); |
|
366 | - } |
|
367 | - } |
|
365 | + Database::query($sql); |
|
366 | + } |
|
367 | + } |
|
368 | 368 | } |
@@ -9,367 +9,367 @@ discard block |
||
9 | 9 | */ |
10 | 10 | class Evaluation implements GradebookItem |
11 | 11 | { |
12 | - private $id; |
|
13 | - private $name; |
|
14 | - private $description; |
|
15 | - private $user_id; |
|
16 | - private $course_code; |
|
17 | - /** @var Category */ |
|
18 | - private $category; |
|
19 | - private $created_at; |
|
20 | - private $weight; |
|
21 | - private $eval_max; |
|
22 | - private $visible; |
|
23 | - private $sessionId; |
|
24 | - public $studentList; |
|
25 | - |
|
26 | - /** |
|
27 | - * Construct |
|
28 | - */ |
|
29 | - public function __construct() |
|
30 | - { |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * @return Category |
|
35 | - */ |
|
36 | - public function getCategory() |
|
37 | - { |
|
38 | - return $this->category; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * @param Category $category |
|
43 | - */ |
|
44 | - public function setCategory($category) |
|
45 | - { |
|
46 | - $this->category = $category; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @return int |
|
51 | - */ |
|
52 | - public function get_category_id() |
|
53 | - { |
|
54 | - return $this->category->get_id(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * @param int $category_id |
|
59 | - */ |
|
60 | - public function set_category_id($category_id) |
|
61 | - { |
|
62 | - $categories = Category::load($category_id); |
|
63 | - if (isset($categories[0])) { |
|
64 | - $this->setCategory($categories[0]); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @return int |
|
70 | - */ |
|
71 | - public function get_id() |
|
72 | - { |
|
73 | - return $this->id; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function get_name() |
|
80 | - { |
|
81 | - return $this->name; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function get_description() |
|
88 | - { |
|
89 | - return $this->description; |
|
90 | - } |
|
91 | - |
|
92 | - public function get_user_id() |
|
93 | - { |
|
94 | - return $this->user_id; |
|
95 | - } |
|
96 | - |
|
97 | - public function get_course_code() |
|
98 | - { |
|
99 | - return $this->course_code; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function getSessionId() |
|
106 | - { |
|
107 | - return $this->sessionId; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @param int $sessionId |
|
112 | - */ |
|
113 | - public function setSessionId($sessionId) |
|
114 | - { |
|
115 | - $this->sessionId = intval($sessionId); |
|
116 | - } |
|
117 | - |
|
118 | - public function get_date() |
|
119 | - { |
|
120 | - return $this->created_at; |
|
121 | - } |
|
122 | - |
|
123 | - public function get_weight() |
|
124 | - { |
|
125 | - return $this->weight; |
|
126 | - } |
|
127 | - |
|
128 | - public function get_max() |
|
129 | - { |
|
130 | - return $this->eval_max; |
|
131 | - } |
|
132 | - |
|
133 | - public function get_type() |
|
134 | - { |
|
135 | - return $this->type; |
|
136 | - } |
|
137 | - |
|
138 | - public function is_visible() |
|
139 | - { |
|
140 | - return $this->visible; |
|
141 | - } |
|
142 | - |
|
143 | - public function get_locked() |
|
144 | - { |
|
145 | - return $this->locked; |
|
146 | - } |
|
147 | - |
|
148 | - public function is_locked() |
|
149 | - { |
|
150 | - return isset($this->locked) && $this->locked == 1 ? true : false; |
|
151 | - } |
|
152 | - |
|
153 | - public function set_id($id) |
|
154 | - { |
|
155 | - $this->id = $id; |
|
156 | - } |
|
157 | - |
|
158 | - public function set_name($name) |
|
159 | - { |
|
160 | - $this->name = $name; |
|
161 | - } |
|
162 | - |
|
163 | - public function set_description($description) |
|
164 | - { |
|
165 | - $this->description = $description; |
|
166 | - } |
|
167 | - |
|
168 | - public function set_user_id($user_id) |
|
169 | - { |
|
170 | - $this->user_id = $user_id; |
|
171 | - } |
|
172 | - |
|
173 | - public function set_course_code($course_code) |
|
174 | - { |
|
175 | - $this->course_code = $course_code; |
|
176 | - } |
|
177 | - |
|
178 | - public function set_date($date) |
|
179 | - { |
|
180 | - $this->created_at = $date; |
|
181 | - } |
|
182 | - |
|
183 | - public function set_weight($weight) |
|
184 | - { |
|
185 | - $this->weight = $weight; |
|
186 | - } |
|
187 | - |
|
188 | - public function set_max($max) |
|
189 | - { |
|
190 | - $this->eval_max = $max; |
|
191 | - } |
|
192 | - |
|
193 | - public function set_visible($visible) |
|
194 | - { |
|
195 | - $this->visible = $visible; |
|
196 | - } |
|
197 | - |
|
198 | - public function set_type($type) |
|
199 | - { |
|
200 | - $this->type = $type; |
|
201 | - } |
|
202 | - |
|
203 | - public function set_locked($locked) |
|
204 | - { |
|
205 | - $this->locked = $locked; |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Retrieve evaluations and return them as an array of Evaluation objects |
|
210 | - * @param int $id evaluation id |
|
211 | - * @param int $user_id user id (evaluation owner) |
|
212 | - * @param string $course_code course code |
|
213 | - * @param int $category_id parent category |
|
214 | - * @param integer $visible visible |
|
215 | - */ |
|
216 | - public static function load( |
|
217 | - $id = null, |
|
218 | - $user_id = null, |
|
219 | - $course_code = null, |
|
220 | - $category_id = null, |
|
221 | - $visible = null, |
|
222 | - $locked = null |
|
223 | - ) { |
|
224 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
225 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
226 | - $paramcount = 0; |
|
227 | - |
|
228 | - if (isset ($id)) { |
|
229 | - $sql.= ' WHERE id = '.intval($id); |
|
230 | - $paramcount ++; |
|
231 | - } |
|
232 | - |
|
233 | - if (isset ($user_id)) { |
|
234 | - if ($paramcount != 0) $sql .= ' AND'; |
|
235 | - else $sql .= ' WHERE'; |
|
236 | - $sql .= ' user_id = '.intval($user_id); |
|
237 | - $paramcount ++; |
|
238 | - } |
|
239 | - |
|
240 | - if (isset ($course_code) && $course_code <> '-1') { |
|
241 | - if ($paramcount != 0) $sql .= ' AND'; |
|
242 | - else $sql .= ' WHERE'; |
|
243 | - $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
244 | - $paramcount ++; |
|
245 | - } |
|
246 | - |
|
247 | - if (isset ($category_id)) { |
|
248 | - if ($paramcount != 0) $sql .= ' AND'; |
|
249 | - else $sql .= ' WHERE'; |
|
250 | - $sql .= ' category_id = '.intval($category_id); |
|
251 | - $paramcount ++; |
|
252 | - } |
|
253 | - |
|
254 | - if (isset ($visible)) { |
|
255 | - if ($paramcount != 0) $sql .= ' AND'; |
|
256 | - else $sql .= ' WHERE'; |
|
257 | - $sql .= ' visible = '.intval($visible); |
|
258 | - $paramcount ++; |
|
259 | - } |
|
260 | - |
|
261 | - if (isset ($locked)) { |
|
262 | - if ($paramcount != 0) $sql .= ' AND'; |
|
263 | - else $sql .= ' WHERE'; |
|
264 | - $sql .= ' locked = '.intval($locked); |
|
265 | - } |
|
266 | - |
|
267 | - $result = Database::query($sql); |
|
268 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
269 | - |
|
270 | - return $alleval; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @param array $result |
|
277 | - * @return array |
|
278 | - */ |
|
279 | - private static function create_evaluation_objects_from_sql_result($result) |
|
280 | - { |
|
281 | - $alleval = array(); |
|
282 | - if (Database::num_rows($result)) { |
|
283 | - while ($data = Database::fetch_array($result)) { |
|
284 | - $eval= new Evaluation(); |
|
285 | - $eval->set_id($data['id']); |
|
286 | - $eval->set_name($data['name']); |
|
287 | - $eval->set_description($data['description']); |
|
288 | - $eval->set_user_id($data['user_id']); |
|
289 | - $eval->set_course_code($data['course_code']); |
|
290 | - $eval->set_category_id($data['category_id']); |
|
291 | - $eval->set_date(api_get_local_time($data['created_at'])); |
|
292 | - $eval->set_weight($data['weight']); |
|
293 | - $eval->set_max($data['max']); |
|
294 | - $eval->set_visible($data['visible']); |
|
295 | - $eval->set_type($data['type']); |
|
296 | - $eval->set_locked($data['locked']); |
|
297 | - $eval->setSessionId(api_get_session_id()); |
|
298 | - |
|
299 | - $alleval[] = $eval; |
|
300 | - } |
|
301 | - } |
|
302 | - |
|
303 | - return $alleval; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Insert this evaluation into the database |
|
308 | - */ |
|
309 | - public function add() |
|
310 | - { |
|
311 | - if (isset($this->name) && |
|
312 | - isset($this->user_id) && |
|
313 | - isset($this->weight) && |
|
314 | - isset ($this->eval_max) && |
|
315 | - isset($this->visible) |
|
316 | - ) { |
|
317 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
318 | - |
|
319 | - $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
320 | - .' (name, user_id, weight, max, visible'; |
|
321 | - if (isset($this->description)) { |
|
322 | - $sql .= ',description'; |
|
323 | - } |
|
324 | - if (isset($this->course_code)) { |
|
325 | - $sql .= ', course_code'; |
|
326 | - } |
|
327 | - if (isset($this->category)) { |
|
328 | - $sql .= ', category_id'; |
|
329 | - } |
|
330 | - $sql .= ', created_at'; |
|
331 | - $sql .= ',type'; |
|
332 | - $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
333 | - .','.intval($this->get_user_id()) |
|
334 | - .','.floatval($this->get_weight()) |
|
335 | - .','.intval($this->get_max()) |
|
336 | - .','.intval($this->is_visible()); |
|
337 | - if (isset($this->description)) { |
|
338 | - $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
339 | - } |
|
340 | - if (isset($this->course_code)) { |
|
341 | - $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
342 | - } |
|
343 | - if (isset($this->category)) { |
|
344 | - $sql .= ','.intval($this->get_category_id()); |
|
345 | - } |
|
346 | - if (empty($this->type)) { |
|
347 | - $this->type = 'evaluation'; |
|
348 | - } |
|
349 | - $sql .= ", '".api_get_utc_datetime()."'"; |
|
350 | - $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
351 | - $sql .= ")"; |
|
352 | - |
|
353 | - Database::query($sql); |
|
354 | - $this->set_id(Database::insert_id()); |
|
355 | - } else { |
|
356 | - die('Error in Evaluation add: required field empty'); |
|
357 | - } |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * @param int $idevaluation |
|
362 | - */ |
|
363 | - public function add_evaluation_log($idevaluation) |
|
364 | - { |
|
365 | - if (!empty($idevaluation)) { |
|
366 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
367 | - $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
368 | - $eval = new Evaluation(); |
|
369 | - $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
370 | - $arreval = get_object_vars($dateobject[0]); |
|
371 | - if (!empty($arreval['id'])) { |
|
372 | - $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
12 | + private $id; |
|
13 | + private $name; |
|
14 | + private $description; |
|
15 | + private $user_id; |
|
16 | + private $course_code; |
|
17 | + /** @var Category */ |
|
18 | + private $category; |
|
19 | + private $created_at; |
|
20 | + private $weight; |
|
21 | + private $eval_max; |
|
22 | + private $visible; |
|
23 | + private $sessionId; |
|
24 | + public $studentList; |
|
25 | + |
|
26 | + /** |
|
27 | + * Construct |
|
28 | + */ |
|
29 | + public function __construct() |
|
30 | + { |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * @return Category |
|
35 | + */ |
|
36 | + public function getCategory() |
|
37 | + { |
|
38 | + return $this->category; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * @param Category $category |
|
43 | + */ |
|
44 | + public function setCategory($category) |
|
45 | + { |
|
46 | + $this->category = $category; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @return int |
|
51 | + */ |
|
52 | + public function get_category_id() |
|
53 | + { |
|
54 | + return $this->category->get_id(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * @param int $category_id |
|
59 | + */ |
|
60 | + public function set_category_id($category_id) |
|
61 | + { |
|
62 | + $categories = Category::load($category_id); |
|
63 | + if (isset($categories[0])) { |
|
64 | + $this->setCategory($categories[0]); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @return int |
|
70 | + */ |
|
71 | + public function get_id() |
|
72 | + { |
|
73 | + return $this->id; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function get_name() |
|
80 | + { |
|
81 | + return $this->name; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function get_description() |
|
88 | + { |
|
89 | + return $this->description; |
|
90 | + } |
|
91 | + |
|
92 | + public function get_user_id() |
|
93 | + { |
|
94 | + return $this->user_id; |
|
95 | + } |
|
96 | + |
|
97 | + public function get_course_code() |
|
98 | + { |
|
99 | + return $this->course_code; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function getSessionId() |
|
106 | + { |
|
107 | + return $this->sessionId; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @param int $sessionId |
|
112 | + */ |
|
113 | + public function setSessionId($sessionId) |
|
114 | + { |
|
115 | + $this->sessionId = intval($sessionId); |
|
116 | + } |
|
117 | + |
|
118 | + public function get_date() |
|
119 | + { |
|
120 | + return $this->created_at; |
|
121 | + } |
|
122 | + |
|
123 | + public function get_weight() |
|
124 | + { |
|
125 | + return $this->weight; |
|
126 | + } |
|
127 | + |
|
128 | + public function get_max() |
|
129 | + { |
|
130 | + return $this->eval_max; |
|
131 | + } |
|
132 | + |
|
133 | + public function get_type() |
|
134 | + { |
|
135 | + return $this->type; |
|
136 | + } |
|
137 | + |
|
138 | + public function is_visible() |
|
139 | + { |
|
140 | + return $this->visible; |
|
141 | + } |
|
142 | + |
|
143 | + public function get_locked() |
|
144 | + { |
|
145 | + return $this->locked; |
|
146 | + } |
|
147 | + |
|
148 | + public function is_locked() |
|
149 | + { |
|
150 | + return isset($this->locked) && $this->locked == 1 ? true : false; |
|
151 | + } |
|
152 | + |
|
153 | + public function set_id($id) |
|
154 | + { |
|
155 | + $this->id = $id; |
|
156 | + } |
|
157 | + |
|
158 | + public function set_name($name) |
|
159 | + { |
|
160 | + $this->name = $name; |
|
161 | + } |
|
162 | + |
|
163 | + public function set_description($description) |
|
164 | + { |
|
165 | + $this->description = $description; |
|
166 | + } |
|
167 | + |
|
168 | + public function set_user_id($user_id) |
|
169 | + { |
|
170 | + $this->user_id = $user_id; |
|
171 | + } |
|
172 | + |
|
173 | + public function set_course_code($course_code) |
|
174 | + { |
|
175 | + $this->course_code = $course_code; |
|
176 | + } |
|
177 | + |
|
178 | + public function set_date($date) |
|
179 | + { |
|
180 | + $this->created_at = $date; |
|
181 | + } |
|
182 | + |
|
183 | + public function set_weight($weight) |
|
184 | + { |
|
185 | + $this->weight = $weight; |
|
186 | + } |
|
187 | + |
|
188 | + public function set_max($max) |
|
189 | + { |
|
190 | + $this->eval_max = $max; |
|
191 | + } |
|
192 | + |
|
193 | + public function set_visible($visible) |
|
194 | + { |
|
195 | + $this->visible = $visible; |
|
196 | + } |
|
197 | + |
|
198 | + public function set_type($type) |
|
199 | + { |
|
200 | + $this->type = $type; |
|
201 | + } |
|
202 | + |
|
203 | + public function set_locked($locked) |
|
204 | + { |
|
205 | + $this->locked = $locked; |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Retrieve evaluations and return them as an array of Evaluation objects |
|
210 | + * @param int $id evaluation id |
|
211 | + * @param int $user_id user id (evaluation owner) |
|
212 | + * @param string $course_code course code |
|
213 | + * @param int $category_id parent category |
|
214 | + * @param integer $visible visible |
|
215 | + */ |
|
216 | + public static function load( |
|
217 | + $id = null, |
|
218 | + $user_id = null, |
|
219 | + $course_code = null, |
|
220 | + $category_id = null, |
|
221 | + $visible = null, |
|
222 | + $locked = null |
|
223 | + ) { |
|
224 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
225 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations; |
|
226 | + $paramcount = 0; |
|
227 | + |
|
228 | + if (isset ($id)) { |
|
229 | + $sql.= ' WHERE id = '.intval($id); |
|
230 | + $paramcount ++; |
|
231 | + } |
|
232 | + |
|
233 | + if (isset ($user_id)) { |
|
234 | + if ($paramcount != 0) $sql .= ' AND'; |
|
235 | + else $sql .= ' WHERE'; |
|
236 | + $sql .= ' user_id = '.intval($user_id); |
|
237 | + $paramcount ++; |
|
238 | + } |
|
239 | + |
|
240 | + if (isset ($course_code) && $course_code <> '-1') { |
|
241 | + if ($paramcount != 0) $sql .= ' AND'; |
|
242 | + else $sql .= ' WHERE'; |
|
243 | + $sql .= " course_code = '".Database::escape_string($course_code)."'"; |
|
244 | + $paramcount ++; |
|
245 | + } |
|
246 | + |
|
247 | + if (isset ($category_id)) { |
|
248 | + if ($paramcount != 0) $sql .= ' AND'; |
|
249 | + else $sql .= ' WHERE'; |
|
250 | + $sql .= ' category_id = '.intval($category_id); |
|
251 | + $paramcount ++; |
|
252 | + } |
|
253 | + |
|
254 | + if (isset ($visible)) { |
|
255 | + if ($paramcount != 0) $sql .= ' AND'; |
|
256 | + else $sql .= ' WHERE'; |
|
257 | + $sql .= ' visible = '.intval($visible); |
|
258 | + $paramcount ++; |
|
259 | + } |
|
260 | + |
|
261 | + if (isset ($locked)) { |
|
262 | + if ($paramcount != 0) $sql .= ' AND'; |
|
263 | + else $sql .= ' WHERE'; |
|
264 | + $sql .= ' locked = '.intval($locked); |
|
265 | + } |
|
266 | + |
|
267 | + $result = Database::query($sql); |
|
268 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
269 | + |
|
270 | + return $alleval; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @param array $result |
|
277 | + * @return array |
|
278 | + */ |
|
279 | + private static function create_evaluation_objects_from_sql_result($result) |
|
280 | + { |
|
281 | + $alleval = array(); |
|
282 | + if (Database::num_rows($result)) { |
|
283 | + while ($data = Database::fetch_array($result)) { |
|
284 | + $eval= new Evaluation(); |
|
285 | + $eval->set_id($data['id']); |
|
286 | + $eval->set_name($data['name']); |
|
287 | + $eval->set_description($data['description']); |
|
288 | + $eval->set_user_id($data['user_id']); |
|
289 | + $eval->set_course_code($data['course_code']); |
|
290 | + $eval->set_category_id($data['category_id']); |
|
291 | + $eval->set_date(api_get_local_time($data['created_at'])); |
|
292 | + $eval->set_weight($data['weight']); |
|
293 | + $eval->set_max($data['max']); |
|
294 | + $eval->set_visible($data['visible']); |
|
295 | + $eval->set_type($data['type']); |
|
296 | + $eval->set_locked($data['locked']); |
|
297 | + $eval->setSessionId(api_get_session_id()); |
|
298 | + |
|
299 | + $alleval[] = $eval; |
|
300 | + } |
|
301 | + } |
|
302 | + |
|
303 | + return $alleval; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Insert this evaluation into the database |
|
308 | + */ |
|
309 | + public function add() |
|
310 | + { |
|
311 | + if (isset($this->name) && |
|
312 | + isset($this->user_id) && |
|
313 | + isset($this->weight) && |
|
314 | + isset ($this->eval_max) && |
|
315 | + isset($this->visible) |
|
316 | + ) { |
|
317 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
318 | + |
|
319 | + $sql = 'INSERT INTO '.$tbl_grade_evaluations |
|
320 | + .' (name, user_id, weight, max, visible'; |
|
321 | + if (isset($this->description)) { |
|
322 | + $sql .= ',description'; |
|
323 | + } |
|
324 | + if (isset($this->course_code)) { |
|
325 | + $sql .= ', course_code'; |
|
326 | + } |
|
327 | + if (isset($this->category)) { |
|
328 | + $sql .= ', category_id'; |
|
329 | + } |
|
330 | + $sql .= ', created_at'; |
|
331 | + $sql .= ',type'; |
|
332 | + $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" |
|
333 | + .','.intval($this->get_user_id()) |
|
334 | + .','.floatval($this->get_weight()) |
|
335 | + .','.intval($this->get_max()) |
|
336 | + .','.intval($this->is_visible()); |
|
337 | + if (isset($this->description)) { |
|
338 | + $sql .= ",'".Database::escape_string($this->get_description())."'"; |
|
339 | + } |
|
340 | + if (isset($this->course_code)) { |
|
341 | + $sql .= ",'".Database::escape_string($this->get_course_code())."'"; |
|
342 | + } |
|
343 | + if (isset($this->category)) { |
|
344 | + $sql .= ','.intval($this->get_category_id()); |
|
345 | + } |
|
346 | + if (empty($this->type)) { |
|
347 | + $this->type = 'evaluation'; |
|
348 | + } |
|
349 | + $sql .= ", '".api_get_utc_datetime()."'"; |
|
350 | + $sql .= ',\''.Database::escape_string($this->type).'\''; |
|
351 | + $sql .= ")"; |
|
352 | + |
|
353 | + Database::query($sql); |
|
354 | + $this->set_id(Database::insert_id()); |
|
355 | + } else { |
|
356 | + die('Error in Evaluation add: required field empty'); |
|
357 | + } |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * @param int $idevaluation |
|
362 | + */ |
|
363 | + public function add_evaluation_log($idevaluation) |
|
364 | + { |
|
365 | + if (!empty($idevaluation)) { |
|
366 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
367 | + $tbl_grade_linkeval_log = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINKEVAL_LOG); |
|
368 | + $eval = new Evaluation(); |
|
369 | + $dateobject = $eval->load($idevaluation,null,null,null,null); |
|
370 | + $arreval = get_object_vars($dateobject[0]); |
|
371 | + if (!empty($arreval['id'])) { |
|
372 | + $sql = 'SELECT weight from '.$tbl_grade_evaluations.' |
|
373 | 373 | WHERE id='.$arreval['id']; |
374 | 374 | $rs = Database::query($sql); |
375 | 375 | $row_old_weight = Database::fetch_array($rs, 'ASSOC'); |
@@ -385,426 +385,426 @@ discard block |
||
385 | 385 | 'user_id_log' => api_get_user_id() |
386 | 386 | ]; |
387 | 387 | Database::insert($tbl_grade_linkeval_log, $params); |
388 | - } |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Update the properties of this evaluation in the database |
|
394 | - */ |
|
395 | - public function save() |
|
396 | - { |
|
397 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
398 | - $sql = 'UPDATE '.$tbl_grade_evaluations |
|
399 | - ." SET name = '".Database::escape_string($this->get_name())."'" |
|
400 | - .', description = '; |
|
401 | - if (isset($this->description)) { |
|
402 | - $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
403 | - }else { |
|
404 | - $sql .= 'null'; |
|
405 | - } |
|
406 | - $sql .= ', user_id = '.intval($this->get_user_id()) |
|
407 | - .', course_code = '; |
|
408 | - if (isset($this->course_code)) { |
|
409 | - $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
410 | - } else { |
|
411 | - $sql .= 'null'; |
|
412 | - } |
|
413 | - $sql .= ', category_id = '; |
|
414 | - if (isset($this->category)) { |
|
415 | - $sql .= intval($this->get_category_id()); |
|
416 | - } else { |
|
417 | - $sql .= 'null'; |
|
418 | - } |
|
419 | - $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
420 | - .', max = '.intval($this->get_max()) |
|
421 | - .', visible = '.intval($this->is_visible()) |
|
422 | - .' WHERE id = '.intval($this->id); |
|
423 | - //recorded history |
|
424 | - |
|
425 | - $eval_log = new Evaluation(); |
|
426 | - $eval_log->add_evaluation_log($this->id); |
|
427 | - Database::query($sql); |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Delete this evaluation from the database |
|
432 | - */ |
|
433 | - public function delete() |
|
434 | - { |
|
435 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
436 | - $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
437 | - Database::query($sql); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Check if an evaluation name (with the same parent category) already exists |
|
442 | - * @param $name name to check (if not given, the name property of this object will be checked) |
|
443 | - * @param $parent parent category |
|
444 | - */ |
|
445 | - public function does_name_exist($name, $parent) |
|
446 | - { |
|
447 | - if (!isset ($name)) { |
|
448 | - $name = $this->name; |
|
449 | - $parent = $this->category; |
|
450 | - } |
|
451 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
452 | - $sql = 'SELECT count(id) AS number' |
|
453 | - .' FROM '.$tbl_grade_evaluations |
|
454 | - ." WHERE name = '".Database::escape_string($name)."'"; |
|
455 | - |
|
456 | - if (api_is_allowed_to_edit()) { |
|
457 | - $parent = Category::load($parent); |
|
458 | - $code = $parent[0]->get_course_code(); |
|
459 | - $courseInfo = api_get_course_info($code); |
|
460 | - $courseId = $courseInfo['real_id']; |
|
461 | - |
|
462 | - if (isset($code) && $code != '0') { |
|
463 | - $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
464 | - $sql .= ' AND user_id IN ( |
|
388 | + } |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Update the properties of this evaluation in the database |
|
394 | + */ |
|
395 | + public function save() |
|
396 | + { |
|
397 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
398 | + $sql = 'UPDATE '.$tbl_grade_evaluations |
|
399 | + ." SET name = '".Database::escape_string($this->get_name())."'" |
|
400 | + .', description = '; |
|
401 | + if (isset($this->description)) { |
|
402 | + $sql .= "'".Database::escape_string($this->get_description())."'"; |
|
403 | + }else { |
|
404 | + $sql .= 'null'; |
|
405 | + } |
|
406 | + $sql .= ', user_id = '.intval($this->get_user_id()) |
|
407 | + .', course_code = '; |
|
408 | + if (isset($this->course_code)) { |
|
409 | + $sql .= "'".Database::escape_string($this->get_course_code())."'"; |
|
410 | + } else { |
|
411 | + $sql .= 'null'; |
|
412 | + } |
|
413 | + $sql .= ', category_id = '; |
|
414 | + if (isset($this->category)) { |
|
415 | + $sql .= intval($this->get_category_id()); |
|
416 | + } else { |
|
417 | + $sql .= 'null'; |
|
418 | + } |
|
419 | + $sql .= ', weight = "'.Database::escape_string($this->get_weight()).'" ' |
|
420 | + .', max = '.intval($this->get_max()) |
|
421 | + .', visible = '.intval($this->is_visible()) |
|
422 | + .' WHERE id = '.intval($this->id); |
|
423 | + //recorded history |
|
424 | + |
|
425 | + $eval_log = new Evaluation(); |
|
426 | + $eval_log->add_evaluation_log($this->id); |
|
427 | + Database::query($sql); |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Delete this evaluation from the database |
|
432 | + */ |
|
433 | + public function delete() |
|
434 | + { |
|
435 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
436 | + $sql = 'DELETE FROM '.$tbl_grade_evaluations.' WHERE id = '.intval($this->id); |
|
437 | + Database::query($sql); |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Check if an evaluation name (with the same parent category) already exists |
|
442 | + * @param $name name to check (if not given, the name property of this object will be checked) |
|
443 | + * @param $parent parent category |
|
444 | + */ |
|
445 | + public function does_name_exist($name, $parent) |
|
446 | + { |
|
447 | + if (!isset ($name)) { |
|
448 | + $name = $this->name; |
|
449 | + $parent = $this->category; |
|
450 | + } |
|
451 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
452 | + $sql = 'SELECT count(id) AS number' |
|
453 | + .' FROM '.$tbl_grade_evaluations |
|
454 | + ." WHERE name = '".Database::escape_string($name)."'"; |
|
455 | + |
|
456 | + if (api_is_allowed_to_edit()) { |
|
457 | + $parent = Category::load($parent); |
|
458 | + $code = $parent[0]->get_course_code(); |
|
459 | + $courseInfo = api_get_course_info($code); |
|
460 | + $courseId = $courseInfo['real_id']; |
|
461 | + |
|
462 | + if (isset($code) && $code != '0') { |
|
463 | + $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER); |
|
464 | + $sql .= ' AND user_id IN ( |
|
465 | 465 | SELECT user_id FROM '.$main_course_user_table.' |
466 | 466 | WHERE |
467 | 467 | c_id = '.$courseId.' AND |
468 | 468 | status = '.COURSEMANAGER.' |
469 | 469 | )'; |
470 | - } else { |
|
471 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
472 | - } |
|
473 | - |
|
474 | - }else { |
|
475 | - $sql .= ' AND user_id = '.api_get_user_id(); |
|
476 | - } |
|
477 | - |
|
478 | - if (!isset ($parent)) { |
|
479 | - $sql.= ' AND category_id is null'; |
|
480 | - } else { |
|
481 | - $sql.= ' AND category_id = '.intval($parent); |
|
482 | - } |
|
483 | - $result = Database::query($sql); |
|
484 | - $number=Database::fetch_row($result); |
|
485 | - |
|
486 | - return $number[0] != 0; |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Are there any results for this evaluation yet ? |
|
491 | - * The 'max' property should not be changed then. |
|
492 | - */ |
|
493 | - public function has_results() |
|
494 | - { |
|
495 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
496 | - $sql = 'SELECT count(id) AS number |
|
470 | + } else { |
|
471 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
472 | + } |
|
473 | + |
|
474 | + }else { |
|
475 | + $sql .= ' AND user_id = '.api_get_user_id(); |
|
476 | + } |
|
477 | + |
|
478 | + if (!isset ($parent)) { |
|
479 | + $sql.= ' AND category_id is null'; |
|
480 | + } else { |
|
481 | + $sql.= ' AND category_id = '.intval($parent); |
|
482 | + } |
|
483 | + $result = Database::query($sql); |
|
484 | + $number=Database::fetch_row($result); |
|
485 | + |
|
486 | + return $number[0] != 0; |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Are there any results for this evaluation yet ? |
|
491 | + * The 'max' property should not be changed then. |
|
492 | + */ |
|
493 | + public function has_results() |
|
494 | + { |
|
495 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
496 | + $sql = 'SELECT count(id) AS number |
|
497 | 497 | FROM '.$tbl_grade_results.' |
498 | 498 | WHERE evaluation_id = '.intval($this->id); |
499 | - $result = Database::query($sql); |
|
500 | - $number=Database::fetch_row($result); |
|
501 | - |
|
502 | - return ($number[0] != 0); |
|
503 | - } |
|
504 | - |
|
505 | - /** |
|
506 | - * Delete all results for this evaluation |
|
507 | - */ |
|
508 | - public function delete_results() |
|
509 | - { |
|
510 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
511 | - $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
499 | + $result = Database::query($sql); |
|
500 | + $number=Database::fetch_row($result); |
|
501 | + |
|
502 | + return ($number[0] != 0); |
|
503 | + } |
|
504 | + |
|
505 | + /** |
|
506 | + * Delete all results for this evaluation |
|
507 | + */ |
|
508 | + public function delete_results() |
|
509 | + { |
|
510 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
511 | + $sql = 'DELETE FROM '.$tbl_grade_results.' |
|
512 | 512 | WHERE evaluation_id = '.intval($this->id); |
513 | - Database::query($sql); |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Delete this evaluation and all underlying results. |
|
518 | - */ |
|
519 | - public function delete_with_results() |
|
520 | - { |
|
521 | - $this->delete_results(); |
|
522 | - $this->delete(); |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * Check if the given score is possible for this evaluation |
|
527 | - */ |
|
528 | - public function is_valid_score($score) |
|
529 | - { |
|
530 | - return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Calculate the score of this evaluation |
|
535 | - * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
536 | - * @param string $type (best, average, ranking) |
|
537 | - * @return array (score, max) if student is given |
|
538 | - * array (sum of scores, number of scores) otherwise |
|
539 | - * or null if no scores available |
|
540 | - */ |
|
541 | - public function calc_score($stud_id = null, $type = null) |
|
542 | - { |
|
513 | + Database::query($sql); |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Delete this evaluation and all underlying results. |
|
518 | + */ |
|
519 | + public function delete_with_results() |
|
520 | + { |
|
521 | + $this->delete_results(); |
|
522 | + $this->delete(); |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * Check if the given score is possible for this evaluation |
|
527 | + */ |
|
528 | + public function is_valid_score($score) |
|
529 | + { |
|
530 | + return is_numeric($score) && $score >= 0 && $score <= $this->eval_max; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Calculate the score of this evaluation |
|
535 | + * @param int $stud_id (default: all students who have results for this eval - then the average is returned) |
|
536 | + * @param string $type (best, average, ranking) |
|
537 | + * @return array (score, max) if student is given |
|
538 | + * array (sum of scores, number of scores) otherwise |
|
539 | + * or null if no scores available |
|
540 | + */ |
|
541 | + public function calc_score($stud_id = null, $type = null) |
|
542 | + { |
|
543 | 543 | $useSession = true; |
544 | - if (isset($stud_id) && empty($type)) { |
|
545 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
546 | - $data = Session::read('calc_score'); |
|
544 | + if (isset($stud_id) && empty($type)) { |
|
545 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id.'_'.$stud_id; |
|
546 | + $data = Session::read('calc_score'); |
|
547 | 547 | $results = isset($data[$key]) ? $data[$key] : null; |
548 | 548 | |
549 | 549 | if ($useSession == false) { |
550 | 550 | $results = null; |
551 | 551 | } |
552 | - if (empty($results)) { |
|
553 | - $results = Result::load(null, $stud_id, $this->id); |
|
554 | - Session::write('calc_score', array($key => $results)); |
|
555 | - } |
|
556 | - |
|
557 | - $score = 0; |
|
558 | - /** @var Result $res */ |
|
559 | - foreach ($results as $res) { |
|
560 | - $score = $res->get_score(); |
|
561 | - } |
|
562 | - |
|
563 | - return array($score, $this->get_max()); |
|
564 | - } else { |
|
565 | - |
|
566 | - $count = 0; |
|
567 | - $sum = 0; |
|
568 | - $bestResult = 0; |
|
569 | - $weight = 0; |
|
570 | - $sumResult = 0; |
|
571 | - |
|
572 | - $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
552 | + if (empty($results)) { |
|
553 | + $results = Result::load(null, $stud_id, $this->id); |
|
554 | + Session::write('calc_score', array($key => $results)); |
|
555 | + } |
|
556 | + |
|
557 | + $score = 0; |
|
558 | + /** @var Result $res */ |
|
559 | + foreach ($results as $res) { |
|
560 | + $score = $res->get_score(); |
|
561 | + } |
|
562 | + |
|
563 | + return array($score, $this->get_max()); |
|
564 | + } else { |
|
565 | + |
|
566 | + $count = 0; |
|
567 | + $sum = 0; |
|
568 | + $bestResult = 0; |
|
569 | + $weight = 0; |
|
570 | + $sumResult = 0; |
|
571 | + |
|
572 | + $key = 'result_score_student_list_'.api_get_course_int_id().'_'.api_get_session_id().'_'.$this->id; |
|
573 | 573 | $data = Session::read('calc_score'); |
574 | 574 | $allResults = isset($data[$key]) ? $data[$key] : null; |
575 | 575 | if ($useSession == false) { |
576 | 576 | $allResults = null; |
577 | 577 | } |
578 | - if (empty($allResults)) { |
|
579 | - $allResults = Result::load(null, null, $this->id); |
|
580 | - Session::write($key, $allResults); |
|
581 | - } |
|
582 | - |
|
583 | - $students = array(); |
|
584 | - /** @var Result $res */ |
|
585 | - foreach ($allResults as $res) { |
|
586 | - $score = $res->get_score(); |
|
587 | - if (!empty($score) || $score == '0') { |
|
588 | - $count++; |
|
589 | - $sum += $score / $this->get_max(); |
|
590 | - $sumResult += $score; |
|
591 | - if ($score > $bestResult) { |
|
592 | - $bestResult = $score; |
|
593 | - } |
|
594 | - $weight = $this->get_max(); |
|
595 | - } |
|
596 | - $students[$res->get_user_id()] = $score; |
|
597 | - } |
|
598 | - |
|
599 | - if (empty($count)) { |
|
600 | - return null; |
|
601 | - } |
|
602 | - |
|
603 | - switch ($type) { |
|
604 | - case 'best': |
|
605 | - return array($bestResult, $weight); |
|
606 | - break; |
|
607 | - case 'average': |
|
608 | - return array($sumResult/$count, $weight); |
|
609 | - break; |
|
610 | - case 'ranking': |
|
578 | + if (empty($allResults)) { |
|
579 | + $allResults = Result::load(null, null, $this->id); |
|
580 | + Session::write($key, $allResults); |
|
581 | + } |
|
582 | + |
|
583 | + $students = array(); |
|
584 | + /** @var Result $res */ |
|
585 | + foreach ($allResults as $res) { |
|
586 | + $score = $res->get_score(); |
|
587 | + if (!empty($score) || $score == '0') { |
|
588 | + $count++; |
|
589 | + $sum += $score / $this->get_max(); |
|
590 | + $sumResult += $score; |
|
591 | + if ($score > $bestResult) { |
|
592 | + $bestResult = $score; |
|
593 | + } |
|
594 | + $weight = $this->get_max(); |
|
595 | + } |
|
596 | + $students[$res->get_user_id()] = $score; |
|
597 | + } |
|
598 | + |
|
599 | + if (empty($count)) { |
|
600 | + return null; |
|
601 | + } |
|
602 | + |
|
603 | + switch ($type) { |
|
604 | + case 'best': |
|
605 | + return array($bestResult, $weight); |
|
606 | + break; |
|
607 | + case 'average': |
|
608 | + return array($sumResult/$count, $weight); |
|
609 | + break; |
|
610 | + case 'ranking': |
|
611 | 611 | $students = array(); |
612 | 612 | /** @var Result $res */ |
613 | 613 | foreach ($allResults as $res) { |
614 | 614 | $score = $res->get_score(); |
615 | 615 | $students[$res->get_user_id()] = $score; |
616 | 616 | } |
617 | - return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
618 | - break; |
|
619 | - default: |
|
620 | - return array($sum, $count); |
|
621 | - break; |
|
622 | - } |
|
623 | - } |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * Generate an array of possible categories where this evaluation can be moved to. |
|
628 | - * Notice: its own parent will be included in the list: it's up to the frontend |
|
629 | - * to disable this element. |
|
630 | - * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
631 | - */ |
|
632 | - public function get_target_categories() |
|
633 | - { |
|
634 | - // - course independent evaluation |
|
635 | - // -> movable to root or other course independent categories |
|
636 | - // - evaluation inside a course |
|
637 | - // -> movable to root, independent categories or categories inside the course |
|
638 | - $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
639 | - $targets = array(); |
|
640 | - $level = 0; |
|
641 | - |
|
642 | - $root = array(0, get_lang('RootCat'), $level); |
|
643 | - $targets[] = $root; |
|
644 | - |
|
645 | - if (isset($this->course_code) && !empty($this->course_code)) { |
|
646 | - $crscats = Category::load(null,null,$this->course_code,0); |
|
647 | - foreach ($crscats as $cat) { |
|
648 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
649 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
650 | - } |
|
651 | - } |
|
652 | - |
|
653 | - $indcats = Category::load(null,$user,0,0); |
|
654 | - foreach ($indcats as $cat) { |
|
655 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
656 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
657 | - } |
|
658 | - |
|
659 | - return $targets; |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * Internal function used by get_target_categories() |
|
664 | - * @param integer $level |
|
665 | - */ |
|
666 | - private function add_target_subcategories($targets, $level, $catid) |
|
667 | - { |
|
668 | - $subcats = Category::load(null,null,null,$catid); |
|
669 | - foreach ($subcats as $cat) { |
|
670 | - $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
671 | - $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
672 | - } |
|
673 | - return $targets; |
|
674 | - } |
|
675 | - |
|
676 | - /** |
|
677 | - * Move this evaluation to the given category. |
|
678 | - * If this evaluation moves from inside a course to outside, |
|
679 | - * its course code is also changed. |
|
680 | - */ |
|
681 | - public function move_to_cat($cat) |
|
682 | - { |
|
683 | - $this->set_category_id($cat->get_id()); |
|
684 | - if ($this->get_course_code() != $cat->get_course_code()) { |
|
685 | - $this->set_course_code($cat->get_course_code()); |
|
686 | - } |
|
687 | - $this->save(); |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Retrieve evaluations where a student has results for |
|
692 | - * and return them as an array of Evaluation objects |
|
693 | - * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
694 | - * @param int $stud_id student id |
|
695 | - */ |
|
696 | - public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
697 | - { |
|
698 | - $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
699 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
700 | - |
|
701 | - $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
617 | + return AbstractLink::getCurrentUserRanking($stud_id, $students); |
|
618 | + break; |
|
619 | + default: |
|
620 | + return array($sum, $count); |
|
621 | + break; |
|
622 | + } |
|
623 | + } |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * Generate an array of possible categories where this evaluation can be moved to. |
|
628 | + * Notice: its own parent will be included in the list: it's up to the frontend |
|
629 | + * to disable this element. |
|
630 | + * @return array 2-dimensional array - every element contains 3 subelements (id, name, level) |
|
631 | + */ |
|
632 | + public function get_target_categories() |
|
633 | + { |
|
634 | + // - course independent evaluation |
|
635 | + // -> movable to root or other course independent categories |
|
636 | + // - evaluation inside a course |
|
637 | + // -> movable to root, independent categories or categories inside the course |
|
638 | + $user = (api_is_platform_admin() ? null : api_get_user_id()); |
|
639 | + $targets = array(); |
|
640 | + $level = 0; |
|
641 | + |
|
642 | + $root = array(0, get_lang('RootCat'), $level); |
|
643 | + $targets[] = $root; |
|
644 | + |
|
645 | + if (isset($this->course_code) && !empty($this->course_code)) { |
|
646 | + $crscats = Category::load(null,null,$this->course_code,0); |
|
647 | + foreach ($crscats as $cat) { |
|
648 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
649 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
650 | + } |
|
651 | + } |
|
652 | + |
|
653 | + $indcats = Category::load(null,$user,0,0); |
|
654 | + foreach ($indcats as $cat) { |
|
655 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
656 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
657 | + } |
|
658 | + |
|
659 | + return $targets; |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * Internal function used by get_target_categories() |
|
664 | + * @param integer $level |
|
665 | + */ |
|
666 | + private function add_target_subcategories($targets, $level, $catid) |
|
667 | + { |
|
668 | + $subcats = Category::load(null,null,null,$catid); |
|
669 | + foreach ($subcats as $cat) { |
|
670 | + $targets[] = array ($cat->get_id(), $cat->get_name(), $level+1); |
|
671 | + $targets = $this->add_target_subcategories($targets, $level+1, $cat->get_id()); |
|
672 | + } |
|
673 | + return $targets; |
|
674 | + } |
|
675 | + |
|
676 | + /** |
|
677 | + * Move this evaluation to the given category. |
|
678 | + * If this evaluation moves from inside a course to outside, |
|
679 | + * its course code is also changed. |
|
680 | + */ |
|
681 | + public function move_to_cat($cat) |
|
682 | + { |
|
683 | + $this->set_category_id($cat->get_id()); |
|
684 | + if ($this->get_course_code() != $cat->get_course_code()) { |
|
685 | + $this->set_course_code($cat->get_course_code()); |
|
686 | + } |
|
687 | + $this->save(); |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Retrieve evaluations where a student has results for |
|
692 | + * and return them as an array of Evaluation objects |
|
693 | + * @param int $cat_id parent category (use 'null' to retrieve them in all categories) |
|
694 | + * @param int $stud_id student id |
|
695 | + */ |
|
696 | + public static function get_evaluations_with_result_for_student($cat_id = null, $stud_id) |
|
697 | + { |
|
698 | + $tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
699 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
700 | + |
|
701 | + $sql = 'SELECT * FROM '.$tbl_grade_evaluations.' |
|
702 | 702 | WHERE id IN ( |
703 | 703 | SELECT evaluation_id FROM '.$tbl_grade_results.' |
704 | 704 | WHERE user_id = '.intval($stud_id).' AND score IS NOT NULL |
705 | 705 | )'; |
706 | - if (!api_is_allowed_to_edit()) { |
|
707 | - $sql .= ' AND visible = 1'; |
|
708 | - } |
|
709 | - if (isset($cat_id)) { |
|
710 | - $sql .= ' AND category_id = '.intval($cat_id); |
|
711 | - } else { |
|
712 | - $sql .= ' AND category_id >= 0'; |
|
713 | - } |
|
714 | - |
|
715 | - $result = Database::query($sql); |
|
716 | - $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
717 | - |
|
718 | - return $alleval; |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * Get a list of students that do not have a result record for this evaluation |
|
723 | - */ |
|
724 | - public function get_not_subscribed_students($first_letter_user = '') |
|
725 | - { |
|
726 | - $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
727 | - $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
728 | - |
|
729 | - $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
730 | - ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
731 | - .' AND status = '.STUDENT |
|
732 | - .' AND user_id NOT IN' |
|
733 | - .' (SELECT user_id FROM '.$tbl_grade_results |
|
734 | - .' WHERE evaluation_id = '.intval($this->id) |
|
735 | - .' )' |
|
736 | - .' ORDER BY lastname'; |
|
737 | - |
|
738 | - $result = Database::query($sql); |
|
739 | - $users = Database::store_result($result); |
|
740 | - |
|
741 | - return $users; |
|
742 | - } |
|
743 | - |
|
744 | - /** |
|
745 | - * Find evaluations by name |
|
746 | - * @param string $name_mask search string |
|
747 | - * @return array evaluation objects matching the search criterium |
|
748 | - * @todo can be written more efficiently using a new (but very complex) sql query |
|
749 | - */ |
|
750 | - public function find_evaluations($name_mask,$selectcat) |
|
751 | - { |
|
752 | - $rootcat = Category::load($selectcat); |
|
753 | - $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
754 | - $foundevals = array(); |
|
755 | - foreach ($evals as $eval) { |
|
756 | - if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
757 | - $foundevals[] = $eval; |
|
758 | - } |
|
759 | - } |
|
760 | - return $foundevals; |
|
761 | - } |
|
762 | - |
|
763 | - public function get_item_type() |
|
764 | - { |
|
765 | - return 'E'; |
|
766 | - } |
|
767 | - |
|
768 | - public function get_icon_name() |
|
769 | - { |
|
770 | - return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
771 | - } |
|
772 | - |
|
773 | - /** |
|
774 | - * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
775 | - * @param int locked 1 or unlocked 0 |
|
776 | - * |
|
777 | - **/ |
|
778 | - function lock($locked) |
|
779 | - { |
|
780 | - $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
781 | - $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
782 | - Database::query($sql); |
|
783 | - } |
|
784 | - |
|
785 | - function check_lock_permissions() |
|
786 | - { |
|
787 | - if (api_is_platform_admin()) { |
|
788 | - return true; |
|
789 | - } else { |
|
790 | - if ($this->is_locked()) { |
|
791 | - api_not_allowed(); |
|
792 | - } |
|
793 | - } |
|
794 | - } |
|
795 | - |
|
796 | - function delete_linked_data() |
|
797 | - { |
|
798 | - |
|
799 | - } |
|
706 | + if (!api_is_allowed_to_edit()) { |
|
707 | + $sql .= ' AND visible = 1'; |
|
708 | + } |
|
709 | + if (isset($cat_id)) { |
|
710 | + $sql .= ' AND category_id = '.intval($cat_id); |
|
711 | + } else { |
|
712 | + $sql .= ' AND category_id >= 0'; |
|
713 | + } |
|
714 | + |
|
715 | + $result = Database::query($sql); |
|
716 | + $alleval = Evaluation::create_evaluation_objects_from_sql_result($result); |
|
717 | + |
|
718 | + return $alleval; |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * Get a list of students that do not have a result record for this evaluation |
|
723 | + */ |
|
724 | + public function get_not_subscribed_students($first_letter_user = '') |
|
725 | + { |
|
726 | + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
727 | + $tbl_grade_results = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_RESULT); |
|
728 | + |
|
729 | + $sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user |
|
730 | + ." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'" |
|
731 | + .' AND status = '.STUDENT |
|
732 | + .' AND user_id NOT IN' |
|
733 | + .' (SELECT user_id FROM '.$tbl_grade_results |
|
734 | + .' WHERE evaluation_id = '.intval($this->id) |
|
735 | + .' )' |
|
736 | + .' ORDER BY lastname'; |
|
737 | + |
|
738 | + $result = Database::query($sql); |
|
739 | + $users = Database::store_result($result); |
|
740 | + |
|
741 | + return $users; |
|
742 | + } |
|
743 | + |
|
744 | + /** |
|
745 | + * Find evaluations by name |
|
746 | + * @param string $name_mask search string |
|
747 | + * @return array evaluation objects matching the search criterium |
|
748 | + * @todo can be written more efficiently using a new (but very complex) sql query |
|
749 | + */ |
|
750 | + public function find_evaluations($name_mask,$selectcat) |
|
751 | + { |
|
752 | + $rootcat = Category::load($selectcat); |
|
753 | + $evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true); |
|
754 | + $foundevals = array(); |
|
755 | + foreach ($evals as $eval) { |
|
756 | + if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) { |
|
757 | + $foundevals[] = $eval; |
|
758 | + } |
|
759 | + } |
|
760 | + return $foundevals; |
|
761 | + } |
|
762 | + |
|
763 | + public function get_item_type() |
|
764 | + { |
|
765 | + return 'E'; |
|
766 | + } |
|
767 | + |
|
768 | + public function get_icon_name() |
|
769 | + { |
|
770 | + return $this->has_results() ? 'evalnotempty' : 'evalempty'; |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * Locks an evaluation, only one who can unlock it is the platform administrator. |
|
775 | + * @param int locked 1 or unlocked 0 |
|
776 | + * |
|
777 | + **/ |
|
778 | + function lock($locked) |
|
779 | + { |
|
780 | + $table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); |
|
781 | + $sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; |
|
782 | + Database::query($sql); |
|
783 | + } |
|
784 | + |
|
785 | + function check_lock_permissions() |
|
786 | + { |
|
787 | + if (api_is_platform_admin()) { |
|
788 | + return true; |
|
789 | + } else { |
|
790 | + if ($this->is_locked()) { |
|
791 | + api_not_allowed(); |
|
792 | + } |
|
793 | + } |
|
794 | + } |
|
795 | + |
|
796 | + function delete_linked_data() |
|
797 | + { |
|
798 | + |
|
799 | + } |
|
800 | 800 | |
801 | 801 | public function getStudentList() |
802 | 802 | { |
803 | 803 | return $this->studentList; |
804 | 804 | } |
805 | 805 | |
806 | - public function setStudentList($list) |
|
807 | - { |
|
808 | - $this->studentList = $list; |
|
809 | - } |
|
806 | + public function setStudentList($list) |
|
807 | + { |
|
808 | + $this->studentList = $list; |
|
809 | + } |
|
810 | 810 | } |