* @license http://www.gnu.org/copyleft/gpl.html GNU GPL * @copyright (C) 2006,2007 Catalyst IT Ltd http://catalyst.net.nz * */ defined('INTERNAL') || die(); class PluginArtefactInternal extends PluginArtefact { 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', ); } public static function get_plugin_name() { return 'internal'; } public static function menu_items() { return array( array( 'name' => 'myprofile', 'link' => '', ) ); } 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 get_toplevel_artefact_types() { return array('profile'); } public static function sort_child_data($a, $b) { return strnatcasecmp($a->text, $b->text); } } 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 */ 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; } public function render($format, $options) { if ($format == FORMAT_ARTEFACT_RENDERFULL) { return $this->title; } return parent::render($format, $options); } public function get_icon() { } public static function get_render_list() { return array(FORMAT_ARTEFACT_LISTSELF, FORMAT_ARTEFACT_RENDERFULL, FORMAT_ARTEFACT_RENDERMETADATA); } 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(); $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 $p; } 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(); $form = array( 'name' => 'profileprefs', 'method' => 'post', 'ajaxpost' => true, 'plugintype' => 'artefact', 'pluginname' => 'internal', 'renderer' => 'multicolumntable', 'submitfunction' => 'save_config_options', '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', ); } $form['elements']['emptyrow'] = array( 'title' => ' ', 'type' => 'html', 'value' => ' ', ); $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, ) ); $form['elements']['submit'] = array( 'type' => 'submit', 'value' =>get_string('save') ); 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']); } } class ArtefactTypeProfileField extends ArtefactTypeProfile { public static function collapse_config() { return 'profile'; } /** * This method is optional, and specifies how child data should be formatted * for the artefact tree. * * It should return a StdClass object, with the following fields set: * * - id * - title * - text * - container * - parent * * @param object $data The data to reformat. Contains some fields from the * artefact table, namely title, artefacttype * and container * @return object The reformatted data */ public static function format_child_data($data, $pluginname) { $res = new StdClass; $res->id = $data->id; $res->title = $data->title; $res->isartefact = true; if ($data->artefacttype == 'email') { $res->text = get_string('email') . ' - ' . $data->title; } else { $res->text = get_string($data->artefacttype, "artefact.$pluginname"); } $res->container = 0; $res->parent = null; return $res; } } class ArtefactTypeCachedProfileField extends ArtefactTypeProfileField { public function commit() { global $USER; parent::commit(); $field = $this->get_artefact_type(); set_field('usr', $field, $this->title, 'id', $this->owner); $USER->set($field, $this->title); } public function delete() { parent::delete(); $field = $this->get_artefact_type(); set_field('usr', $field, null, 'id', $this->owner); } } class ArtefactTypeFirstname extends ArtefactTypeCachedProfileField {} class ArtefactTypeLastname extends ArtefactTypeCachedProfileField {} class ArtefactTypePreferredname extends ArtefactTypeCachedProfileField {} class ArtefactTypeEmail extends ArtefactTypeProfileField { public function commit() { parent::commit(); $email_record = get_record('artefact_internal_profile_email', 'owner', $this->owner, 'email', $this->title); // we've created a new artefact that doesn't have a profile email thingy. // we assume that it's a validated email, and set it to primary (if there isn't already one) if(!$email_record) { $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, ) ); } } } class ArtefactTypeStudentid extends ArtefactTypeProfileField {} class ArtefactTypeIntroduction extends ArtefactTypeProfileField {} class ArtefactTypeWebAddress extends ArtefactTypeProfileField { public function render($format, $options) { if (($format == FORMAT_ARTEFACT_LISTSELF || $format == FORMAT_ARTEFACT_RENDERFULL) && $options['link'] == true) { return make_link($this->title); } return parent::render($format, $options); } } class ArtefactTypeOfficialwebsite extends ArtefactTypeWebAddress {} class ArtefactTypePersonalwebsite extends ArtefactTypeWebAddress {} class ArtefactTypeBlogAddress extends ArtefactTypeProfileField {} class ArtefactTypeAddress extends ArtefactTypeProfileField {} class ArtefactTypeTown extends ArtefactTypeProfileField {} class ArtefactTypeCity extends ArtefactTypeProfileField {} class ArtefactTypeCountry extends ArtefactTypeProfileField { public function render($format, $options) { if ($format == FORMAT_ARTEFACT_LISTSELF || $format == FORMAT_ARTEFACT_RENDERFULL) { $countries = getoptions_country(); return $countries[$this->title]; } return parent::render($format, $options); } } class ArtefactTypeHomenumber extends ArtefactTypeProfileField {} class ArtefactTypeBusinessnumber extends ArtefactTypeProfileField {} class ArtefactTypeMobilenumber extends ArtefactTypeProfileField {} class ArtefactTypeFaxnumber extends ArtefactTypeProfileField {} class ArtefactTypeIcqnumber extends ArtefactTypeProfileField {} class ArtefactTypeMsnnumber extends ArtefactTypeProfileField {} class ArtefactTypeAimscreenname extends ArtefactTypeProfileField {} class ArtefactTypeYahoochat extends ArtefactTypeProfileField {} class ArtefactTypeSkypeusername extends ArtefactTypeProfileField {} class ArtefactTypeJabberusername extends ArtefactTypeProfileField {} class ArtefactTypeOccupation extends ArtefactTypeProfileField {} class ArtefactTypeIndustry extends ArtefactTypeProfileField {} ?>