lib.php 29.9 KB
Newer Older
Penny Leach's avatar
Penny Leach committed
1
2
<?php
/**
Francois Marier's avatar
Francois Marier committed
3
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
4
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
Penny Leach's avatar
Penny Leach committed
5
 *
Francois Marier's avatar
Francois Marier committed
6
7
8
9
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
Penny Leach's avatar
Penny Leach committed
10
 *
Francois Marier's avatar
Francois Marier committed
11
12
13
14
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
Penny Leach's avatar
Penny Leach committed
15
 *
Francois Marier's avatar
Francois Marier committed
16
17
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
Penny Leach's avatar
Penny Leach committed
18
19
 *
 * @package    mahara
Penny Leach's avatar
Penny Leach committed
20
 * @subpackage artefact-resume
21
 * @author     Catalyst IT Ltd
Penny Leach's avatar
Penny Leach committed
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
23
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
Penny Leach's avatar
Penny Leach committed
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 *
 */

defined('INTERNAL') || die();

class PluginArtefactResume extends Plugin {
    
    public static function get_artefact_types() {
        return array(
            'coverletter', 
            'contactinformation',
            'personalinformation',
            'employmenthistory',
            'educationhistory',
            'certification',
            'book',
            'membership',
            'interest',
42
43
44
45
46
47
            'personalgoal',
            'academicgoal',
            'careergoal',
            'personalskill',
            'academicskill',
            'workskill'
Penny Leach's avatar
Penny Leach committed
48
49
        );
    }
50
51
    
    public static function get_block_types() {
52
        return array(); 
53
    }
Penny Leach's avatar
Penny Leach committed
54
55
56
57
58
59
60
61

    public static function get_plugin_name() {
        return 'resume';
    }

    public static function menu_items() {
        return array(
            array(
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
                'path' => 'profile/myresume',
                'title' => get_string('myresume', 'artefact.resume'),
                'url' => 'artefact/resume/',
                'weight' => 20,
            ),
            array(
                'path' => 'profile/mygoals',
                'title' => get_string('mygoals', 'artefact.resume'),
                'url' => 'artefact/resume/goals.php',
                'weight' => 21,
            ),
            array(
                'path' => 'profile/myskills',
                'title' => get_string('myskills', 'artefact.resume'),
                'url' => 'artefact/resume/skills.php',
                'weight' => 22,
Penny Leach's avatar
Penny Leach committed
78
79
80
81
            )
        );
    }

82
83
84
85
86
87
88
89
90
91
92
93
    public static function get_artefact_type_content_types() {
        return array(
            'coverletter'   => array('text'),
            'interest'      => array('text'),
            'personalgoal'  => array('text'),
            'academicgoal'  => array('text'),
            'careergoal'    => array('text'),
            'personalskill' => array('text'),
            'academicskill' => array('text'),
            'workskill'     => array('text'),
        );
    }
Penny Leach's avatar
Penny Leach committed
94
95
96
97
}

class ArtefactTypeResume extends ArtefactType {

98
    public static function get_icon($options=null) {}
99
100
101
102
103
104
105

    public function __construct($id=0, $data=array()) {
        if (empty($id)) {
            $data['title'] = get_string($this->get_artefact_type(), 'artefact.resume');
        }
        parent::__construct($id, $data);
    }
Penny Leach's avatar
Penny Leach committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
    
    public static function is_singular() {
        return false;
    }

    public static function format_child_data($artefact, $pluginname) {
        $a = new StdClass;
        $a->id         = $artefact->id;
        $a->isartefact = true;
        $a->title      = '';
        $a->text       = get_string($artefact->artefacttype, 'artefact.resume'); // $artefact->title;
        $a->container  = (bool) $artefact->container;
        $a->parent     = $artefact->id;
        return $a;
    }
Penny Leach's avatar
Penny Leach committed
121
122

    public static function get_links($id) {
123
        // @todo Catalyst IT Ltd
Penny Leach's avatar
Penny Leach committed
124
    }
125
126
127
128
129

