/** * Return the value of a profile field for a given user * * @param integer user id to find the profile field for * @param field what profile field you want the value for * @returns string for non-socialprofile fields - the value of the profile field. * array for socialprofile fields - array of the values of the profile fields ('id-<id>'|'<description>|'<title>'). * null if it doesn't exist * * @todo, this needs to be better (fix email behaviour) */ function get_profile_field($userid, $field) { if ($field == 'email') { $value = get_field_sql("\n SELECT a.title\n FROM {usr} u\n JOIN {artefact} a ON (a.title = u.email AND a.owner = u.id)\n WHERE a.artefacttype = 'email' AND u.id = ?", array($userid)); } else { if ($field == 'socialprofile') { // First check if the block is enabled. if (get_record('blocktype_installed', 'active', 1, 'name', 'socialprofile')) { // The user can have more than one social profiles. Will need to return an array. safe_require('artefact', 'internal'); $value = ArtefactTypeSocialprofile::get_social_profiles(); } } else { $value = get_field('artefact', 'title', 'owner', $userid, 'artefacttype', $field); } } if ($value) { return $value; } return null; }
function editprofileform_validate(Pieform $form, $values) { global $USER; if (in_array($values['profiletype'], ArtefactTypeSocialprofile::$socialnetworks)) { $desc = get_string($values['profiletype'], 'artefact.internal'); $type = $values['profiletype']; } else { $desc = $values['profiletype']; $type = 'website'; } // We're editing. Make sure it's not a duplicate. $data = ArtefactTypeSocialprofile::get_social_profiles(); foreach ($data as $i => $socialprofile) { // don't compare to itself. if ($socialprofile->id != $values['id']) { if ($socialprofile->title == $values['profileurl'] && $socialprofile->description == $desc && $socialprofile->note == $type) { $form->set_error('profileurl', get_string('duplicateurl', 'artefact.internal')); break; } } } }