Logo Search packages:      
Sourcecode: mahara version File versions  Download package

lib.php

<?php
/**
 * Mahara: Electronic portfolio, weblog, resume builder and social networking
 * Copyright (C) 2006-2008 Catalyst IT Ltd (http://www.catalyst.net.nz)
 *
 * 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.
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    mahara
 * @subpackage artefact-internal
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL
 * @copyright  (C) 2006-2008 Catalyst IT Ltd http://catalyst.net.nz
 *
 */

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

00029 class PluginArtefactInternal extends PluginArtefact {

00031     public static function get_artefact_types() {
        return array(
            'firstname',
            'lastname',
            'studentid',
            'preferredname',
            'introduction',
            'email',
            'officialwebsite',
            'personalwebsite',
            'blogaddress',
            'address',
            'town',
            'city',
            'country',
            'homenumber',
            'businessnumber',
            'mobilenumber',
            'faxnumber',
            'icqnumber',
            'msnnumber',
            'aimscreenname',
            'yahoochat',
            'skypeusername',
            'jabberusername',
            'occupation',
            'industry',
            'profileicon'
        );
    }

    public static function get_contactinfo_artefact_types() {
        return array(
            'email',
            'officialwebsite',
            'personalwebsite',
            'blogaddress',
            'address',
            'town',
            'city',
            'country',
            'homenumber',
            'businessnumber',
            'mobilenumber',
            'faxnumber',
            'icqnumber',
            'msnnumber',
            'aimscreenname',
            'yahoochat',
            'skypeusername',
            'jabberusername',
        );
    }
    
00085     public static function get_block_types() {
        return array();
    }

00089     public static function get_plugin_name() {
        return 'internal';
    }

00093     public static function menu_items() {
        return array(
            array(
                'path' => 'profile',
                'url'  => 'artefact/internal/', // @todo possibly do path aliasing and dispatch?
                'title' => get_string('profile', 'artefact.internal'),
                'weight' => 20,
            ),
            array(
                'path' => 'profile/edit',
                'url' => 'artefact/internal/',
                'title' => get_string('editprofile', 'artefact.internal'),
                'weight' => 10,
            ),
            array(
                'path' => 'profile/icons',
                'url' => 'artefact/internal/profileicons.php',
                'title' => get_string('profileicons', 'artefact.internal'),
                'weight' => 11,
            ),
        );
    }

00116     public static function get_cron() {
        return array(
            (object)array(
                'callfunction' => 'clean_email_validations',
                'hour'         => '4',
                'minute'       => '10',
            ),
        );
    }

    public static function clean_email_validations() {
        delete_records_select('artefact_internal_profile_email', 'verified=0 AND expiry IS NOT NULL AND expiry < ?', array(db_format_timestamp(time())));
    }

    public static function sort_child_data($a, $b) {
        return strnatcasecmp($a->text, $b->text);
    }
}