    /**
     * Default render method for resume fields - show their description
     */
    public function render_self($options) {
130
        return array('html' => clean_html($this->description));
131
    }
132
133
134
135
136
137
138
139

    /**
     * Overrides the default commit to make sure that any 'entireresume' blocks 
     * in views the user have know about this artefact - but only if necessary. 
     * Goals and skills are not in the entireresume block
     *
     * @param boolean $updateresumeblocks Whether to update any resume blockinstances
     */
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    public function commit() {
        parent::commit();

        if ($blockinstances = get_records_sql_array('
            SELECT id, view, configdata
            FROM {block_instance}
            WHERE blocktype = \'entireresume\'
            AND "view" IN (
                SELECT id
                FROM {view}
                WHERE "owner" = ?)', array($this->owner))) {
            foreach ($blockinstances as $blockinstance) {
                $whereobject = (object)array(
                    'view' => $blockinstance->view,
                    'artefact' => $this->get('id'),
                    'block' => $blockinstance->id,
                );
                ensure_record_exists('view_artefact', $whereobject, $whereobject);
158
159
160
            }
        }
    }
Penny Leach's avatar
Penny Leach committed
161
162
163
164
165
166
167
168
}

class ArtefactTypeCoverletter extends ArtefactTypeResume {
    
    public static function is_singular() {
        return true;
    }

169
170
171
172
173
174
175
    public function __construct($id=0, $data=array()) {
        if (empty($id)) {
            $data['title'] = get_string($this->get_artefact_type(), 'artefact.resume');
        }
        parent::__construct($id, $data);
    }

Penny Leach's avatar
Penny Leach committed
176
177
}

178
179
180
181
182
183
184
185
class ArtefactTypeInterest extends ArtefactTypeResume {

    public static function is_singular() {
        return true;
    }

}

Penny Leach's avatar
Penny Leach committed
186
187
class ArtefactTypeContactinformation extends ArtefactTypeResume {

188
    public function render_self($options) {
189
        $smarty = smarty_core();
Penny Leach's avatar
Penny Leach committed
190
191
192
        $fields = ArtefactTypeContactinformation::get_profile_fields();
        foreach ($fields as $f) {
            try {
193
                $$f = artefact_instance_from_type($f, $this->get('owner'));
194
                $rendered = $$f->render_self(array());
195
                $smarty->assign($f, format_whitespace($rendered['html']));
196
                $smarty->assign('hascontent', true);
Penny Leach's avatar
Penny Leach committed
197
198
199
200
201
            }
            catch (Exception $e) { }
        }

        $template = 'artefact:resume:fragments/contactinformation.';
202
        if (!empty($options['editing'])) {
Penny Leach's avatar
Penny Leach committed
203
204
205
            $template .= 'editing.';
        }
        $template .= 'tpl';
206
        return array('html' => $smarty->fetch($template));
Penny Leach's avatar
Penny Leach committed
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
    }

    public static function is_singular() {
        return true;
    }

    public static function setup_new($userid) {
        $artefact = new ArtefactTypeContactinformation(null, array(
            'owner' => $userid,
            'title' => get_string('contactinformation', 'artefact.resume')
        ));
        $artefact->commit();
        return $artefact;
    }

    public static function get_profile_fields() {
        static $fields = array(
            'address', 
            'town',
            'city', 
            'country', 
            'faxnumber',
            'businessnumber',
            'homenumber',
            'mobilenumber'
        );
        return $fields;
    }

}

class ArtefactTypePersonalinformation extends ArtefactTypeResume {
    
240
    protected $composites;
Penny Leach's avatar
Penny Leach committed
241
242
243
244
245
246
247
248

    public function __construct($id=0, $data=null) {
        if (empty($id)) {
            $data['title'] = get_string('personalinformation', 'artefact.resume');
        }
        parent::__construct($id, $data);
        $this->composites = ArtefactTypePersonalinformation::get_composite_fields();
        if (!empty($id)) {
249
250
            $this->composites = (array)get_record('artefact_resume_personal_information', 'artefact', $id,
                null, null, null, null, '*, ' . db_format_tsfield('dateofbirth'));
Penny Leach's avatar
Penny Leach committed
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
        }
    }

