本文整理汇总了PHP中artefact_instance_from_type函数的典型用法代码示例。如果您正苦于以下问题:PHP artefact_instance_from_type函数的具体用法?PHP artefact_instance_from_type怎么用?PHP artefact_instance_from_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了artefact_instance_from_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add_links
public function add_links()
{
$fields = ArtefactTypeContactinformation::get_profile_fields();
foreach ($fields as $f) {
try {
${$f} = artefact_instance_from_type($f, $this->artefact->get('owner'));
$this->add_artefact_link(${$f}, 'has_part');
} catch (MaharaException $e) {
}
// might not exist which is ok
}
}
示例2: render_instance
public static function render_instance(BlockInstance $instance, $editing = false)
{
// Check if XSLT extension is loaded properly, because we will need it...
// The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library.
$xslext = extension_loaded('xsl');
if (!$xslext) {
$missingextensions = array();
!$xslext && ($missingextensions[] = 'xsl');
$errormsg = '<p>' . get_string('europassextensionmissing', 'artefact.europass') . '</p>';
$errormsg .= '<ul>';
foreach ($missingextensions as $extension) {
$errormsg .= '<li><a href="http://www.php.net/' . $extension . '">' . $extension . '</a></li>';
}
$errormsg .= '</ul>';
return $errormsg;
exit;
}
require_once get_config('docroot') . 'artefact/lib.php';
$smarty = smarty_core();
$configdata = $instance->get('configdata');
$configdata['viewid'] = $instance->get('view');
// Get data about the resume field in this blockinstance
if (!empty($configdata['artefactid'])) {
$europassfield = $instance->get_artefact_instance($configdata['artefactid']);
if ($europassfield->get('artefacttype') != 'application') {
$rendered = $europassfield->render_self($configdata);
$result = $rendered['html'];
if (!empty($rendered['javascript'])) {
$result .= '<script type="text/javascript">' . $rendered['javascript'] . '</script>';
}
} else {
require_once get_config('docroot') . 'artefact/europass/lib/locale.php';
$personalinformation = null;
try {
$personalinformation = artefact_instance_from_type('personalinformation');
} catch (Exception $e) {
}
if (!empty($personalinformation)) {
$gender = $personalinformation->get_composite('gender');
} else {
$gender = null;
}
$occupation = get_occupation($europassfield->get('description'), get_config('lang'), $gender);
$result = $occupation['label'];
}
return $result;
}
return '';
}
示例3: set_profile_field
function set_profile_field($userid, $field, $value)
{
safe_require('artefact', 'internal');
// this is a special case that replaces the primary email address with the
// specified one
if ($field == 'email') {
try {
$email = artefact_instance_from_type('email', $userid);
} catch (ArtefactNotFoundException $e) {
$email = new ArtefactTypeEmail();
$email->set('owner', $userid);
}
$email->set('title', $value);
$email->commit();
} else {
$classname = generate_artefact_class_name($field);
$profile = new $classname(0, array('owner' => $userid));
$profile->set('title', $value);
$profile->commit();
}
}
示例4: generate_europasslp_xml
function generate_europasslp_xml($userid, $showHTML = false, $locale = 'en_GB', $internaldateformat = 'dmy11', $externaldateformat = '/numeric/long', $convert = false)
{
// ================================
// Load values from Mahara database
// ================================
// load user's existing contact information
$element_list = array('firstname' => 'text', 'lastname' => 'text');
$contactinfo = array('firstname' => null, 'lastname' => null);
$contactinfo_data = get_records_select_array('artefact', "owner=? AND artefacttype IN (" . join(",", array_map(create_function('$a', 'return db_quote($a);'), array_keys($element_list))) . ")", array($userid));
if ($contactinfo_data) {
foreach ($contactinfo_data as $field) {
$contactinfo[$field->artefacttype] = $field->title;
}
}
// load user's existing demographics information
$demographics = null;
try {
$demographics = artefact_instance_from_type('personalinformation', $userid);
} catch (Exception $e) {
}
// load user's existing mother tongue(s) and foreign language(s)
$artefact_id = get_field('artefact', 'id', 'artefacttype', 'mothertongue', 'owner', $userid);
if ($artefact_id !== false) {
$mothertongue_list = get_records_select_array('artefact_europass_mothertongue', "artefact=?", array($artefact_id));
} else {
$mothertongue_list = array();
}
$artefact_id = get_field('artefact', 'id', 'artefacttype', 'otherlanguage', 'owner', $userid);
if ($artefact_id !== false) {
$otherlanguage_list = get_records_select_array('artefact_europass_otherlanguage', "artefact=?", array($artefact_id));
} else {
$otherlanguage_list = array();
}
// ======================
// Dinamically create XML
// ======================
$xmlDoc = new DOMDocument('1.0', 'UTF-8');
// We want a nice output
//$xmlDoc->formatOutput = true;
$styleSheet = $xmlDoc->createProcessingInstruction('xml-stylesheet', 'href="http://europass.cedefop.europa.eu/xml/lp_' . $locale . '_V2.0.xsl" type="text/xsl"');
$xmlDoc->appendChild($styleSheet);
$rootElement = $xmlDoc->createElement('europass:learnerinfo');
$rootNode = $xmlDoc->appendChild($rootElement);
$rootNode->setAttribute('locale', $locale);
$rootNode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$rootNode->setAttribute('xmlns:europass', 'http://europass.cedefop.europa.eu/Europass/V2.0');
$rootNode->setAttribute('xsi:schemaLocation', 'http://europass.cedefop.europa.eu/Europass/V2.0 http://europass.cedefop.europa.eu/xml/EuropassSchema_V2.0.xsd');
$children = array('docinfo', 'prefs', 'identification', 'languagelist');
foreach ($children as $child) {
$childRoot = $xmlDoc->getElementsByTagName('europass:learnerinfo')->item(0);
$childElement = $xmlDoc->createElement($child);
$childRoot->appendChild($childElement);
}
// =======================
// Dinamically set docinfo
// =======================
// Dinamically set issuedate
$childRoot = $xmlDoc->getElementsByTagName('docinfo')->item(0);
$childElement = $xmlDoc->createElement('issuedate');
$childElement->nodeValue = date('Y-m-d\\TH:i:sP');
$childRoot->appendChild($childElement);
// Dinamically set xsdversion
$childRoot = $xmlDoc->getElementsByTagName('docinfo')->item(0);
$childElement = $xmlDoc->createElement('xsdversion');
$childElement->nodeValue = 'V2.0';
$childRoot->appendChild($childElement);
// Dinamically set comment
$childRoot = $xmlDoc->getElementsByTagName('docinfo')->item(0);
$childElement = $xmlDoc->createElement('comment');
$childElement->nodeValue = 'Automatically generated Europass Language Passport from Mahara e-portfolio data';
$childRoot->appendChild($childElement);
// ========================================
// Dinamically set prefs and identification
// ========================================
// Dinamically set first and last name
$childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
$childElement = $xmlDoc->createElement('field');
$childElement->setAttribute('name', 'personal.lastName');
$childElement->setAttribute('before', 'personal.firstName');
$childRoot->appendChild($childElement);
$childRoot = $xmlDoc->getElementsByTagName('identification')->item(0);
$childElement = $xmlDoc->createElement('firstname');
$childElement->nodeValue = valid_xml_string($contactinfo['firstname']);
$childRoot->appendChild($childElement);
$childElement = $xmlDoc->createElement('lastname');
$childElement->nodeValue = valid_xml_string($contactinfo['lastname']);
$childRoot->appendChild($childElement);
// ----------------------------
// Dinamically set demographics
// ----------------------------
$childRoot = $xmlDoc->getElementsByTagName('identification')->item(0);
$childElement = $xmlDoc->createElement('demographics');
$childRoot->appendChild($childElement);
// Dinamically set birthdate
$childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
$childElement = $xmlDoc->createElement('field');
$childElement->setAttribute('name', 'personal.birthDate');
$childElement->setAttribute('keep', !empty($demographics) ? 'false' : 'true');
$childElement->setAttribute('format', $externaldateformat);
$childRoot->appendChild($childElement);
//.........这里部分代码省略.........
示例5: catch
} catch (Exception $e) {
}
try {
$computerskill = artefact_instance_from_type('computerskill');
} catch (Exception $e) {
}
try {
$artisticskill = artefact_instance_from_type('artisticskill');
} catch (Exception $e) {
}
try {
$otherskill = artefact_instance_from_type('otherskill');
} catch (Exception $e) {
}
try {
$drivinglicence = artefact_instance_from_type('drivinglicence');
$drivinglicence = unserialize($drivinglicence->get('description'));
} catch (Exception $e) {
}
// Locations for various buttons and graphics
$topbanner = get_config('wwwroot') . 'artefact/europass/images/topbanner.png';
$rightlogo = get_config('wwwroot') . 'artefact/europass/images/rightlogo.png';
$skillsform = pieform(array('name' => 'europassform', 'plugintype' => 'artefact', 'pluginname' => 'europass', 'template' => 'skillsform.php', 'elements' => array('AM' => array('type' => 'checkbox', 'title' => 'AM', 'defaultvalue' => !empty($drivinglicence['AM']) ? $drivinglicence['AM'] : null, 'disabled' => true), 'A1' => array('type' => 'checkbox', 'title' => 'A1', 'defaultvalue' => !empty($drivinglicence['A1']) ? $drivinglicence['A1'] : null), 'A' => array('type' => 'checkbox', 'title' => 'A', 'defaultvalue' => !empty($drivinglicence['A']) ? $drivinglicence['A'] : null), 'B' => array('type' => 'checkbox', 'title' => 'B', 'defaultvalue' => !empty($drivinglicence['B']) ? $drivinglicence['B'] : null), 'BE' => array('type' => 'checkbox', 'title' => 'BE', 'defaultvalue' => !empty($drivinglicence['BE']) ? $drivinglicence['BE'] : null), 'B1' => array('type' => 'checkbox', 'title' => 'B1', 'defaultvalue' => !empty($drivinglicence['B1']) ? $drivinglicence['B1'] : null), 'C' => array('type' => 'checkbox', 'title' => 'C', 'defaultvalue' => !empty($drivinglicence['C']) ? $drivinglicence['C'] : null), 'CE' => array('type' => 'checkbox', 'title' => 'CE', 'defaultvalue' => !empty($drivinglicence['CE']) ? $drivinglicence['CE'] : null), 'C1' => array('type' => 'checkbox', 'title' => 'C1', 'defaultvalue' => !empty($drivinglicence['C1']) ? $drivinglicence['C1'] : null), 'C1E' => array('type' => 'checkbox', 'title' => 'C1E', 'defaultvalue' => !empty($drivinglicence['C1E']) ? $drivinglicence['C1E'] : null), 'D' => array('type' => 'checkbox', 'title' => 'D', 'defaultvalue' => !empty($drivinglicence['D']) ? $drivinglicence['D'] : null), 'DE' => array('type' => 'checkbox', 'title' => 'DE', 'defaultvalue' => !empty($drivinglicence['DE']) ? $drivinglicence['DE'] : null), 'D1' => array('type' => 'checkbox', 'title' => 'D1', 'defaultvalue' => !empty($drivinglicence['D1']) ? $drivinglicence['D1'] : null), 'D1E' => array('type' => 'checkbox', 'title' => 'D1E', 'defaultvalue' => !empty($drivinglicence['D1E']) ? $drivinglicence['D1E'] : null), 'socialskill' => array('type' => 'textarea', 'rows' => 4, 'cols' => 60, 'defaultvalue' => !empty($socialskill) ? $socialskill->get('description') : null, 'title' => get_string('socialskill', 'artefact.europass'), 'help' => true), 'organisationalskill' => array('type' => 'textarea', 'rows' => 4, 'cols' => 60, 'defaultvalue' => !empty($organisationalskill) ? $organisationalskill->get('description') : null, 'title' => get_string('organisationalskill', 'artefact.europass'), 'help' => true), 'technicalskill' => array('type' => 'textarea', 'rows' => 4, 'cols' => 60, 'defaultvalue' => !empty($technicalskill) ? $technicalskill->get('description') : null, 'title' => get_string('technicalskill', 'artefact.europass'), 'help' => true), 'computerskill' => array('type' => 'textarea', 'rows' => 4, 'cols' => 60, 'defaultvalue' => !empty($computerskill) ? $computerskill->get('description') : null, 'title' => get_string('computerskill', 'artefact.europass'), 'help' => true), 'artisticskill' => array('type' => 'textarea', 'rows' => 4, 'cols' => 60, 'defaultvalue' => !empty($artisticskill) ? $artisticskill->get('description') : null, 'title' => get_string('artisticskill', 'artefact.europass'), 'help' => true), 'otherskill' => array('type' => 'textarea', 'rows' => 4, 'cols' => 60, 'defaultvalue' => !empty($otherskill) ? $otherskill->get('description') : null, 'title' => get_string('otherskill', 'artefact.europass')), 'submit' => array('type' => 'submit', 'value' => get_string('save', 'mahara')), 'drivingform' => array('type' => 'hidden', 'value' => true), 'redirect' => array('type' => 'hidden', 'value' => 'skills'))));
$smarty = smarty();
// Check if Mahara release is older than 1.3.0
if (get_config('version') < 2010083102) {
$SESSION->add_info_msg(get_string('newerversionforcompatibility', 'artefact.europass'));
$smarty->assign('mahararelease', 1);
}
$smarty->assign('topbanner', $topbanner);
$smarty->assign('rightlogo', $rightlogo);
示例6: set_profile_field
/**
* Save a profile field.
* Exception is 'socialprofile' field. It is made up of 2 fields:
* socialprofile_profileurl,
* socialprofile_profiletype
* @param int $userid
* @param string $field
* @param string (or array for socialprofile) $value
* @param int $new - Whether the user is new (avoid unnecessary queries)
*/
function set_profile_field($userid, $field, $value, $new = FALSE)
{
safe_require('artefact', 'internal');
// this is a special case that replaces the primary email address with the
// specified one
if ($field == 'email') {
if (!$new) {
try {
$email = artefact_instance_from_type('email', $userid);
} catch (ArtefactNotFoundException $e) {
// We'll create a new artefact then.
}
}
if (!isset($email)) {
$email = new ArtefactTypeEmail(0, null, TRUE);
$email->set('owner', $userid);
}
$email->set('title', $value);
$email->commit();
} else {
if ($field == 'socialprofile') {
if (in_array($value['socialprofile_profiletype'], ArtefactTypeSocialprofile::$socialnetworks)) {
$desc = get_string($value['socialprofile_profiletype'], 'artefact.internal');
$type = $value['socialprofile_profiletype'];
} else {
$desc = $value['socialprofile_profiletype'];
$type = 'website';
}
$classname = generate_artefact_class_name($field);
$profile = new $classname(0, array('owner' => $userid), $new);
$profile->set('title', $value['socialprofile_profileurl']);
$profile->set('description', $desc);
$profile->set('note', $type);
$profile->commit();
} else {
$classname = generate_artefact_class_name($field);
$profile = new $classname(0, array('owner' => $userid), $new);
$profile->set('title', $value);
$profile->commit();
}
}
}
示例7: define
define('MENUITEM', 'profile/myresume');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'resume');
define('SECTION_PAGE', 'index');
define('RESUME_SUBPAGE', 'skills');
require_once dirname(dirname(dirname(__FILE__))) . '/init.php';
require_once 'pieforms/pieform.php';
define('TITLE', get_string('myresume', 'artefact.resume'));
require_once get_config('docroot') . 'artefact/lib.php';
$personal = null;
$academic = null;
$work = null;
try {
$personal = artefact_instance_from_type('personalskill');
} catch (Exception $e) {
}
try {
$academic = artefact_instance_from_type('academicskill');
} catch (Exception $e) {
}
try {
$work = artefact_instance_from_type('workskill');
} catch (Exception $e) {
}
$sform = array('name' => 'skillform', 'jsform' => true, 'plugintype' => 'artefact', 'pluginname' => 'resume', 'successcallback' => 'goalandskillform_submit', 'elements' => array('myskills' => array('type' => 'fieldset', 'legend' => get_string('myskills', 'artefact.resume'), 'help' => true, 'elements' => array('personalskill' => array('type' => 'wysiwyg', 'rows' => 20, 'cols' => 80, 'defaultvalue' => !empty($personal) ? $personal->get('description') : null, 'title' => get_string('personalskill', 'artefact.resume')), 'academicskill' => array('type' => 'wysiwyg', 'rows' => 20, 'cols' => 80, 'defaultvalue' => !empty($academic) ? $academic->get('description') : null, 'title' => get_string('academicskill', 'artefact.resume')), 'workskill' => array('type' => 'wysiwyg', 'rows' => 20, 'cols' => 80, 'defaultvalue' => !empty($work) ? $work->get('description') : null, 'title' => get_string('workskill', 'artefact.resume')), 'submit' => array('type' => 'submit', 'value' => get_string('save'))))));
$skillform = pieform($sform);
$smarty = smarty();
$smarty->assign('skillform', $skillform);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
$smarty->display('artefact:resume:skills.tpl');
示例8: create_artefact
/**
* Creates an artefact in the manner required to overwrite existing profile
* artefacts
*
* @param PluginImportLeap $importer The importer
* @param string $artefacttype The type of artefact to create
* @param string $title The title for the artefact (with profile
* fields, this is the main data)
* @return int The ID of the artefact created
*/
private static function create_artefact(PluginImportLeap $importer, $artefacttype, $title)
{
$classname = generate_artefact_class_name($artefacttype);
$artefact = null;
if ($artefacttype == 'email') {
// this type is a bit special. just check if we have one with this value already
if ($a = get_record('artefact', 'artefacttype', 'email', 'owner', $importer->get('usr'), 'title', $title)) {
$artefact = new $classname($a->id, $a);
}
}
if (empty($artefact)) {
try {
$artefact = artefact_instance_from_type($artefacttype, $importer->get('usr'));
} catch (Exception $e) {
$artefact = new $classname(0, array('owner' => $importer->get('usr')));
}
}
$artefact->set('title', $title);
$artefact->commit();
return $artefact->get('id');
}
示例9: create_personalinformation_artefact_from_request
/**
* Imports data for the "Personal Information" section of the resume.
* TODO: Currently the user has to make one decision about all of it -- it would be nice if
* they could make a separate decision about each field.
* @param PluginImport $importer
* @param array $entry_request
* @return int The ID of the artefact created or updated, or 0 if none was touched
*/
private static function create_personalinformation_artefact_from_request(PluginImport $importer, $entry_request)
{
global $USER;
$aid = 0;
$values = unserialize($entry_request->entrycontent);
switch ($entry_request->decision) {
case PluginImport::DECISION_IGNORE:
$duplicatedids = unserialize($entry_request->duplicateditemids);
if (!empty($duplicatedids)) {
$aid = $duplicatedids[0];
}
break;
case PluginImport::DECISION_REPLACE:
$existingids = unserialize($entry_request->existingitemids);
if (!empty($existingids)) {
try {
$a = artefact_instance_from_id($existingids[0]);
if ($USER->get('id') != $a->get('owner')) {
return 0;
}
} catch (Exception $e) {
return 0;
}
}
break;
case PluginImport::DECISION_APPEND:
// We will literally append the content of each text field to each existing text field
// We ignore numeric and date fields
$existingids = unserialize($entry_request->existingitemids);
if (!empty($existingids)) {
try {
$a = artefact_instance_from_id($existingids[0]);
if ($USER->get('id') != $a->get('owner')) {
return 0;
}
foreach (array_keys(ArtefactTypePersonalinformation::get_composite_fields()) as $fieldname) {
if (!empty($values[$fieldname]) && !is_numeric($values[$fieldname]) && $fieldname !== 'dateofbirth') {
$values[$fieldname] = $a->get_composite($fieldname) . ' ' . $values[$fieldname];
}
}
} catch (ArtefactNotFoundException $e) {
$a = new ArtefactTypePersonalinformation(0, array('owner' => $importer->get('usr'), 'title' => get_string($entry_request->entrytype, 'artefact.resume')));
$a->commit();
} catch (Exception $e) {
return 0;
}
break;
}
break;
case PluginImport::DECISION_ADDNEW:
try {
$a = artefact_instance_from_type('personalinformation', $USER->get('id'));
$a->set('mtime', time());
} catch (ArtefactNotFoundException $e) {
$a = new ArtefactTypePersonalinformation(0, array('owner' => $importer->get('usr'), 'title' => get_string($entry_request->entrytype, 'artefact.resume')));
} catch (Exception $e) {
return 0;
}
break;
default:
break;
}
if (isset($a)) {
foreach (array_keys(ArtefactTypePersonalinformation::get_composite_fields()) as $field) {
if (!empty($values[$field])) {
$a->set_composite($field, $values[$field]);
}
}
$a->commit();
$aid = $a->get('id');
}
if ($aid) {
$importer->add_artefactmapping($entry_request->entryid, $aid);
}
return $aid;
}
示例10: create_artefact
/**
* Creates an artefact in the manner required to overwrite existing profile
* artefacts
*
* @param PluginImportLeap $importer The importer
* @param string $artefacttype The type of artefact to create
* @param string $title The title for the artefact (with profile
* fields, this is the main data)
* @param array $extradata An array containing extra data (used for socialprofile artefacts)
* @return int The ID of the artefact created
*/
private static function create_artefact(PluginImportLeap $importer, $artefacttype, $title, $extradata = null)
{
$classname = generate_artefact_class_name($artefacttype);
if ($artefacttype == 'email' && ($a = get_record('artefact', 'artefacttype', 'email', 'owner', $importer->get('usr'), 'title', $title))) {
// email is a bit special. just check if we have one with this value already
// User may have several email addresses but they must be UNIQUE
return $a->id;
}
try {
$artefact = artefact_instance_from_type($artefacttype, $importer->get('usr'));
} catch (Exception $e) {
$artefact = new $classname(0, array('owner' => $importer->get('usr')));
}
$artefact->set('title', $title);
if (!empty($extradata)) {
foreach ($extradata as $field => $value) {
$artefact->set($field, $value);
}
}
$artefact->commit();
return $artefact->get('id');
}
示例11: smarty
if (!$xslext) {
$smarty = smarty();
$missingextensions = array();
!$xslext && ($missingextensions[] = 'xsl');
$smarty->assign('missingextensions', $missingextensions);
$smarty->display('artefact:europass:index.tpl');
exit;
}
$additionalinfo = null;
$annexes = null;
try {
$additionalinfo = artefact_instance_from_type('additionalinfo');
} catch (Exception $e) {
}
try {
$annexes = artefact_instance_from_type('annexes');
} catch (Exception $e) {
}
// Locations for various buttons and graphics
$topbanner = get_config('wwwroot') . 'artefact/europass/images/topbanner.png';
$rightlogo = get_config('wwwroot') . 'artefact/europass/images/rightlogo.png';
$annexesform = pieform(array('name' => 'europassform', 'plugintype' => 'artefact', 'pluginname' => 'europass', 'elements' => array('additionalinfo' => array('type' => 'textarea', 'rows' => 6, 'cols' => 60, 'defaultvalue' => !empty($additionalinfo) ? $additionalinfo->get('description') : null, 'labelhtml' => get_string('additionalinfo', 'artefact.europass'), 'help' => true), 'annexes' => array('type' => 'textarea', 'rows' => 6, 'cols' => 60, 'defaultvalue' => !empty($annexes) ? $annexes->get('description') : null, 'labelhtml' => get_string('annexes', 'artefact.europass'), 'help' => false), 'submit' => array('type' => 'submit', 'value' => get_string('save', 'mahara')), 'redirect' => array('type' => 'hidden', 'value' => 'annexes'))));
$smarty = smarty(array('tablerenderer'));
// Check if Mahara release is older than 1.3.0
if (get_config('version') < 2010083102) {
$SESSION->add_info_msg(get_string('newerversionforcompatibility', 'artefact.europass'));
$smarty->assign('mahararelease', 1);
}
$smarty->assign('topbanner', $topbanner);
$smarty->assign('rightlogo', $rightlogo);
$smarty->assign('annexesform', $annexesform);
示例12: ensure_composite_value
/**
* 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");
}
try {
$a = artefact_instance_from_type($compositetype, $owner);
$a->set('mtime', time());
} catch (Exception $e) {
$classname = generate_artefact_class_name($compositetype);
$a = new $classname(0, array('owner' => $owner, 'title' => get_string($compositetype, 'artefact.resume')));
}
$a->commit();
$values['artefact'] = $a->get('id');
$table = 'artefact_resume_' . $compositetype;
if (!empty($values['id'])) {
update_record($table, (object) $values, 'id');
} else {
if (isset($values['displayorder'])) {
$values['displayorder'] = intval($values['displayorder']);
} else {
$max = get_field($table, 'MAX(displayorder)', 'artefact', $values['artefact']);
$values['displayorder'] = is_numeric($max) ? $max + 1 : 0;
}
insert_record($table, (object) $values);
}
}
示例13: define
define('SECTION_PLUGINNAME', 'resume');
define('SECTION_PAGE', 'index');
define('RESUME_SUBPAGE', 'index');
require_once dirname(dirname(dirname(__FILE__))) . '/init.php';
define('TITLE', get_string('resume', 'artefact.resume'));
require_once 'pieforms/pieform.php';
safe_require('artefact', 'resume');
if (!PluginArtefactResume::is_active()) {
throw new AccessDeniedException(get_string('plugindisableduser', 'mahara', get_string('resume', 'artefact.resume')));
}
$defaults = array('coverletter' => array('default' => '', 'fshelp' => true));
$coverletterform = pieform(simple_resumefield_form($defaults, 'artefact/resume/index.php', array('editortitle' => get_string('coverletter', 'artefact.resume'))));
// load up all the artefacts this user already has....
$personalinformation = null;
try {
$personalinformation = artefact_instance_from_type('personalinformation');
} catch (Exception $e) {
}
$personalinformationform = pieform(array('name' => 'personalinformation', 'plugintype' => 'artefact', 'pluginname' => 'resume', 'jsform' => true, 'method' => 'post', 'elements' => array('personalinfomation' => array('type' => 'fieldset', 'legend' => get_string('personalinformation', 'artefact.resume'), 'elements' => array('dateofbirth' => array('type' => 'calendar', 'caloptions' => array('showsTime' => false, 'ifFormat' => '%Y/%m/%d', 'dateFormat' => 'yy/mm/dd'), 'defaultvalue' => !empty($personalinformation) && null !== $personalinformation->get_composite('dateofbirth') ? $personalinformation->get_composite('dateofbirth') + 3600 : null, 'title' => get_string('dateofbirth', 'artefact.resume'), 'description' => get_string('dateofbirthformatguide')), 'placeofbirth' => array('type' => 'text', 'defaultvalue' => !empty($personalinformation) ? $personalinformation->get_composite('placeofbirth') : null, 'title' => get_string('placeofbirth', 'artefact.resume'), 'size' => 30), 'citizenship' => array('type' => 'text', 'defaultvalue' => !empty($personalinformation) ? $personalinformation->get_composite('citizenship') : null, 'title' => get_string('citizenship', 'artefact.resume'), 'size' => 30), 'visastatus' => array('type' => 'text', 'defaultvalue' => !empty($personalinformation) ? $personalinformation->get_composite('visastatus') : null, 'title' => get_string('visastatus', 'artefact.resume'), 'help' => true, 'size' => 30), 'gender' => array('type' => 'radio', 'defaultvalue' => !empty($personalinformation) ? $personalinformation->get_composite('gender') : null, 'options' => array('' => get_string('gendernotspecified', 'artefact.resume'), 'female' => get_string('female', 'artefact.resume'), 'male' => get_string('male', 'artefact.resume')), 'title' => get_string('gender', 'artefact.resume')), 'maritalstatus' => array('type' => 'text', 'defaultvalue' => !empty($personalinformation) ? $personalinformation->get_composite('maritalstatus') : null, 'title' => get_string('maritalstatus', 'artefact.resume'), 'size' => 30), 'save' => array('type' => 'submit', 'value' => get_string('save')))))));
$smarty = smarty(array('artefact/resume/js/simpleresumefield.js'));
$smarty->assign('coverletterform', $coverletterform);
$smarty->assign('personalinformationform', $personalinformationform);
$smarty->assign('INLINEJAVASCRIPT', '$j(simple_resumefield_init);');
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
$smarty->display('artefact:resume:index.tpl');
function personalinformation_validate(Pieform $form, $values)
{
if (!empty($values['dateofbirth'])) {
if ($values['dateofbirth'] > time()) {
$form->json_reply(PIEFORM_ERR, get_string('dateofbirthinvalid1', 'artefact.resume'));
示例14: define
* @copyright (C) 2006-2009 Catalyst IT Ltd http://catalyst.net.nz
*
*/
define('INTERNAL', true);
define('MENUITEM', 'profile/myresume');
define('SECTION_PLUGINTYPE', 'artefact');
define('SECTION_PLUGINNAME', 'resume');
define('SECTION_PAGE', 'index');
define('RESUME_SUBPAGE', 'interests');
require_once dirname(dirname(dirname(__FILE__))) . '/init.php';
define('TITLE', get_string('myresume', 'artefact.resume'));
require_once 'pieforms/pieform.php';
safe_require('artefact', 'resume');
$interest = null;
try {
$interest = artefact_instance_from_type('interest');
} catch (Exception $e) {
}
$interestsform = pieform(array('name' => 'interests', 'jsform' => true, 'plugintype' => 'artefact', 'pluginname' => 'resume', 'jsform' => true, 'method' => 'post', 'elements' => array('interestsfs' => array('type' => 'fieldset', 'legend' => get_string('interest', 'artefact.resume'), 'elements' => array('interest' => array('type' => 'wysiwyg', 'defaultvalue' => !empty($interest) ? $interest->get('description') : null, 'cols' => 100, 'rows' => 30), 'save' => array('type' => 'submit', 'value' => get_string('save'))), 'help' => true))));
$smarty = smarty();
$smarty->assign('interestsform', $interestsform);
$smarty->assign('PAGEHEADING', TITLE);
$smarty->assign('SUBPAGENAV', PluginArtefactResume::submenu_items());
$smarty->display('artefact:resume:interests.tpl');
function interests_submit(Pieform $form, $values)
{
global $coverletter, $personalinformation, $interest, $USER;
$userid = $USER->get('id');
$errors = array();
try {
if (empty($interest) && !empty($values['interest'])) {
示例15: process_compositeform
/**
* This function processes the form for the composite
* @throws Exception
*/
public static function process_compositeform(Pieform $form, $values)
{
try {
$a = artefact_instance_from_type($values['compositetype']);
$a->set('mtime', time());
} catch (Exception $e) {
global $USER;
$classname = generate_artefact_class_name($values['compositetype']);
$a = new $classname(0, array('owner' => $USER->get('id'), 'title' => get_string($values['compositetype'], 'artefact.resume')));
}
$a->commit();
$values['artefact'] = $a->get('id');
$table = 'artefact_resume_' . $values['compositetype'];
if (!empty($values['id'])) {
update_record($table, (object) $values, 'id');
} else {
$max = get_field($table, 'MAX(displayorder)', 'artefact', $values['artefact']);
$values['displayorder'] = is_numeric($max) ? $max + 1 : 0;
insert_record($table, (object) $values);
}
}