00135 class ArtefactTypeProfile extends ArtefactType {

    /**
     * overriding this because profile fields
     * are unique in that except for email, you only get ONE
     * so if we don't get an id, we still need to go look for it
     */
00142     public function __construct($id=0, $data=null) {
        $type = $this->get_artefact_type();
        if (!empty($id) || $type == 'email') {
            return parent::__construct($id, $data);
        }
        if (!empty($data['owner'])) {
            if ($a = get_record('artefact', 'artefacttype', $type, 'owner', $data['owner'])) {
                return parent::__construct($a->id, $a);
            } 
            else {
                $this->owner = $data['owner'];
            }
        } 
        $this->ctime = time();
        $this->atime = time();
        $this->artefacttype = $type;
        if (empty($id)) {
            $this->dirty = true;
            $this->ctime = $this->mtime = time();
            if (empty($data)) {
                $data = array();
            }
            foreach ((array)$data as $field => $value) {
                if (property_exists($this, $field)) {
                    $this->{$field} = $value;
                }
            }
        }
    }

    public function set($field, $value) {
        if ($field == 'title' && empty($value)) {
            return $this->delete();
        }
        return parent::set($field, $value);
    }

00179     public static function get_icon($options=null) {

    }

00183     public static function is_singular() {
        return true;
    }
    
    public static function get_all_fields() {
        return array(
            'firstname'       => 'text',
            'lastname'        => 'text',
            'studentid'       => 'text',
            'preferredname'   => 'text',
            'introduction'    => 'wysiwyg',
            'email'           => 'emaillist',
            'officialwebsite' => 'text',
            'personalwebsite' => 'text',
            'blogaddress'     => 'text',
            'address'         => 'textarea',
            'town'            => 'text',
            'city'            => 'text',
            'country'         => 'select',
            'homenumber'      => 'text',
            'businessnumber'  => 'text',
            'mobilenumber'    => 'text',
            'faxnumber'       => 'text',
            'icqnumber'       => 'text',
            'msnnumber'       => 'text',
            'aimscreenname'   => 'text',
            'yahoochat'       => 'text',
            'skypeusername'   => 'text',
            'jabberusername'  => 'text',
            'occupation'      => 'text',
            'industry'        => 'text',
        );
    }

    public static function get_mandatory_fields() {
        $m = array();
        $all = self::get_all_fields();
        $alwaysm = self::get_always_mandatory_fields();
        if ($man = get_config_plugin('artefact', 'internal', 'profilemandatory')) {
            $mandatory = explode(',', $man);
        }
        else {
            $mandatory = array();
        }
        foreach ($mandatory as $mf) {
            $m[$mf] = $all[$mf];
        }
        return array_merge($m, $alwaysm);
    }

    public static function get_always_mandatory_fields() {
        return array(
            'firstname' => 'text', 
            'lastname'  => 'text', 
            'email'     => 'emaillist',
        );
    }

    public static function get_public_fields() {
        $all = self::get_all_fields();
        $alwaysp = self::get_always_public_fields();
        $p = array();
        if ($pub = get_config_plugin('artefact', 'internal', 'profilepublic')) {
            $public = explode(',', $pub);
        }
        else {
            $public = array();
        }
        foreach ($public as $pf) {
            $p[$pf] = $all[$pf];
        }
        return array_merge($p, $alwaysp);
    }

    public static function get_always_public_fields() {
        return array(
            'introduction' => 'wysiwyg'
        );
    }

    public static function has_config() {
        return true;
    }

    public static function get_config_options() {
        $mandatory = self::get_mandatory_fields();
        $public = self::get_public_fields();
        $alwaysmandatory = self::get_always_mandatory_fields();
        $alwayspublic = self::get_always_public_fields();
        $form = array(
            'renderer'   => 'multicolumntable',
            'elements'   => array(
                'mandatory' =>  array(
                    'title' => ' ', 
                    'type'  => 'html',
                    'class' => 'header',
                    'value' => get_string('mandatory', 'artefact.internal'),
                ),
                'public' => array(
                    'title' => ' ', 
                    'class' => 'header',
                    'type'  => 'html',
                    'value' => get_string('public', 'artefact.internal'),
                )
            ),
        );

        foreach (array_keys(self::get_all_fields()) as $field) {
            $form['elements'][$field . '_mandatory'] = array(
                'defaultvalue' => ((isset($mandatory[$field])) ? 'checked' : ''),
                'title'        => get_string($field, 'artefact.internal'),
                'type'         => 'checkbox',
            );
            if (isset($alwaysmandatory[$field])) {
                $form['elements'][$field . '_mandatory']['value'] = 'checked';
                $form['elements'][$field . '_mandatory']['disabled'] = true;
            }
            $form['elements'][$field . '_public'] = array(
                'defaultvalue' => ((isset($public[$field])) ? 'checked' : ''),
                'title'        => get_string($field, 'artefact.internal'),
                'type'         => 'checkbox',

            );
            if (isset($alwayspublic[$field])) {
                $form['elements'][$field . '_public']['value'] = 'checked';
                $form['elements'][$field . '_public']['disabled'] = true;
            }
        }

        $form['elements']['emptyrow'] = array(
            'title' => '    ',
            'type' => 'html',
            'value' => '&nbsp;',
        );
        $currentwidth = get_config_plugin('artefact', 'internal', 'profileiconwidth');
        $form['elements']['profileiconwidth'] = array(
            'type' => 'text',
            'size' => 4,
            'suffix' => get_string('widthshort'),
            'title' => get_string('profileiconsize', 'artefact.internal'),
            'defaultvalue' => ((!empty($currentwidth)) ? $currentwidth : 100),
            'rules' => array(
                'required' => true,
                'integer'  => true,
            )
        );
        $currentheight = get_config_plugin('artefact', 'internal', 'profileiconheight');
        $form['elements']['profileiconheight'] = array(
            'type' => 'text',
            'suffix' => get_string('heightshort'),
            'size' => 4,
            'title' => get_string('profileiconsize', 'artefact.internal'),
            'defaultvalue' => ((!empty($currentheight)) ? $currentheight : 100),
            'rules' => array(
                'required' => true,
                'integer'  => true,
            ),
            'help' => true,
        );

        return $form;
    }

    public function save_config_options($values) {
        $mandatory = '';
        $public = '';
        foreach ($values as $field => $value) {
            if (($value == 'on' || $value == 'checked')
                && preg_match('/([a-zA-Z]+)_(mandatory|public)/', $field, $matches)) {
                if (empty($$matches[2])) {
                    $$matches[2] = $matches[1];
                } 
                else {
                    $$matches[2] .= ',' . $matches[1];
                }
            }
        }
        set_config_plugin('artefact', 'internal', 'profilepublic', $public);
        set_config_plugin('artefact', 'internal', 'profilemandatory', $mandatory);
        set_config_plugin('artefact', 'internal', 'profileiconwidth', $values['profileiconwidth']);
        set_config_plugin('artefact', 'internal', 'profileiconheight', $values['profileiconheight']);
    }

00366     public static function get_links($id) {
        $wwwroot = get_config('wwwroot');

        return array(
            '_default' => $wwwroot . 'artefact/internal/',
        );
    }

00374     public function in_view_list() {
        return false;
    }

00378     public function display_title($maxlen=null) {
        return get_string($this->get('artefacttype'), 'artefact.internal');
    }
}