    public function set_composite($field, $value) {
        if (!array_key_exists($field, $this->composites)) {
            throw new InvalidArgumentException("Tried to set a non existant composite, $field");
        }
        if ($this->composites[$field] == $value) {
            return true;
        }
        // only set it to dirty if it's changed
        $this->dirty = true;
        $this->mtime = time();
        $this->composites[$field] = $value;
    }   

    public function get_composite($field) {
        return $this->composites[$field];
    }

    public function commit() {
        if (empty($this->dirty)) {
            return true;
        }

        db_begin(); 

        $data = new StdClass;
        foreach ($this->composites as $field => $value) {
280
281
282
            if ($field == 'dateofbirth' && !empty($value)) {
                $value = db_format_timestamp($value);
            }
Penny Leach's avatar
Penny Leach committed
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
            $data->{$field} = $value;
        }   
        $inserting = empty($this->id);
        parent::commit();
        $data->artefact = $this->id;
        if ($inserting) {
            insert_record('artefact_resume_personal_information', $data);
        }
        else {
            update_record('artefact_resume_personal_information', $data, 'artefact');
        }

        db_commit();
    }

    public static function get_composite_fields() {
        static $composites = array(
300
301
302
303
304
305
            'dateofbirth' => null,
            'placeofbirth' => null, 
            'citizenship' => null,
            'visastatus' => null,
            'gender' => null,
            'maritalstatus' => null,
Penny Leach's avatar
Penny Leach committed
306
307
308
309
310
311
312
313
        );
        return $composites;
    }

    public static function is_singular() {
        return true;
    }

314
    public function render_self($options) {
315
        $smarty = smarty_core();
316
317
        $fields = array();
        foreach (array_keys(ArtefactTypePersonalInformation::get_composite_fields()) as $field) {
318
            $value = $this->get_composite($field);
319
            if ($field == 'gender' && !empty($value)) {
320
321
                $value = get_string($value, 'artefact.resume');
            }
322
323
324
            if ($field == 'dateofbirth' && !empty($value)) {
                $value = strftime(get_string('strftimedate'), $value);
            }
325
            $fields[get_string($field, 'artefact.resume')] = $value;
326
327
328
329
330
        }
        $smarty->assign('fields', $fields);
        return array('html' => $smarty->fetch('artefact:resume:fragments/personalinformation.tpl'));
    }

331
332
333
334
335
336
337
338
    public function delete() {
        db_begin();

        delete_records('artefact_resume_personal_information', 'artefact', $this->id);
        parent::delete();

        db_commit();
    }
Penny Leach's avatar
Penny Leach committed
339
340
341
342
}



Penny Leach's avatar
Penny Leach committed
343
abstract class ArtefactTypeResumeComposite extends ArtefactTypeResume {
Penny Leach's avatar
Penny Leach committed
344

345
346
347
348
    public static function is_singular() {
        return true;
    }

Penny Leach's avatar
Penny Leach committed
349
350
351
352
353
354
355
356
357
    public static function get_composite_artefact_types() {
        return array(
            'employmenthistory',
            'educationhistory',
            'certification',
            'book',
            'membership'
        );
    }
Penny Leach's avatar
Penny Leach committed
358

Penny Leach's avatar
Penny Leach committed
359
360
361
362
363
    /**
    * This function should return a snippet of javascript
    * to be plugged into a table renderer instantiation
    * it comprises the cell function definition
    */
Penny Leach's avatar
Penny Leach committed
364
    public static abstract function get_tablerenderer_js();
Penny Leach's avatar
Penny Leach committed
365

366
367
368
369
    public static abstract function get_tablerenderer_title_js_string();

