3 * Global Search Engine for Moodle
7 * @subpackage document_wrappers
8 * @author Michael Campanis, Valery Fremaux [valery.fremaux@club-internet.fr] > 1.8
10 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
12 * document handling for techproject activity module
16 * requires and includes
18 require_once("$CFG->dirroot/search/documents/document.php");
19 require_once("$CFG->dirroot/mod/techproject/lib.php");
22 * a class for representing searchable information
25 class TechprojectEntrySearchDocument
extends SearchDocument
{
31 public function __construct(&$entry, $course_id, $context_id) {
32 // generic information
33 $doc->docid
= $entry['id'];
34 $doc->documenttype
= SEARCH_TYPE_TECHPROJECT
;
35 $doc->itemtype
= $entry['entry_type'];
36 $doc->contextid
= $context_id;
39 $doc->title
= $entry['abstract'];
40 $doc->author
= ($entry['userid']) ?
$entry['author'] : '';
41 $doc->contents
= strip_tags($entry['description']);
44 $doc->url
= techproject_make_link($entry['projectid'], $entry['id'], $entry['entry_type'], $entry['groupid']);
46 // module specific information
47 $data->techproject
= $entry['projectid'];
49 parent
::__construct($doc, $data, $course_id, $entry['groupid'], $entry['userid'], PATH_FOR_SEARCH_TYPE_TECHPROJECT
);
51 } //TechprojectEntrySearchDocument
54 * constructs a valid link to a description detail
57 function techproject_make_link($techproject_id, $entry_id, $entry_type, $group_id) {
59 return $CFG->wwwroot
.'/mod/techproject/view.php?view=view_detail&id='.$techproject_id.'&objectId='.$entry_id.'&objectClass='.$entry_type.'&group='.$group_id;
60 } //techproject_make_link
66 function techproject_iterator() {
67 $techprojects = get_records('techproject');
69 } //techproject_iterator
73 * @param techproject a techproject instance
74 * @return an array of collected searchable documents
76 function techproject_get_content_for_index(&$techproject) {
78 if (!$techproject) return $documents;
80 $requirements = techproject_get_entries($techproject->id
, 'requirement');
81 $specifications = techproject_get_entries($techproject->id
, 'specification');
82 $tasks = techproject_get_tasks($techproject->id
);
83 $milestones = techproject_get_entries($techproject->id
, 'milestone');
84 $deliverables = techproject_get_entries($techproject->id
, 'deliverable');
85 $coursemodule = get_field('modules', 'id', 'name', 'techproject');
86 $cm = get_record('course_modules', 'course', $techproject->course
, 'module', $coursemodule, 'instance', $techproject->id
);
87 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
89 $entries = @array_merge
($requirements, $specifications, $milestones, $deliverables);
91 foreach($entries as $anEntry) {
93 if (strlen($anEntry->description
) > 0) {
94 $anEntry->author
= '';
95 $documents[] = new TechprojectEntrySearchDocument(get_object_vars($anEntry), $techproject->course
, $context->id
);
101 foreach($tasks as $aTask) {
103 if (strlen($aTask->description
) > 0) {
104 if ($aTask->assignee
){
105 $user = get_record('user', 'id', $aTask->assignee
);
106 $aTask->author
= $user->firstname
.' '.$user->lastname
;
108 $documents[] = new TechprojectEntrySearchDocument(get_object_vars($aTask), $techproject->course
, $context->id
);
114 } //techproject_get_content_for_index
117 * returns a single techproject search document based on a techproject_entry id and itemtype
120 function techproject_single_document($id, $itemtype) {
123 $entry = get_record('techproject_requirement', 'id', $id);
127 case 'specification':{
128 $entry = get_record('techproject_specification', 'id', $id);
133 $entry = get_record('techproject_milestone', 'id', $id);
138 $entry = get_record('techproject_deliverable', 'id', $id);
143 $entry = get_record('techproject_task', 'id', $id);
144 if ($entry->assignee
){
145 $user = get_record('user', 'id', $entry->assignee
);
146 $entry->author
= $user->firstname
.' '.$user->lastname
;
151 $techproject_course = get_field('techproject', 'course', 'id', $entry->projectid
);
152 $coursemodule = get_field('modules', 'id', 'name', 'techproject');
153 $cm = get_record('course_modules', 'course', $techproject_course, 'module', $coursemodule, 'instance', $entry->projectid
);
154 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
155 $entry->type
= $itemtype;
156 $techproject = get_record('techproject', 'id', $requirement->projectid
);
157 return new TechprojectEntrySearchDocument(get_object_vars($anEntry), $techproject->course
, $context->id
);
158 } //techproject_single_document
161 * dummy delete function that packs id with itemtype.
162 * this was here for a reason, but I can't remember it at the moment.
165 function techproject_delete($info, $itemtype) {
167 $object->itemtype
= $itemtype;
169 } //techproject_delete
172 * returns the var names needed to build a sql query for addition/deletions
175 // TODO : what should we do there ?
176 function techproject_db_names() {
177 //[primary id], [table name], [time created field name], [time modified field name]
179 array('id', 'techproject_requirement', 'created', 'modified', 'requirement'),
180 array('id', 'techproject_specification', 'created', 'modified', 'specification'),
181 array('id', 'techproject_task', 'created', 'modified', 'task'),
182 array('id', 'techproject_milestone', 'created', 'modified', 'milestone'),
183 array('id', 'techproject_deliverable', 'created', 'modified', 'deliverable')
185 } //techproject_db_names
188 * get a complete list of entries of one particular type
189 * @param techprojectId the project instance
190 * @param type the entity type
191 * @return an array of records
193 function techproject_get_entries($techproject_id, $type) {
204 '$type' AS entry_type
206 {$CFG->prefix}techproject_{$type} AS e
208 e.projectid = '{$techproject_id}'
210 return get_records_sql($query);
211 } //techproject_get_entries
214 * get the task list for a project instance
215 * @param techprojectId the project
216 * @return an array of records that represent tasks
218 function techproject_get_tasks($techproject_id) {
233 {$CFG->prefix}techproject_task AS t
235 {$CFG->prefix}user AS u
239 t.projectid = '{$techproject_id}'
243 return get_records_sql($query);
244 } //techproject_get_tasks
247 * this function handles the access policy to contents indexed as searchable documents. If this
248 * function does not exist, the search engine assumes access is allowed.
249 * When this point is reached, we already know that :
250 * - user is legitimate in the surrounding context
251 * - user may be guest and guest access is allowed to the module
252 * - the function may perform local checks within the module information logic
253 * @param path the access path to the module script code
254 * @param entry_type the information subclassing (usefull for complex modules, defaults to 'standard')
255 * @param this_id the item id within the information class denoted by entry_type. In techprojects, this id
256 * points to the techproject instance in which all resources are indexed.
257 * @param user the user record denoting the user who searches
258 * @param group_id the current group used by the user when searching
259 * @return true if access is allowed, false elsewhere
261 function techproject_check_text_access($path, $entry_type, $this_id, $user, $group_id, $context_id){
264 include_once("{$CFG->dirroot}/{$path}/lib.php");
266 // get the techproject object and all related stuff
267 $techproject = get_record('techproject', 'id', $this_id);
268 $course = get_record('course', 'id', $techproject->course
);
269 $module_context = get_record('context', 'id', $context_id);
270 $cm = get_record('course_modules', 'id', $module_context->instanceid
);
271 if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $module_context)) return false;
273 //group consistency check : checks the following situations about groups
274 // if user is guest check access capabilities for guests :
275 // guests can see default project, and other records if groups are liberal
276 // TODO : change guestsallowed in a capability
277 if (isguest() && $techproject->guestsallowed
){
278 if ($group_id && groupmode($course, $cm) == SEPARATEGROUPS
)
283 // trap if user is not same group and groups are separated
284 $current_group = get_current_group($course->id
);
285 if ((groupmode($course) == SEPARATEGROUPS
) && $group_id != $current_group && $group_id) return false;
287 //trap if ungroupedsees is off in strict access mode and user is not teacher
288 if ((groupmode($course) == SEPARATEGROUPS
) && !$techproject->ungroupedsees
&& !$group_id && isteacher($user->id
)) return false;
291 } //techproject_check_text_access
294 * this call back is called when displaying the link for some last post processing
297 function techproject_link_post_processing($title){
298 return mb_convert_encoding($title, 'UTF-8', 'auto');