00383 class ArtefactTypeProfileField extends ArtefactTypeProfile {
    public static function collapse_config() {
        return 'profile';
    }

    public function render_self($options) {
        return array('html' => $this->title, 'javascript' => null);
    }
}

00393 class ArtefactTypeCachedProfileField extends ArtefactTypeProfileField {
    
00395     public function commit() {
        global $USER;
        parent::commit();
        if (!$this->deleted) {
            $field = $this->get_artefact_type();
            set_field('usr', $field, $this->title, 'id', $this->owner);
            if ($this->owner == $USER->get('id')) {
                $USER->{$field} = $this->title;
            }
        }
    }

00407     public function delete() {
        parent::delete();
        $field = $this->get_artefact_type();
        set_field('usr', $field, null, 'id', $this->owner);
        $this->title = null;
    }

}

00416 class ArtefactTypeFirstname extends ArtefactTypeCachedProfileField {}
00417 class ArtefactTypeLastname extends ArtefactTypeCachedProfileField {}
00418 class ArtefactTypePreferredname extends ArtefactTypeCachedProfileField {}
00419 class ArtefactTypeEmail extends ArtefactTypeProfileField {
00420     public function commit() {

        parent::commit();

        $email_record = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'email', $this->title);

        if(!$email_record) {
            if (record_exists('artefact_internal_profile_email', 'owner', $this->owner, 'artefact', $this->id)) {
                update_record(
                    'artefact_internal_profile_email',
                    (object) array(
                        'email'     => $this->title,
                        'verified'  => 1,
                    ),
                    (object) array(
                        'owner'     => $this->owner,
                        'artefact'  => $this->id,
                    )
                );
                if (get_field('artefact_internal_profile_email', 'principal', 'owner', $this->owner, 'artefact', $this->id)) {
                    update_record('usr', (object) array( 'email' => $this->title, 'id' => $this->owner));
                }
            }
            else {
                $principal = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'principal', 1);

                insert_record(
                    'artefact_internal_profile_email',
                    (object) array(
                        'owner'     => $this->owner,
                        'email'     => $this->title,
                        'verified'  => 1,
                        'principal' => ( $principal ? 0 : 1 ),
                        'artefact'  => $this->id,
                    )
                );
                update_record('usr', (object)array('email' => $this->title, 'id' => $this->owner));
            }
        }
    }
}