    public static abstract function get_tablerenderer_body_js_string();

370
371
372
373
374
375
376
377
    /**
     * Can be overridden to format data retrieved from artefact tables for 
     * display of the resume artefact by render_self
     */
    public static function format_render_self_data($data) {
        return $data;
    }

Penny Leach's avatar
Penny Leach committed
378
379
380
381
382
383
384
385
386
387
388
389
    /** 
    * This function should return an array suitable to 
    * put into the 'elements' part of a pieform array
    * to generate a form to add an instance
    */
    public static abstract function get_addform_elements();

    /**
    * This function processes the form for the composite
    * @throws Exception
    */
    public static function process_compositeform(Pieform $form, $values) {
390
391
392
        global $USER;
        self::ensure_composite_value($values, $values['compositetype'], $USER->get('id'));
    }
393

394
395
396
397
398
399
400
401
    /**
     * Ensures that the given value for the given composite is present
     * TODO: expand on these docs.
     */
    public static function ensure_composite_value($values, $compositetype, $owner) {
        if (!in_array($compositetype, self::get_composite_artefact_types())) {
            throw new SystemException("ensure_composite_value called with invalid composite type");
        }
402
        try {
403
            $a = artefact_instance_from_type($compositetype, $owner);
404
405
406
            $a->set('mtime', time());
        }
        catch (Exception $e) {
407
            $classname = generate_artefact_class_name($compositetype);
408
            $a = new $classname(0, array(
409
410
                'owner' => $owner,
                'title' => get_string($compositetype, 'artefact.resume'),
411
412
                )
            );
413
        }
414
415
416
417
418

        $a->commit();

        $values['artefact'] = $a->get('id');

419
        $table = 'artefact_resume_' . $compositetype;
420
421
        if (!empty($values['id'])) {
            update_record($table, (object)$values, 'id');
Penny Leach's avatar
Penny Leach committed
422
423
        }
        else {
424
425
            $max = get_field($table, 'MAX(displayorder)', 'artefact', $values['artefact']);
            $values['displayorder'] = is_numeric($max) ? $max + 1 : 0;
426
            insert_record($table, (object)$values);
Penny Leach's avatar
Penny Leach committed
427
428
        }
    }
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449

    public function delete() {
        $table = $this->get_other_table_name();
        db_begin();

        delete_records($table, 'artefact', $this->id);
        parent::delete();

        db_commit();
    }


    /**
    * Takes a pieform that's been set up by all the 
    * subclass get_addform_elements functions
    * and puts the default values in (and hidden id field)
    * ready to be an edit form
    * 
    * @param $form pieform structure (before calling pieform() on it
    * passed by _reference_
    */
450
451
452
453
454
    public static function populate_form(&$form, $id, $type) {
        if (!$composite = get_record('artefact_resume_' . $type, 'id', $id)) {
            throw new InvalidArgumentException("Couldn't find composite of type $type with id $id");
        }
        $datetypes = array('date', 'startdate', 'enddate');
455
456
457
458
        foreach ($form['elements'] as $k => $element) {
            if ($k == 'submit' || $k == 'compositetype') {
                continue;
            }
459
            if (isset($composite->{$k})) {
460
                $form['elements'][$k]['defaultvalue'] = $composite->{$k};
461
462
463
464
            }
        }
        $form['elements']['id'] = array(
            'type' => 'hidden',
465
466
467
468
469
            'value' => $id,
        );
        $form['elements']['artefact'] = array(
            'type' => 'hidden',
            'value' => $composite->artefact,
470
471
472
473
474
475
476
477
478
479
480
        );
    }


    /** 
    * call the parent constructor
    * and then load up the stuff from the supporting table
    */
    public function __construct($id=0, $data=array()) {
        if (empty($id)) {
            $data['container'] = 0;
481
            $data['title'] = get_string($this->get_artefact_type(), 'artefact.resume');
482
483
        }
        parent::__construct($id, $data);
484
    }    
485
486
487
488
489
490
491

