Automatic installer.php lang files by installer_builder (20070726)
[moodle-linuxchix.git] / search / documents / techproject_document.php
blobb1f2bc5231f08c18e44880b869dc427e38c383ef
1 <?php
2 /**
3 * Global Search Engine for Moodle
4 * add-on 1.8+ : Valery Fremaux [valery.fremaux@club-internet.fr]
5 * 2007/08/02
7 * document handling for techproject activity module
8 */
9 /* see wiki_document.php for descriptions */
11 require_once("$CFG->dirroot/search/documents/document.php");
12 require_once("$CFG->dirroot/mod/techproject/lib.php");
14 /**
15 * a class for representing searchable information
18 class TechprojectEntrySearchDocument extends SearchDocument {
20 /**
21 * constructor
24 public function __construct(&$entry, $course_id, $context_id) {
25 // generic information
26 $doc->docid = $entry['id'];
27 $doc->documenttype = SEARCH_TYPE_TECHPROJECT;
28 $doc->itemtype = $entry['entry_type'];
29 $doc->contextid = $context_id;
32 $doc->title = $entry['abstract'];
33 $doc->author = ($entry['userid']) ? $entry['author'] : '';
34 $doc->contents = strip_tags($entry['description']);
35 $doc->date = '';
37 $doc->url = techproject_make_link($entry['projectid'], $entry['id'], $entry['entry_type'], $entry['groupid']);
39 // module specific information
40 $data->techproject = $entry['projectid'];
42 parent::__construct($doc, $data, $course_id, $entry['groupid'], $entry['userid'], PATH_FOR_SEARCH_TYPE_TECHPROJECT);
43 } //constructor
44 } //TechprojectEntrySearchDocument
46 /**
47 * constructs a valid link to a description detail
50 function techproject_make_link($techproject_id, $entry_id, $entry_type, $group_id) {
51 global $CFG;
52 return $CFG->wwwroot.'/mod/techproject/view.php?view=view_detail&amp;id='.$techproject_id.'&amp;objectId='.$entry_id.'&amp;objectClass='.$entry_type.'&amp;group='.$group_id;
53 } //techproject_make_link
55 /**
56 * search standard API
59 function techproject_iterator() {
60 $techprojects = get_records('techproject');
61 return $techprojects;
62 } //techproject_iterator
64 /**
65 * search standard API
66 * @param techproject a techproject instance
67 * @return an array of collected searchable documents
69 function techproject_get_content_for_index(&$techproject) {
70 $documents = array();
71 if (!$techproject) return $documents;
73 $requirements = techproject_get_entries($techproject->id, 'requirement');
74 $specifications = techproject_get_entries($techproject->id, 'specification');
75 $tasks = techproject_get_tasks($techproject->id);
76 $milestones = techproject_get_entries($techproject->id, 'milestone');
77 $deliverables = techproject_get_entries($techproject->id, 'deliverable');
78 $coursemodule = get_field('modules', 'id', 'name', 'techproject');
79 $cm = get_record('course_modules', 'course', $techproject->course, 'module', $coursemodule, 'instance', $techproject->id);
80 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
82 $entries = array_merge($requirements, $specifications, $milestones, $deliverables);
83 foreach($entries as $anEntry) {
84 if ($anEntry) {
85 if (strlen($anEntry->description) > 0) {
86 $documents[] = new TechprojectEntrySearchDocument(get_object_vars($anEntry), $techproject->course, $context->id);
91 foreach($tasks as $aTask) {
92 if ($aTask) {
93 if (strlen($aTask->description) > 0) {
94 if ($aTask->assignee){
95 $user = get_record('user', 'id', $aTask->assignee);
96 $aTask->author = $user->firstname.' '.$user->lastname;
98 $documents[] = new TechprojectEntrySearchDocument(get_object_vars($aTask), $techproject->course, $context->id);
102 return $documents;
103 } //techproject_get_content_for_index
106 * returns a single techproject search document based on a techproject_entry id and itemtype
109 function techproject_single_document($id, $itemtype) {
110 switch ($itemtype){
111 case 'requirement':{
112 $entry = get_record('techproject_requirement', 'id', $id);
113 break;
115 case 'specification':{
116 $entry = get_record('techproject_specification', 'id', $id);
117 break;
119 case 'milestone':{
120 $entry = get_record('techproject_milestone', 'id', $id);
121 break;
123 case 'deliverable':{
124 $entry = get_record('techproject_deliverable', 'id', $id);
125 break;
127 case 'task':{
128 $entry = get_record('techproject_task', 'id', $id);
129 if ($entry->assignee){
130 $user = get_record('user', 'id', $entry->assignee);
131 $entry->author = $user->firstname.' '.$user->lastname;
133 break;
136 $techprojet_course = get_field('techproject', 'course', 'id', $entry->projectid);
137 $coursemodule = get_field('modules', 'id', 'name', 'techproject');
138 $cm = get_record('course_modules', 'course', $techproject_course, 'module', $coursemodule, 'instance', $entry->projectid);
139 $context = get_context_instance(CONTEXT_MODULE, $cm->id);
140 $entry->type = $itemtype;
141 $techproject = get_record('techproject', 'id', $requirement->projectid);
142 return new TechprojectEntrySearchDocument(get_object_vars($anEntry), $techproject->course, $context->id);
143 } //techproject_single_document
146 * dummy delete function that packs id with itemtype.
147 * this was here for a reason, but I can't remember it at the moment.
150 function techproject_delete($info, $itemtype) {
151 $object->id = $info;
152 $object->itemtype = $itemtype;
153 return $object;
154 } //techproject_delete
157 * returns the var names needed to build a sql query for addition/deletions
160 // TODO : what should we do there ?
161 function techproject_db_names() {
162 //[primary id], [table name], [time created field name], [time modified field name]
163 return array(
164 array('id', 'techproject_requirement', 'created', 'modified', 'requirement'),
165 array('id', 'techproject_specification', 'created', 'modified', 'specification'),
166 array('id', 'techproject_task', 'created', 'modified', 'task'),
167 array('id', 'techproject_milestone', 'created', 'modified', 'milestone'),
168 array('id', 'techproject_deliverable', 'created', 'modified', 'deliverable')
170 } //techproject_db_names
173 * get a complete list of entries of one particular type
174 * @param techprojectId the project instance
175 * @param type the entity type
176 * @return an array of records
178 function techproject_get_entries($techproject_id, $type) {
179 global $CFG;
181 $query = "
182 SELECT
183 e.id,
184 e.abstract,
185 e.description,
186 e.projectid,
187 e.groupid,
188 e.userid,
189 '$type' AS entry_type
190 FROM
191 {$CFG->prefix}techproject_{$type} AS e
192 WHERE
193 e.projectid = '{$techproject_id}'
195 return get_records_sql($query);
196 } //techproject_get_entries
199 * get the task list for a project instance
200 * @param techprojectId the project
201 * @return an array of records that represent tasks
203 function techproject_get_tasks($techproject_id) {
204 global $CFG;
206 $query = "
207 SELECT
208 t.id,
209 t.abstract,
210 t.description,
211 t.projectid,
212 t.groupid,
213 t.owner as userid,
214 u.firstname,
215 u.lastname,
216 'task' as entry_type
217 FROM
218 {$CFG->prefix}techproject_task AS t
219 LEFT JOIN
220 {$CFG->prefix}user AS u
222 t.owner = u.id
223 WHERE
224 t.projectid = '{$techproject_id}'
225 ORDER BY
226 t.taskstart ASC
228 return get_records_sql($query);
229 } //techproject_get_tasks
232 * this function handles the access policy to contents indexed as searchable documents. If this
233 * function does not exist, the search engine assumes access is allowed.
234 * When this point is reached, we already know that :
235 * - user is legitimate in the surrounding context
236 * - user may be guest and guest access is allowed to the module
237 * - the function may perform local checks within the module information logic
238 * @param path the access path to the module script code
239 * @param entry_type the information subclassing (usefull for complex modules, defaults to 'standard')
240 * @param this_id the item id within the information class denoted by entry_type. In techprojects, this id
241 * points to the techproject instance in which all resources are indexed.
242 * @param user the user record denoting the user who searches
243 * @param group_id the current group used by the user when searching
244 * @return true if access is allowed, false elsewhere
246 function techproject_check_text_access($path, $entry_type, $this_id, $user, $group_id, $context_id){
247 global $CFG;
249 include_once("{$CFG->dirroot}/{$path}/lib.php");
251 // get the techproject object and all related stuff
252 $techproject = get_record('techproject', 'id', $this_id);
253 $course = get_record('course', 'id', $techproject->course);
254 $module_context = get_record('context', 'id', $context_id);
255 $cm = get_record('course_modules', 'id', $module_context->instance);
256 if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $module_context)) return false;
258 //group consistency check : checks the following situations about groups
259 // if user is guest check access capabilities for guests :
260 // guests can see default project, and other records if groups are liberal
261 // TODO : change guestsallowed in a capability
262 if (isguest() && $techproject->guestsallowed){
263 if ($group_id && groupmode($course, $cm) == SEPARATEGROUPS)
264 return false;
265 return true;
268 // trap if user is not same group and groups are separated
269 $current_group = get_current_group($course->id);
270 if ((groupmode($course) == SEPARATEGROUPS) && $group_id != $current_group && $group_id) return false;
272 //trap if ungroupedsees is off in strict access mode and user is not teacher
273 if ((groupmode($course) == SEPARATEGROUPS) && !$techproject->ungroupedsees && !$group_id && isteacher($user->id)) return false;
275 return true;
276 } //techproject_check_text_access