00462 class ArtefactTypeStudentid extends ArtefactTypeProfileField {}
00463 class ArtefactTypeIntroduction extends ArtefactTypeProfileField {}
00464 class ArtefactTypeWebAddress extends ArtefactTypeProfileField {

    public function render_self($options) {
        if ($options['link'] == true) {
            $html = make_link($this->title);
        }
        else {
            $html = $this->title;
        }
        return array('html' => $html, 'javascript' => null);
    }
}
00476 class ArtefactTypeOfficialwebsite extends ArtefactTypeWebAddress {}
00477 class ArtefactTypePersonalwebsite extends ArtefactTypeWebAddress {}
00478 class ArtefactTypeBlogAddress extends ArtefactTypeProfileField {}
00479 class ArtefactTypeAddress extends ArtefactTypeProfileField {}
00480 class ArtefactTypeTown extends ArtefactTypeProfileField {}
00481 class ArtefactTypeCity extends ArtefactTypeProfileField {}
00482 class ArtefactTypeCountry extends ArtefactTypeProfileField {

    public function render_self($options) {
          $countries = getoptions_country();
          return array('html' => $countries[$this->title], 'javascript' => null);
    }
}
00489 class ArtefactTypeHomenumber extends ArtefactTypeProfileField {}
00490 class ArtefactTypeBusinessnumber extends ArtefactTypeProfileField {}
00491 class ArtefactTypeMobilenumber extends ArtefactTypeProfileField {}
00492 class ArtefactTypeFaxnumber extends ArtefactTypeProfileField {}
00493 class ArtefactTypeIcqnumber extends ArtefactTypeProfileField {}
00494 class ArtefactTypeMsnnumber extends ArtefactTypeProfileField {}
00495 class ArtefactTypeAimscreenname extends ArtefactTypeProfileField {}
00496 class ArtefactTypeYahoochat extends ArtefactTypeProfileField {}
00497 class ArtefactTypeSkypeusername extends ArtefactTypeProfileField {}
00498 class ArtefactTypeJabberusername extends ArtefactTypeProfileField {}
00499 class ArtefactTypeOccupation extends ArtefactTypeProfileField {}
00500 class ArtefactTypeIndustry extends ArtefactTypeProfileField {}

00502 class ArtefactTypeProfileIcon extends ArtefactTypeProfileField {
00503     public static function is_note_private() {
        return true;
    }

    public function render_self($options) {
        $options['id'] = $this->get('id');

        $size = filesize(get_config('dataroot') . 'artefact/internal/profileicons/originals/'
            . ($this->get('id') % 256) . '/' . $this->get('id'));

        $downloadpath = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $this->id;
        if (isset($options['viewid'])) {
            $downloadpath .= '&id=' . $options['viewid'];
        }
        $smarty = smarty_core();
        $smarty->assign('iconpath', $this->get_icon($options));
        $smarty->assign('downloadpath', $downloadpath);
        $smarty->assign('owner', display_name($this->get('owner')));
        $smarty->assign('title', $this->get('note'));
        $smarty->assign('description', $this->get('title'));
        $smarty->assign('artefacttype', $this->get('artefacttype'));
        $smarty->assign('created', strftime(get_string('strftimedaydatetime'), $this->get('ctime')));
        $smarty->assign('modified', strftime(get_string('strftimedaydatetime'), $this->get('mtime')));
        $smarty->assign('size', display_size($size) . ' (' . $size . ' ' . get_string('bytes') . ')');
        $smarty->assign('previewpath', get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . $this->get('id') . '&maxwidth=400');
        return array('html' => $smarty->fetch('artefact:internal:profileicon_render_self.tpl'), 'javascript' => '');
    }

00531     public static function get_links($id) {
        $wwwroot = get_config('wwwroot');

        return array(
            '_default' => $wwwroot . 'artefact/internal/profileicons.php',
        );
    }

00539     public static function get_icon($options=null) {
        $url = get_config('wwwroot') . 'thumb.php?type=profileiconbyid&id=' . hsc($options['id']);

        if (isset($options['size'])) {
            $url .= '&size=' . $options['size'];
        }
        else {
            $url .= '&size=20x20';
        }

        return $url;
    }

00552     public function in_view_list() {
        return true;
    }
}


?>

Generated by  Doxygen 1.6.0   Back to index