    /** 
    * returns the name of the supporting table
    */
    public function get_other_table_name() {
        return 'artefact_resume_' . $this->get_artefact_type();
    }
492

493
    public function render_self($options) {
494
        global $USER;
495
        $suffix = '_' . substr(md5(microtime()), 0, 4);
496
        $smarty = smarty_core();
497
        $smarty->assign('hidetitle', true);
498
        $smarty->assign('suffix', $suffix);
499
        $type = $this->get('artefacttype');
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
        $othertable = 'artefact_resume_' . $type;
        $owner = $USER->get('id');

        $sql = 'SELECT ar.*, a.owner
            FROM {artefact} a 
            JOIN {' . $othertable . '} ar ON ar.artefact = a.id
            WHERE a.owner = ? AND a.artefacttype = ?
            ORDER BY ar.displayorder';

        if (!empty($options['viewid'])) { 
            if (!can_view_view($options['viewid'])) {
                throw new AccessDeniedException();
            }
            require_once('view.php');
            $v = new View($options['viewid']);
            $owner = $v->get('owner');
        }

        if (!$data = get_records_sql_array($sql, array($owner, $type))) {
            $data = array();
        }

        // Give the artefact type a chance to format the data how it sees fit
        $data = call_static_method(generate_artefact_class_name($type), 'format_render_self_data', $data);
        $smarty->assign('rows', $data);

526
527
        $content = array(
            'html'         => $smarty->fetch('artefact:resume:fragments/' . $type . '.tpl'),
528
529
            'javascript'   => $this->get_showhide_composite_js()
        );
530
531
532
        return $content;
    }

533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
    static function get_tablerenderer_title_js($titlestring, $bodystring) {
        return "
                function (r, d) {
                    if (!{$bodystring}) {
                        return TD(null, {$titlestring});
                    }
                    var link = A({'href': ''}, {$titlestring});
                    connect(link, 'onclick', function (e) {
                        e.stop();
                        return showhideComposite(r, {$bodystring});
                    });
                    return TD({'id': 'composite-' + r.artefact + '-' + r.id}, link);
                },
                ";
    }

    static function get_showhide_composite_js() {
        return "
            function showhideComposite(r, content) {
                // get the reference for the title we just clicked on
                var titleTD = $('composite-' + r.artefact + '-' + r.id);
                var theRow = titleTD.parentNode;
                var bodyRow = $('composite-body-' + r.artefact +  '-' + r.id);
                if (bodyRow) {
                    if (hasElementClass(bodyRow, 'hidden')) {
                        removeElementClass(bodyRow, 'hidden');
                    }
                    else {
                        addElementClass(bodyRow, 'hidden');
                    }
                    return false;
                }
                // we have to actually create the dom node too
                var colspan = theRow.childNodes.length;
                var newRow = TR({'id': 'composite-body-' + r.artefact + '-' + r.id}, 
                    TD({'colspan': colspan}, content)); 
                insertSiblingNodesAfter(theRow, newRow);
            }
        ";
    }
Penny Leach's avatar
Penny Leach committed
573
}
Penny Leach's avatar
Penny Leach committed
574

Penny Leach's avatar
Penny Leach committed
575
class ArtefactTypeEmploymenthistory extends ArtefactTypeResumeComposite { 
Penny Leach's avatar
Penny Leach committed
576
577
578
579
580

    protected $startdate;
    protected $enddate;
    protected $employer;

Penny Leach's avatar
Penny Leach committed
581
582
583
584
    public static function get_tablerenderer_js() {
        return "
                'startdate',
                'enddate',
585
586
587
588
                " . ArtefactTypeResumeComposite::get_tablerenderer_title_js(
                    self::get_tablerenderer_title_js_string(),
                    self::get_tablerenderer_body_js_string()
                ) . "
Penny Leach's avatar
Penny Leach committed
589
590
        ";
    }
Penny Leach's avatar
Penny Leach committed
591

592
    public static function get_tablerenderer_title_js_string() {
593
        return " r.jobtitle + ' : ' + r.employer";
594
595
596
597
598
    }

