/** * Sets up form for display to user * @global object $CFG Moodle global config * @version 2015062901 * @since 2011042601 */ public function definition() { global $CFG; global $PAGE; $accountDAO = new TxttoolsAccountDAO(); $accountCount = $accountDAO->countTxttoolsRecords(); $PAGE->requires->jquery(); $PAGE->requires->yui_module('moodle-block_moodletxt-admin', 'M.block_moodletxt.admin.init'); $installForm =& $this->_form; // We need a list of users that can be default inboxes, // for the user to choose from for this initial account $defaultInboxUsers = get_users_by_capability(context_system::instance(), 'block/moodletxt:defaultinbox'); $admins = get_admins(); foreach ($admins as $admin) { $defaultInboxUsers[$admin->id] = $admin; } $defaultInboxList = array(); foreach ($defaultInboxUsers as $defaultInboxUser) { $defaultInboxList[$defaultInboxUser->id] = MoodletxtStringHelper::formatNameForDisplay($defaultInboxUser->firstname, $defaultInboxUser->lastname, $defaultInboxUser->username); } $ctxtInstances = array(); $ctxtInstances[TxttoolsAccount::$UK_LOCATION] = TxttoolsAccount::$UK_LOCATION . ' - ' . TxttoolsAccount::$UK_URL; $ctxtInstances[TxttoolsAccount::$US_LOCATION] = TxttoolsAccount::$US_LOCATION . ' - ' . TxttoolsAccount::$US_URL; $ctxtInstances['URL'] = 'Custom'; // Txttools account $installForm->addElement('header', 'addAccount', get_string('adminlabeladdaccount', 'block_moodletxt')); if ($accountCount < 1) { $installForm->addElement('select', 'accountCtxtInstance', get_string('adminaccountctxtinstance', 'block_moodletxt'), $ctxtInstances); $installForm->setType('accountCtxtInstance', PARAM_STRINGID); $installForm->addElement('text', 'accountUrl', get_string('adminaccounturl', 'block_moodletxt')); $installForm->setType('accountUrl', PARAM_URL); } $installForm->addElement('text', 'accountName', get_string('adminlabelaccusername', 'block_moodletxt'), array('maxlength' => 20)); $installForm->setType('accountName', PARAM_ALPHANUMEXT); $installForm->addRule('accountName', get_string('errornousername', 'block_moodletxt'), 'required'); $installForm->addElement('password', 'accountPassword1', get_string('adminlabelaccpassword', 'block_moodletxt')); $installForm->setType('accountPassword1', PARAM_ALPHANUMEXT); $installForm->addRule('accountPassword1', get_string('errornopassword', 'block_moodletxt'), 'required'); $installForm->addRule('accountPassword1', get_string('errorpasswordtooshort', 'block_moodletxt'), 'minlength', 8); $installForm->addElement('password', 'accountPassword2', get_string('adminlabelaccpassword2', 'block_moodletxt')); $installForm->setType('accountPassword2', PARAM_ALPHANUMEXT); $installForm->addRule('accountPassword2', get_string('errornopassword', 'block_moodletxt'), 'required'); $installForm->addRule('accountPassword2', get_string('errorpasswordtooshort', 'block_moodletxt'), 'minlength', 8); $installForm->addElement('text', 'accountDescription', get_string('adminlabelaccdesc', 'block_moodletxt')); $installForm->setType('accountDescription', PARAM_TEXT); $installForm->addElement('select', 'accountDefaultInbox', get_string('adminlabelaccinbox', 'block_moodletxt'), $defaultInboxList); $installForm->setType('accountDefaultInbox', PARAM_INT); // Buttons $buttonarray = array(); $buttonarray[] =& $installForm->createElement('submit', 'submitButton', get_string('adminbutaddaccount', 'block_moodletxt')); $installForm->addGroup($buttonarray, 'buttonar', '', array(' '), false); $installForm->closeHeaderBefore('buttonar'); }
/** * Override of standard Moodle function - allows for this * element to have additional recipients selected that were not * in the form when it first loaded. * @param array $submitValues Data submitted to form * @param boolean $assoc Whether to return the value(s) as associative array * @return mixed The selected and valid value(s) of the element * @version 2012100301 * @since 2012100301 */ public function exportValue(&$submitValues, $assoc = false) { $value = $this->_findValue($submitValues); // Get values of element to iterate over if (is_null($value)) { $value = $this->getValue(); } else { if (!is_array($value)) { $value = array($value); } } $cleanValues = null; // Values should only be allowed into the form data // if they are part of the initial value set, // or if they begin with the fragment "add#", which // denotes an additional recipient being dynamically added // to the composition form if (is_array($value) && !empty($this->_options)) { foreach ($value as $v) { for ($i = 0, $optCount = count($this->_options); $i < $optCount; $i++) { // Passed values are compound - look for recipient type $explodedValue = explode("#", $v); if ($v == $this->_options[$i]['attr']['value'] || $explodedValue[0] === 'add') { $cleanValues[] = $v; // Dynamically added contacts must be persisted // to the internal options array. After this point, // the form will consider them to be valid and treat them // as any other option in the form. Hurrah! if ($explodedValue[0] === 'add') { $this->_options[] = array('text' => MoodletxtStringHelper::formatNameForDisplay($explodedValue[3], $explodedValue[2], null, null, null, $explodedValue[1]), 'attr' => array('value' => $v)); } break; } } } } else { $cleanValues = $value; } if (is_array($cleanValues) && !$this->getMultiple()) { return $this->_prepareValue($cleanValues[0], $assoc); } else { return $this->_prepareValue($cleanValues, $assoc); } }
/** * If the user has selected a message source for reply on * the inbox page, process it here */ $unknownString = get_string('fragunknownname', 'block_moodletxt'); if ($replyType != '' && $replyValue != '') { switch ($replyType) { case 'user': $initialData['recipients'] = 'u#' . $replyValue; break; case 'contact': $initialData['recipients'] = array('ab#' . $replyValue); break; case 'additional': $recipientValue = 'add#' . $replyValue . '#' . $unknownString . '#' . $unknownString; $potentialRecipients[$recipientValue] = array(MoodletxtStringHelper::formatNameForDisplay($unknownString, $unknownString, null, null, null, $replyValue), array()); $initialData['recipients'] = array($recipientValue); break; } } // CREATE THE FORM, OH YEAH //$sendForm = new MoodletxtSendMessageForm(null, $customData, 'post', '', array('id' => 'messageForm')); // Would work, except Moodle overrides IDs... $sendForm = new MoodletxtSendMessageForm(null, $customData); $sendForm->set_data($initialData); // Check for submitted data $formData = $sendForm->get_data(); if ($formData != null) { $moodleUsers = array(); $moodleUserGroups = array(); $addressBookContacts = array(); $addressBookGroups = array();
$PAGE->requires->jquery_plugin('moodletxt-json', 'block_moodletxt'); $PAGE->requires->js('/blocks/moodletxt/js/received.js', true); $PAGE->requires->js_init_call('receiveCourseId', array($courseId)); $PAGE->requires->js_init_call('receiveInstanceId', array($instanceId)); $output = $PAGE->get_renderer('block_moodletxt'); /* * Inline form for message controls */ $userList = array_merge(get_users_by_capability(context_system::instance(), 'block/moodletxt:receivemessages'), get_users_by_capability(context_course::instance($courseId), 'block/moodletxt:receivemessages')); $userArray = array(0 => ''); foreach ($userList as $thisUser) { // Don't add the current user to the destination list if ($thisUser->id == $USER->id) { continue; } $userArray[$thisUser->id] = MoodletxtStringHelper::formatNameForDisplay($thisUser->firstname, $thisUser->lastname, $thisUser->username); } $GLOBALS['_HTML_QuickForm_default_renderer'] = new InlineFormRenderer(); $customData = array('userlist' => $userArray); $inboxForm = new MoodletxtInboundControlForm(null, $customData, 'post', '', array('class' => 'mdltxt_left')); /* * Create results table */ $table = new flexible_table('blocks-moodletxt-inboxmessages'); $table->define_baseurl($CFG->wwwroot . '/blocks/moodletxt/received.php?course=' . $courseId . '&instance=' . $instanceId); // Required in 2.2 for export $table->set_attribute('id', 'mdltxtReceivedMessagesList'); $table->set_attribute('class', 'generaltable generalbox boxaligncenter boxwidthwide mtxtCentredCells'); $table->collapsible(true); if ($download != '') { $table->is_downloading($download, get_string('exportsheetinbox', 'block_moodletxt'), get_string('exporttitleinbox', 'block_moodletxt'));
/** * Returns the recipients full name, formatted for screen display * @return string Recipient's full name, display formatted * @version 2013052301 * @since 2012031401 */ public function getFullNameForDisplay($linkifyUsername = false) { $userId = $linkifyUsername ? $this->getId() : 0; return MoodletxtStringHelper::formatNameForDisplay($this->getFirstName(), $this->getLastName(), $this->getUsername(), null, $userId); }
/** * Returns a full-name string to be used * in page table displays * @return string Recipient's full name, display formatted * @version 2013052301 * @since 2010082001 */ public function getFullNameForDisplay() { return MoodletxtStringHelper::formatNameForDisplay($this->getFirstName(), $this->getLastName()); }
/** * Gets the message source's name, formatted for display * @return string Formatted source name * @version 2013052301 * @since 2012042401 */ public function getSourceNameForDisplay() { if ($this->associatedSource instanceof MoodletxtRecipient) { return $this->associatedSource->getFullNameForDisplay(); } else { return MoodletxtStringHelper::formatNameForDisplay($this->getSourceFirstName(), $this->getSourceLastName()); } }