    public static function get_tablerenderer_body_js_string() {
        return " r.positiondescription";
    }
599

Penny Leach's avatar
Penny Leach committed
600
601
602
    public static function get_addform_elements() {
        return array(
            'startdate' => array(
603
                'type' => 'text',
Penny Leach's avatar
Penny Leach committed
604
605
606
607
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('startdate', 'artefact.resume'),
608
                'help' => true,
Penny Leach's avatar
Penny Leach committed
609
610
            ),
            'enddate' => array(
611
                'type' => 'text', 
Penny Leach's avatar
Penny Leach committed
612
613
614
615
616
617
618
619
620
                'title' => get_string('enddate', 'artefact.resume'),
            ),
            'employer' => array(
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('employer', 'artefact.resume'),
            ),
621
            'jobtitle' => array(
Penny Leach's avatar
Penny Leach committed
622
623
624
625
626
627
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('jobtitle', 'artefact.resume'),
            ),
628
            'positiondescription' => array(
Penny Leach's avatar
Penny Leach committed
629
630
631
632
633
634
635
636
                'type' => 'textarea',
                'rows' => 10,
                'cols' => 50,
                'resizable' => false,
                'title' =>  get_string('jobdescription', 'artefact.resume'),
            ),
        );
    }
Penny Leach's avatar
Penny Leach committed
637
}
Penny Leach's avatar
Penny Leach committed
638

Penny Leach's avatar
Penny Leach committed
639
class ArtefactTypeEducationhistory extends ArtefactTypeResumeComposite {
Penny Leach's avatar
Penny Leach committed
640
641
642
643
644
645

    protected $startdate;
    protected $enddate;
    protected $qualtype;
    protected $institution;

Penny Leach's avatar
Penny Leach committed
646
    public static function get_tablerenderer_js() {
647

Penny Leach's avatar
Penny Leach committed
648
649
650
        return "
                'startdate',
                'enddate',
651
652
653
654
                " . ArtefactTypeResumeComposite::get_tablerenderer_title_js(
                    self::get_tablerenderer_title_js_string(),
                    self::get_tablerenderer_body_js_string()
                ) . "
Penny Leach's avatar
Penny Leach committed
655
656
        ";
    }
657
658
659
660
661
662

    public static function get_tablerenderer_title_js_string() {
        $at = get_string('at');
        return " r.qualname + ' (' + r.qualtype + ') {$at} ' + r.institution";
    }

663
664
665
666
667
668
669
670
    public static function format_render_self_data($data) {
        $at = get_string('at');
        foreach ($data as &$row) {
            $row->qualification = $row->qualname . ' (' . $row->qualtype . ")  $at " . $row->institution;
        }
        return $data;
    }

671
672
673
674
    public static function get_tablerenderer_body_js_string() {
        return " r.qualdescription"; 
    }

Penny Leach's avatar
Penny Leach committed
675
676
677
    public static function get_addform_elements() {
        return array(
            'startdate' => array(
678
                'type' => 'text',
Penny Leach's avatar
Penny Leach committed
679
680
681
682
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('startdate', 'artefact.resume'),
683
                'help' => true,
Penny Leach's avatar
Penny Leach committed
684
685
            ),
            'enddate' => array(
686
                'type' => 'text', 
Penny Leach's avatar
Penny Leach committed
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
                'title' => get_string('enddate', 'artefact.resume'),
            ),
            'institution' => array(
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('institution', 'artefact.resume'),
            ),
            'qualtype' => array(
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('qualtype', 'artefact.resume'),
            ),
703
            'qualname' => array(
Penny Leach's avatar
Penny Leach committed
704
705
706
707
708
709
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('qualname', 'artefact.resume'),
            ),
710
            'qualdescription' => array(
Penny Leach's avatar
Penny Leach committed
711
712
713
714
715
716
717
718
                'type' => 'textarea',
                'rows' => 10,
                'cols' => 50,
                'resizable' => false,
                'title' => get_string('qualdescription', 'artefact.resume'),
            ),
        );
    }
Penny Leach's avatar
Penny Leach committed
719
720
721
}

class ArtefactTypeCertification extends ArtefactTypeResumeComposite { 
Penny Leach's avatar
Penny Leach committed
722
723
724

    protected $date;

Penny Leach's avatar
Penny Leach committed
725
726
727
    public static function get_tablerenderer_js() {
        return "
                'date',
728
729
730
731
                " . ArtefactTypeResumeComposite::get_tablerenderer_title_js(
                    self::get_tablerenderer_title_js_string(),
                    self::get_tablerenderer_body_js_string()
                ) . "
Penny Leach's avatar
Penny Leach committed
732
733
        ";
    }
734
735
736
737
738
739
740
741
742

    public static function get_tablerenderer_title_js_string() {
        return "r.title";
    }

    public static function get_tablerenderer_body_js_string() {
        return "r.description";
    }

Penny Leach's avatar
Penny Leach committed
743
744
745
    public static function get_addform_elements() {
        return array(
            'date' => array(
746
                'type' => 'text',
Penny Leach's avatar
Penny Leach committed
747
748
749
750
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('date', 'artefact.resume'),
751
                'help' => true,
Penny Leach's avatar
Penny Leach committed
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
            ),
            'title' => array(
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('title', 'artefact.resume'),
            ),
            'description' => array(
                'type' => 'textarea',
                'rows' => 10,
                'cols' => 50,
                'resizable' => false,
                'title' => get_string('description'),
            ),
        );
    }
Penny Leach's avatar
Penny Leach committed
769
}
Penny Leach's avatar
Penny Leach committed
770

Penny Leach's avatar
Penny Leach committed
771
class ArtefactTypeBook extends ArtefactTypeResumeComposite {
Penny Leach's avatar
Penny Leach committed
772
773
774
775

    protected $date;
    protected $contribution;

Penny Leach's avatar
Penny Leach committed
776
777
778
    public static function get_tablerenderer_js() {
        return "
                'date',
779
780
781
782
                " . ArtefactTypeResumeComposite::get_tablerenderer_title_js(
                    self::get_tablerenderer_title_js_string(),
                    self::get_tablerenderer_body_js_string()
                ) . "
Penny Leach's avatar
Penny Leach committed
783
784
        ";
    }
785
786
787
788
789
790
791
792
793

    public static function get_tablerenderer_title_js_string() {
        return "r.title + ' (' + r.contribution + ')'";
    }

    public static function get_tablerenderer_body_js_string() {
        return "r.description";
    }

Penny Leach's avatar
Penny Leach committed
794
795
796
    public static function get_addform_elements() {
        return array(
            'date' => array(
797
                'type' => 'text',
Penny Leach's avatar
Penny Leach committed
798
799
800
801
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('date', 'artefact.resume'),
802
                'help' => true,
Penny Leach's avatar
Penny Leach committed
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
            ),
            'title' => array(
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('title', 'artefact.resume'),
            ),
            'contribution' => array(
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('contribution', 'artefact.resume'),
            ),
            'description' => array(
                'type' => 'textarea',
                'rows' => 10,
                'cols' => 50,
                'resizable' => false,
823
                'title' => get_string('description', 'artefact.resume'),
Penny Leach's avatar
Penny Leach committed
824
825
826
            ),
        );
    }
Penny Leach's avatar
Penny Leach committed
827
}
Penny Leach's avatar
Penny Leach committed
828

Penny Leach's avatar
Penny Leach committed
829
class ArtefactTypeMembership extends ArtefactTypeResumeComposite { 
Penny Leach's avatar
Penny Leach committed
830

831
832
    protected $startdate;
    protected $enddate;
Penny Leach's avatar
Penny Leach committed
833

Penny Leach's avatar
Penny Leach committed
834
835
836
837
    public static function get_tablerenderer_js() {
        return "
                'startdate',
                'enddate',
838
839
840
841
                " . ArtefactTypeResumeComposite::get_tablerenderer_title_js(
                    self::get_tablerenderer_title_js_string(),
                    self::get_tablerenderer_body_js_string()
                ) . "
Penny Leach's avatar
Penny Leach committed
842
843
        ";
    }
844
845
846
847
848
849
850
851
852

    public static function get_tablerenderer_title_js_string() {
        return "r.title";
    }
   
    public static function get_tablerenderer_body_js_string() {
        return "r.description";
    }

Penny Leach's avatar
Penny Leach committed
853
854
855
    public static function get_addform_elements() {
        return array(
            'startdate' => array(
856
                'type' => 'text',
Penny Leach's avatar
Penny Leach committed
857
858
859
860
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('startdate', 'artefact.resume'),
861
                'help' => true,
Penny Leach's avatar
Penny Leach committed
862
863
            ),
            'enddate' => array(
864
                'type' => 'text', 
Penny Leach's avatar
Penny Leach committed
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
                'title' => get_string('enddate', 'artefact.resume'),
            ),
            'title' => array(
                'type' => 'text',
                'rules' => array(
                    'required' => true,
                ),
                'title' => get_string('title', 'artefact.resume'),
            ),
            'description' => array(
                'type' => 'textarea',
                'rows' => 10,
                'cols' => 50,
                'resizable' => false,
                'title' => get_string('description', 'artefact.resume'),
            ),
        );
    }
Penny Leach's avatar
Penny Leach committed
883
}
Penny Leach's avatar
Penny Leach committed
884

885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
class ArtefactTypeResumeGoalAndSkill extends ArtefactTypeResume {

    public static function is_singular() {
        return true;
    }

    public static function get_goalandskill_artefact_types() {
        return array('personalgoal', 'academicgoal', 'careergoal',
            'personalskill', 'academicskill', 'workskill');
    }

}

class ArtefactTypePersonalgoal extends ArtefactTypeResumeGoalAndSkill { }
class ArtefactTypeAcademicgoal extends ArtefactTypeResumeGoalAndSkill { }
class ArtefactTypeCareergoal extends ArtefactTypeResumeGoalAndSkill { }
class ArtefactTypePersonalskill extends ArtefactTypeResumeGoalAndSkill { }
class ArtefactTypeAcademicskill extends ArtefactTypeResumeGoalAndSkill { }
class ArtefactTypeWorkskill extends ArtefactTypeResumeGoalAndSkill { }

function compositeform_submit(Pieform $form, $values) {
    try {
        call_static_method(generate_artefact_class_name($values['compositetype']), 
            'process_compositeform', $form, $values);
    }
    catch (Exception $e) {
        $form->json_reply(PIEFORM_ERR, $e->getMessage());
    }
    $form->json_reply(PIEFORM_OK, get_string('compositesaved', 'artefact.resume'));
}

916
917
918
919
920
921
922
923
924
925
926
927
928
929
function compositeformedit_submit(Pieform $form, $values) {
    global $SESSION;
    try {
        call_static_method(generate_artefact_class_name($values['compositetype']),
            'process_compositeform', $form, $values);
    }
    catch (Exception $e) {
        $SESSION->add_error_msg(get_string('compositesavefailed', 'artefact.resume'));
        redirect('/artefact/resume/');
    }
    $SESSION->add_ok_msg(get_string('compositesaved', 'artefact.resume'));
    redirect('/artefact/resume/');
}

930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
function goalandskillform_submit(Pieform $form, $values) {
    foreach ($values as $key => $value) {
        if (!in_array($key, ArtefactTypeResumeGoalAndSkill::get_goalandskill_artefact_types())) {
            continue;
        }
        try {
            $a = artefact_instance_from_type($key);
            $a->set('description', $value);
        }
        catch (Exception $e) {
            global $USER;
            $classname = generate_artefact_class_name($key);
            $a = new $classname(0, array(
                'owner' => $USER->get('id'),
                'title' => get_string($key),
                'description' => $value,
           )); 
        }
        $a->commit();
    }
    $form->json_reply(PIEFORM_OK, get_string('goalandskillsaved', 'artefact.resume'));
}   
Penny Leach's avatar
Penny Leach committed
952
953

?>