当前位置: 首页>>代码示例>>PHP>>正文


PHP object::addRule方法代码示例

本文整理汇总了PHP中object::addRule方法的典型用法代码示例。如果您正苦于以下问题:PHP object::addRule方法的具体用法?PHP object::addRule怎么用?PHP object::addRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在object的用法示例。


在下文中一共展示了object::addRule方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildQuickForm

 /**
  * This function provides the HTML form elements that are specific
  * to the Household Contact Type
  *
  * @param object $form form object
  * @param int $inlineEditMode ( 1 for contact summary
  * top bar form and 2 for display name edit )
  *
  * @access public
  * @return void
  */
 public static function buildQuickForm(&$form, $inlineEditMode = NULL)
 {
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
     $form->applyFilter('__ALL__', 'trim');
     if (!$inlineEditMode || $inlineEditMode == 1) {
         // household_name
         $form->add('text', 'household_name', ts('Household Name'), $attributes['household_name']);
     }
     if (!$inlineEditMode || $inlineEditMode == 2) {
         // nick_name
         $form->addElement('text', 'nick_name', ts('Nickname'), $attributes['nick_name']);
         $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     }
     if (!$inlineEditMode) {
         $form->add('text', 'external_identifier', ts('External Id'), $attributes['external_identifier'], FALSE);
         $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
     }
 }
开发者ID:hguru,项目名称:224Civi,代码行数:29,代码来源:Household.php

示例2: school_formelement_condition

 /**
  * @method  school_formelement_condition
  * @todo to display school field form element based on condition (if multiple school providing drop down box else static field)
  * @param object $mform    
  * @return array of objects(form elements)
  */
 public function school_formelement_condition($mform) {
     global $DB, $CFG, $USER;
     $hier = new hierarchy();
     if (is_siteadmin($USER->id)) {
         $schoolids = $DB->get_records('local_school', array('visible' => 1));
     } else
         $schoolids = $hier->get_assignedschools();
     if (!empty($schoolids)) {
         $count = sizeof($schoolids);
         if ($count > 1) {
             $parents = $hier->get_school_parent($schoolids, '', true);
             $mform->addElement('select', 'schoolid', get_string('select', 'local_collegestructure'), $parents);
             $mform->addRule('schoolid', get_string('missingschool', 'local_collegestructure'), 'required', null, 'client');
         } else {
             $schoolname = $DB->get_record('local_school', array('id' => $schoolids[0]->id));
             $mform->addElement('static', 'sid', get_string('schoolid', 'local_collegestructure'), $schoolname->fullname);
             $mform->addElement('hidden', 'schoolid', $schoolids[0]->id);
         }
         $mform->setType('schoolid', PARAM_INT);
     }
 }
开发者ID:anilch,项目名称:Personel,代码行数:27,代码来源:lib.php

示例3: addQuickFormElement

 /**
  * This function for building custom fields
  *
  * @param object  $qf             form object (reference)
  * @param string  $elementName    name of the custom field
  * @param boolean $inactiveNeeded
  * @param boolean $useRequired    true if required else false
  * @param boolean $search         true if used for search else false
  * @param string  $label          label for custom field
  *
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = TRUE, $label = NULL, $fieldOptions = NULL, $feezeOptions = array())
 {
     $field = new CRM_Price_DAO_PriceField();
     $field->id = $fieldId;
     if (!$field->find(TRUE)) {
         /* FIXME: failure! */
         return NULL;
     }
     $is_pay_later = 0;
     if (isset($qf->_mode) && empty($qf->_mode)) {
         $is_pay_later = 1;
     } elseif (isset($qf->_values)) {
         $is_pay_later = CRM_Utils_Array::value('is_pay_later', $qf->_values);
     }
     $otherAmount = $qf->get('values');
     $config = CRM_Core_Config::singleton();
     $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
     $qf->assign('currencySymbol', $currencySymbol);
     // get currency name for price field and option attributes
     $currencyName = $config->defaultCurrency;
     if (!isset($label)) {
         $label = !empty($qf->_membershipBlock) && $field->name == 'contribution_amount' ? ts('Additional Contribution') : $field->label;
     }
     if ($field->name == 'contribution_amount') {
         $qf->_contributionAmount = 1;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = FALSE;
     }
     $customOption = $fieldOptions;
     if (!is_array($customOption)) {
         $customOption = CRM_Price_BAO_PriceField::getOptions($field->id, $inactiveNeeded);
     }
     //use value field.
     $valueFieldName = 'amount';
     $seperator = '|';
     switch ($field->html_type) {
         case 'Text':
             $optionKey = key($customOption);
             $count = CRM_Utils_Array::value('count', $customOption[$optionKey], '');
             $max_value = CRM_Utils_Array::value('max_value', $customOption[$optionKey], '');
             $priceVal = implode($seperator, array($customOption[$optionKey][$valueFieldName], $count, $max_value));
             $extra = array();
             if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
                 foreach ($fieldOptions as &$fieldOption) {
                     if ($fieldOption['name'] == 'other_amount') {
                         $fieldOption['label'] = $fieldOption['label'] . '  ' . $currencySymbol;
                     }
                 }
                 $qf->assign('priceset', $elementName);
                 $extra = array('onclick' => 'useAmountOther();');
             }
             // if seperate membership payment is used with quick config priceset then change the other amount label
             if (!empty($qf->_membershipBlock) && !empty($qf->_quickConfig) && $field->name == 'other_amount' && empty($qf->_contributionAmount)) {
                 $label = ts('Additional Contribution');
                 $useRequired = 0;
             } elseif (CRM_Utils_Array::value('label', $fieldOptions[$optionKey])) {
                 //check for label.
                 $label = $fieldOptions[$optionKey]['label'];
             }
             $element =& $qf->add('text', $elementName, $label, array_merge($extra, array('price' => json_encode(array($optionKey, $priceVal)), 'size' => '4')), $useRequired && $field->is_required);
             if ($is_pay_later) {
                 $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4'));
             }
             // CRM-6902
             if (in_array($optionKey, $feezeOptions)) {
                 $element->freeze();
             }
             //CRM-10117
             if (!empty($qf->_quickConfig)) {
                 $message = ts('Please enter a valid amount.');
                 $type = 'money';
             } else {
                 $message = ts('%1 must be an integer (whole number).', array(1 => $label));
                 $type = 'positiveInteger';
             }
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, $message, $type);
             break;
         case 'Radio':
             $choice = array();
             if (!empty($qf->_quickConfig) && !empty($qf->_contributionAmount)) {
                 $qf->assign('contriPriceset', $elementName);
             }
             foreach ($customOption as $opId => $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] = CRM_Utils_Array::value('label', $opt) ? $opt['label'] : '';
//.........这里部分代码省略.........
开发者ID:TheCraftyCanvas,项目名称:aegir-platforms,代码行数:101,代码来源:PriceField.php

示例4: setup_format

 /**
  * Add form elements for course format.
  * @param object $mform			form definition
  * @param object $courseinfo	a record of general information from course info table
  * @return void
  */
 private function setup_format($mform, $courseinfo)
 {
     global $CFG, $DB, $USER;
     //Declare our globals for use
     global $courseId;
     $mform->addElement('html', '<a name="format"></a>');
     // anchor
     $mform->addElement('header', 'course_format_header', get_string('course_format_header', 'local_metadata'));
     $mform->addHelpButton('course_format_header', 'course_format_header', 'local_metadata');
     // Assessment
     $course_assessment = $mform->addElement('text', 'course_assessment', get_string('assessment_counter', 'local_metadata'), '');
     //$mform->addRule('course_assessment', get_string('err_required', 'local_metadata'), 'required', null, 'client');
     $mform->addRule('course_assessment', get_string('err_numeric', 'local_metadata'), 'numeric', null, 'client');
     $courseassessment = $DB->count_records('courseassessment', array('courseid' => $courseId));
     if ($courseassessment != 0) {
         $mform->setDefault('course_assessment', $courseassessment);
     } else {
         if ($courseinfo) {
             $mform->setDefault('course_assessment', $courseinfo->assessmentnumber);
         }
     }
     $mform->setType('course_assessment', PARAM_INT);
     // Session
     $course_assessment = $mform->addElement('text', 'course_session', get_string('session_counter', 'local_metadata'), '');
     //$mform->addRule('course_session', get_string('err_required', 'local_metadata'), 'required', null, 'client');
     $mform->addRule('course_session', get_string('err_numeric', 'local_metadata'), 'numeric', null, 'client');
     $coursesession = $DB->count_records('coursesession', array('courseid' => $courseId));
     if ($coursesession != 0) {
         $mform->setDefault('course_session', $coursesession);
     } else {
         if ($courseinfo) {
             $mform->setDefault('course_session', $courseinfo->sessionnumber);
         }
     }
     $mform->setType('course_session', PARAM_INT);
     $mform->addElement('static', 'h_6', '');
     // end of header
     $mform->setType('h_6', PARAM_RAW);
     $mform->closeHeaderBefore('h_6');
     $mform->setExpanded('course_format_header');
 }
开发者ID:MoodleMetaData,项目名称:MoodleMetaData,代码行数:47,代码来源:general_form.php

示例5: foreach

 /**
  * DB_DataObject_FormBuilder_QuickForm::_addFieldRulesToForm()
  *
  * Adds a set of rules to a form that will apply to a specific element
  * Used in _generateForm().
  *
  * @param object $form      The form object to add the ruleset to
  * @param array  $rules     Array of rule names to be enforced on the element (must be registered QuickForm rules)
  * @param string $fieldName Name of the form element in question
  * @access protected
  * @see DB_DataObject_FormBuilder::_generateForm()
  */
 function _addFieldRulesToForm(&$form, $rules, $fieldName)
 {
     $fieldLabel = $this->getFieldLabel($fieldName);
     $ruleSide = $this->clientRules ? 'client' : 'server';
     foreach ($rules as $rule) {
         if ($rule['rule'] === false) {
             $form->addRule($this->getFieldName($fieldName), sprintf($rule['message'], $fieldLabel), $rule['validator'], '', $ruleSide);
         } else {
             $form->addRule($this->getFieldName($fieldName), sprintf($rule['message'], $fieldLabel), $rule['validator'], $rule['rule'], $ruleSide);
         }
         // End if
     }
     // End while
 }
开发者ID:GeekyNinja,项目名称:LifesavingCAD,代码行数:26,代码来源:QuickForm.php

示例6: type_config_form

 /**
  * Add Plugin settings input to Moodle form
  * @param object $mform
  */
 public function type_config_form(&$mform)
 {
     $public_account = get_config('boxnet', 'public_account');
     $api_key = get_config('boxnet', 'api_key');
     if (empty($api_key)) {
         $api_key = '';
     }
     $strrequired = get_string('required');
     $mform->addElement('text', 'api_key', get_string('apikey', 'repository_boxnet'), array('value' => $api_key, 'size' => '40'));
     $mform->addRule('api_key', $strrequired, 'required', null, 'client');
     $mform->addElement('static', null, '', get_string('information', 'repository_boxnet'));
 }
开发者ID:nicolasconnault,项目名称:moodle2.0,代码行数:16,代码来源:repository.class.php

示例7: addQuickFormElement

 /**
  * This function for building custom fields
  *
  * @param object  $qf             form object (reference)
  * @param string  $elementName    name of the custom field
  * @param boolean $inactiveNeeded
  * @param boolean $userRequired   true if required else false
  * @param boolean $search         true if used for search else false
  * @param string  $label          label for custom field
  *
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded = FALSE, $useRequired = TRUE, $search = FALSE, $label = NULL)
 {
     // we use $_POST directly, since we dont want to use session memory, CRM-4677
     if (isset($_POST['_qf_Relationship_refresh']) && ($_POST['_qf_Relationship_refresh'] == 'Search' || $_POST['_qf_Relationship_refresh'] == 'Search Again')) {
         $useRequired = FALSE;
     }
     $field = self::getFieldObject($fieldId);
     // Custom field HTML should indicate group+field name
     $groupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $field->custom_group_id);
     $dataCrmCustomVal = $groupName . ':' . $field->name;
     $dataCrmCustomAttr = 'data-crm-custom="' . $dataCrmCustomVal . '"';
     $field->attributes .= $dataCrmCustomAttr;
     // Fixed for Issue CRM-2183
     if ($field->html_type == 'TextArea' && $search) {
         $field->html_type = 'Text';
     }
     // FIXME: Why are select state/country separate widget types?
     if (in_array($field->html_type, array('Select', 'Multi-Select', 'Select State/Province', 'Multi-Select State/Province', 'Select Country', 'Multi-Select Country'))) {
         $selectAttributes = array('data-crm-custom' => $dataCrmCustomVal, 'class' => 'crm-select2');
         if (strpos($field->html_type, 'Multi') === 0) {
             $selectAttributes['multiple'] = 'multiple';
         }
     }
     // Add popup link for editing options. Normally this is handled by CRM_Core_Form->addSelect
     if (in_array($field->html_type, array('Select', 'Multi-Select')) && !$search && CRM_Core_Permission::check('administer CiviCRM')) {
         $selectAttributes += array('data-api-entity' => 'contact', 'data-api-field' => 'custom_' . $field->id, 'data-option-group-url' => 'civicrm/admin/options/' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $field->option_group_id));
     }
     if (!isset($label)) {
         $label = $field->label;
     }
     /**
      * at some point in time we might want to split the below into small functions
      **/
     switch ($field->html_type) {
         case 'Text':
             if ($field->is_search_range && $search) {
                 $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes);
                 $qf->add('text', $elementName . '_to', ts('To'), $field->attributes);
             } else {
                 $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, $useRequired && !$search);
             }
             break;
         case 'TextArea':
             $attributes = $dataCrmCustomAttr;
             if ($field->note_rows) {
                 $attributes .= 'rows=' . $field->note_rows;
             } else {
                 $attributes .= 'rows=4';
             }
             if ($field->note_columns) {
                 $attributes .= ' cols=' . $field->note_columns;
             } else {
                 $attributes .= ' cols=60';
             }
             if ($field->text_length) {
                 $attributes .= ' maxlength=' . $field->text_length;
             }
             $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $attributes, $useRequired && !$search);
             break;
         case 'Select Date':
             if ($field->is_search_range && $search) {
                 $qf->addDate($elementName . '_from', $label . ' - ' . ts('From'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
                 $qf->addDate($elementName . '_to', ts('To'), FALSE, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
             } else {
                 $required = $useRequired && !$search;
                 $qf->addDate($elementName, $label, $required, array('format' => $field->date_format, 'timeFormat' => $field->time_format, 'startOffset' => $field->start_date_years, 'endOffset' => $field->end_date_years, 'data-crm-custom' => $dataCrmCustomVal));
             }
             break;
         case 'Radio':
             $choice = array();
             if ($field->data_type != 'Boolean') {
                 $customOption =& CRM_Core_BAO_CustomOption::valuesByID($field->id, $field->option_group_id);
                 foreach ($customOption as $v => $l) {
                     $choice[] = $qf->createElement('radio', NULL, '', $l, (string) $v, $field->attributes);
                 }
                 $group = $qf->addGroup($choice, $elementName, $label);
             } else {
                 $choice[] = $qf->createElement('radio', NULL, '', ts('Yes'), '1', $field->attributes);
                 $choice[] = $qf->createElement('radio', NULL, '', ts('No'), '0', $field->attributes);
                 $group = $qf->addGroup($choice, $elementName, $label);
             }
             if ($useRequired && !$search) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             } else {
                 $group->setAttribute('unselectable', TRUE);
             }
             break;
//.........这里部分代码省略.........
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:101,代码来源:CustomField.php

示例8: array

 /**
  * Add custom requirement rules to filter elements
  *
  * @param   object $mform  The mform object for the filter page
  * @param   string $key    The filter field key
  * @param   object $fields The filter field values object
  *
  * @return  object $mform  The modified mform object for the filter page
  */
 function apply_filter_required_rule($mform, $key, $fields)
 {
     if ($mform->elementExists($key . '_grp')) {
         $mform->addRule($key . '_grp', get_string('required'), 'required', null, 'client');
         $mform->registerRule('custom_rule', 'function', 'user_course_completion_check_custom_rule');
         $mform->addRule($key . '_grp', get_string('required'), 'custom_rule', array($key, $fields));
     }
     return $mform;
 }
开发者ID:remotelearner,项目名称:elis.reporting,代码行数:18,代码来源:user_class_completion_report.class.php

示例9: addQuickFormElement

 /**
  * This function for building custom fields
  * 
  * @param object  $qf             form object (reference)
  * @param string  $elementName    name of the custom field
  * @param boolean $inactiveNeeded 
  * @param boolean $useRequired    true if required else false
  * @param boolean $search         true if used for search else false
  * @param string  $label          label for custom field        
  *
  * @access public
  * @static
  */
 public static function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired = true, $label = null)
 {
     require_once 'CRM/Utils/Money.php';
     $field =& new CRM_Price_DAO_Field();
     $field->id = $fieldId;
     if (!$field->find(true)) {
         /* FIXME: failure! */
         return null;
     }
     $config =& CRM_Core_Config::singleton();
     $qf->assign('currencySymbol', CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Currency', $config->defaultCurrency, 'symbol', 'name'));
     if (!isset($label)) {
         $label = $field->label;
     }
     if (isset($qf->_online) && $qf->_online) {
         $useRequired = false;
     }
     //use value field.
     $valueFieldName = 'value';
     switch ($field->html_type) {
         case 'Text':
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             // text fields only have one option
             $optionKey = key($customOption);
             if ($field->is_display_amounts) {
                 $label .= '&nbsp;-&nbsp;';
                 $label .= CRM_Utils_Money::format(CRM_Utils_Array::value($valueFieldName, $customOption[$optionKey]));
             }
             $element =& $qf->add('text', $elementName, $label, array_merge(array('size' => "4"), array('price' => json_encode(array($optionKey, $customOption[$optionKey][$valueFieldName])))), $useRequired && $field->is_required);
             // integers will have numeric rule applied to them.
             $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'positiveInteger');
             break;
         case 'Radio':
             $choice = array();
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             if (!$field->is_required) {
                 // add "none" option
                 $choice[] = $qf->createElement('radio', null, '', '-none-', '0', array('price' => json_encode(array($elementName, "0"))));
             }
             foreach ($customOption as $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $choice[] = $qf->createElement('radio', null, '', $opt['label'], $opt['id'], array('price' => json_encode(array($elementName, $opt[$valueFieldName]))));
             }
             $element =& $qf->addGroup($choice, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
         case 'Select':
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             $selectOption = array();
             foreach ($customOption as $opt) {
                 $amount[$opt['id']] = $opt[$valueFieldName];
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $selectOption[$opt['id']] = $opt['label'];
             }
             $element =& $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, $useRequired && $field->is_required, array('price' => json_encode($amount)));
             break;
         case 'CheckBox':
             $customOption = CRM_Price_BAO_Field::getOptions($field->id, $inactiveNeeded);
             $check = array();
             foreach ($customOption as $opt) {
                 if ($field->is_display_amounts) {
                     $opt['label'] .= '&nbsp;-&nbsp;';
                     $opt['label'] .= CRM_Utils_Money::format($opt[$valueFieldName]);
                 }
                 $check[] =& $qf->createElement('checkbox', $opt['id'], null, $opt['label'], array('price' => json_encode(array($opt['id'], $opt[$valueFieldName]))));
             }
             $element =& $qf->addGroup($check, $elementName, $label);
             if ($useRequired && $field->is_required) {
                 $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required');
             }
             break;
     }
     if (isset($qf->_online) && $qf->_online) {
         $element->freeze();
     }
 }
开发者ID:bhirsch,项目名称:voipdev,代码行数:97,代码来源:Field.php

示例10: onQuickFormEvent

 /**
  * Called by HTML_QuickForm whenever form event is made on this element.
  * Adds necessary rules to the element and checks that coorenct instance of gradingform_instance
  * is passed in attributes
  *
  * @param string $event Name of event
  * @param mixed $arg event arguments
  * @param object $caller calling object
  * @return bool
  * @throws moodle_exception
  */
 public function onQuickFormEvent($event, $arg, &$caller)
 {
     if ($event == 'createElement') {
         $attributes = $arg[2];
         if (!is_array($attributes) || !array_key_exists('gradinginstance', $attributes) || !$attributes['gradinginstance'] instanceof gradingform_instance) {
             throw new moodle_exception('exc_gradingformelement', 'grading');
         }
     }
     $name = $this->getName();
     if ($name && $caller->elementExists($name)) {
         $caller->addRule($name, $this->get_gradinginstance()->default_validation_error_message(), 'gradingvalidated', $this->gradingattributes);
     }
     return parent::onQuickFormEvent($event, $arg, $caller);
 }
开发者ID:alanaipe2015,项目名称:moodle,代码行数:25,代码来源:grading.php

示例11: onQuickFormEvent

 /**
  * Called by HTML_QuickForm whenever form event is made on this element.
  *
  * @param string $event Name of event
  * @param mixed $arg event arguments
  * @param object $caller calling object
  * @return mixed
  */
 public function onQuickFormEvent($event, $arg, &$caller)
 {
     global $COURSE;
     switch ($event) {
         case 'updateValue':
             $value = $this->_findValue($caller->_constantValues);
             if (null === $value) {
                 if ($caller->isSubmitted()) {
                     $value = $this->_findValue($caller->_submitValues);
                 } else {
                     $value = $this->_findValue($caller->_defaultValues);
                 }
             }
             $name = $this->getName();
             // Set disable actions.
             $caller->disabledIf($name . '[modgrade_scale]', $name . '[modgrade_type]', 'neq', 'scale');
             $caller->disabledIf($name . '[modgrade_point]', $name . '[modgrade_type]', 'neq', 'point');
             // Set element state for existing data.
             if (!empty($this->_elements)) {
                 if (!empty($value)) {
                     if ($value < 0) {
                         $this->_elements[1]->setValue('scale');
                         $this->_elements[4]->setValue($value * -1);
                     } else {
                         if ($value > 0) {
                             $this->_elements[1]->setValue('point');
                             $this->_elements[7]->setValue($value);
                         }
                     }
                 } else {
                     $this->_elements[1]->setValue('none');
                     $this->_elements[7]->setValue('');
                 }
             }
             // Value Validation.
             if ($name && $caller->elementExists($name)) {
                 $checkmaxgrade = function ($val) {
                     if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'point') {
                         if (!isset($val['modgrade_point'])) {
                             return false;
                         }
                         return $this->validate_point($val['modgrade_point']);
                     }
                     return true;
                 };
                 $checkvalidscale = function ($val) {
                     if (isset($val['modgrade_type']) && $val['modgrade_type'] === 'scale') {
                         if (!isset($val['modgrade_scale'])) {
                             return false;
                         }
                         return $this->validate_scale($val['modgrade_scale']);
                     }
                     return true;
                 };
                 $maxgradeexceeded = get_string('modgradeerrorbadpoint', 'grades', get_config('core', 'gradepointmax'));
                 $invalidscale = get_string('modgradeerrorbadscale', 'grades');
                 $caller->addRule($name, $maxgradeexceeded, 'callback', $checkmaxgrade);
                 $caller->addRule($name, $invalidscale, 'callback', $checkvalidscale);
             }
             break;
     }
     return parent::onQuickFormEvent($event, $arg, $caller);
 }
开发者ID:abhilash1994,项目名称:moodle,代码行数:71,代码来源:modgrade.php

示例12: turnitin_get_form_elements

/**
 * adds the list of plagiarism settings to a form
 *
 * @param object $mform - Moodle form object
 */
function turnitin_get_form_elements($mform)
{
    $ynoptions = array(0 => get_string('no'), 1 => get_string('yes'));
    $tiishowoptions = array(PLAGIARISM_TII_SHOW_NEVER => get_string("never"), PLAGIARISM_TII_SHOW_ALWAYS => get_string("always"), PLAGIARISM_TII_SHOW_CLOSED => get_string("showwhenclosed", "plagiarism_turnitin"));
    $tiidraftoptions = array(PLAGIARISM_TII_DRAFTSUBMIT_IMMEDIATE => get_string("submitondraft", "plagiarism_turnitin"), PLAGIARISM_TII_DRAFTSUBMIT_FINAL => get_string("submitonfinal", "plagiarism_turnitin"));
    $reportgenoptions = array(0 => get_string('reportgenimmediate', 'plagiarism_turnitin'), 1 => get_string('reportgenimmediateoverwrite', 'plagiarism_turnitin'), 2 => get_string('reportgenduedate', 'plagiarism_turnitin'));
    $excludetype = array(0 => get_string('no'), 1 => get_string('wordcount', 'plagiarism_turnitin'), 2 => get_string('percentage', 'plagiarism_turnitin'));
    $mform->addElement('header', 'plagiarismdesc');
    $mform->addElement('select', 'use_turnitin', get_string("useturnitin", "plagiarism_turnitin"), $ynoptions);
    $mform->addElement('select', 'plagiarism_show_student_score', get_string("showstudentsscore", "plagiarism_turnitin"), $tiishowoptions);
    $mform->addHelpButton('plagiarism_show_student_score', 'showstudentsscore', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_show_student_report', get_string("showstudentsreport", "plagiarism_turnitin"), $tiishowoptions);
    $mform->addHelpButton('plagiarism_show_student_report', 'showstudentsreport', 'plagiarism_turnitin');
    if ($mform->elementExists('var4')) {
        $mform->addElement('select', 'plagiarism_draft_submit', get_string("draftsubmit", "plagiarism_turnitin"), $tiidraftoptions);
    }
    $mform->addElement('select', 'plagiarism_compare_student_papers', get_string("comparestudents", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_compare_student_papers', 'comparestudents', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_compare_internet', get_string("compareinternet", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_compare_internet', 'compareinternet', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_compare_journals', get_string("comparejournals", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_compare_journals', 'comparejournals', 'plagiarism_turnitin');
    if (get_config('plagiarism', 'turnitin_institutionnode')) {
        $mform->addElement('select', 'plagiarism_compare_institution', get_string("compareinstitution", "plagiarism_turnitin"), $ynoptions);
        $mform->addHelpButton('plagiarism_compare_institution', 'compareinstitution', 'plagiarism_turnitin');
    }
    $mform->addElement('select', 'plagiarism_report_gen', get_string("reportgen", "plagiarism_turnitin"), $reportgenoptions);
    $mform->addHelpButton('plagiarism_report_gen', 'reportgen', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_exclude_biblio', get_string("excludebiblio", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_exclude_biblio', 'excludebiblio', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_exclude_quoted', get_string("excludequoted", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_exclude_quoted', 'excludequoted', 'plagiarism_turnitin');
    $mform->addElement('select', 'plagiarism_exclude_matches', get_string("excludematches", "plagiarism_turnitin"), $excludetype);
    $mform->addHelpButton('plagiarism_exclude_matches', 'excludematches', 'plagiarism_turnitin');
    $mform->addElement('text', 'plagiarism_exclude_matches_value', '');
    $mform->addRule('plagiarism_exclude_matches_value', null, 'numeric', null, 'client');
    $mform->disabledIf('plagiarism_exclude_matches_value', 'plagiarism_exclude_matches', 'eq', 0);
    $mform->addElement('select', 'plagiarism_anonymity', get_string("anonymity", "plagiarism_turnitin"), $ynoptions);
    $mform->addHelpButton('plagiarism_anonymity', 'anonymity', 'plagiarism_turnitin');
}
开发者ID:rrusso,项目名称:moodle-plagiarism_turnitin,代码行数:45,代码来源:lib.php

示例13: buildQuickForm

 /**
  * This function provides the HTML form elements that are specific
  * to the Individual Contact Type
  *
  * @param object $form form object
  * @param int $inlineEditMode ( 1 for contact summary
  * top bar form and 2 for display name edit )
  *
  * @access public
  * @return void
  */
 public static function buildQuickForm(&$form, $inlineEditMode = NULL)
 {
     $form->applyFilter('__ALL__', 'trim');
     if (!$inlineEditMode || $inlineEditMode == 1) {
         //prefix
         $prefix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id');
         if (!empty($prefix)) {
             $form->addElement('select', 'prefix_id', ts('Prefix'), array('' => '') + $prefix);
         }
         $attributes = CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact');
         // first_name
         $form->addElement('text', 'first_name', ts('First Name'), $attributes['first_name']);
         //middle_name
         $form->addElement('text', 'middle_name', ts('Middle Name'), $attributes['middle_name']);
         // last_name
         $form->addElement('text', 'last_name', ts('Last Name'), $attributes['last_name']);
         // suffix
         $suffix = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id');
         if ($suffix) {
             $form->addElement('select', 'suffix_id', ts('Suffix'), array('' => '') + $suffix);
         }
     }
     if (!$inlineEditMode || $inlineEditMode == 2) {
         // nick_name
         $form->addElement('text', 'nick_name', ts('Nickname'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'nick_name'));
         // job title
         // override the size for UI to look better
         $attributes['job_title']['size'] = 30;
         $form->addElement('text', 'job_title', ts('Job Title'), $attributes['job_title'], 'size="30"');
         //Current Employer Element
         $employerDataURL = CRM_Utils_System::url('civicrm/ajax/rest', 'className=CRM_Contact_Page_AJAX&fnName=getContactList&json=1&context=contact&org=1&employee_id=' . $form->_contactId, FALSE, NULL, FALSE);
         $form->assign('employerDataURL', $employerDataURL);
         $form->addElement('text', 'current_employer', ts('Current Employer'), '');
         $form->addElement('hidden', 'current_employer_id', '', array('id' => 'current_employer_id'));
         $form->addElement('text', 'contact_source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     }
     if (!$inlineEditMode) {
         $checkSimilar = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_ajax_check_similar', NULL, TRUE);
         if ($checkSimilar == null) {
             $checkSimilar = 0;
         }
         $form->assign('checkSimilar', $checkSimilar);
         //External Identifier Element
         $form->add('text', 'external_identifier', ts('External Id'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'), FALSE);
         $form->addRule('external_identifier', ts('External ID already exists in Database.'), 'objectExists', array('CRM_Contact_DAO_Contact', $form->_contactId, 'external_identifier'));
         $config = CRM_Core_Config::singleton();
         CRM_Core_ShowHideBlocks::links($form, 'demographics', '', '');
     }
 }
开发者ID:hguru,项目名称:224Civi,代码行数:60,代码来源:Individual.php

示例14: setupForm

 /**
  * Adds controls specific to this filter in the form.
  * @param  object  $mform  A MoodleForm object to setup
  */
 public function setupForm(&$mform)
 {
     global $CFG;
     $report = $this->_parent_report;
     $filter = $this->_uniqueid;
     $filter_js = array('var ac_show_panel = function( url ) {
             var x = window.open(url, \'newWindow\', \'height=700,width=650,resizable=yes,scrollbars=yes,screenX=50,screenY=50\');
         }
         window.ac_show_panel = ac_show_panel;');
     $filt_action_url_base = $CFG->wwwroot . '/local/eliscore/lib/form/autocomplete.php?report=' . $report . '&filter=' . $filter;
     if ($this->_ui === 'inline') {
         $mform->addElement('hidden', $this->_uniqueid, $this->get_default(), array('id' => 'id_' . $this->_uniqueid));
         $mform->setType($this->_uniqueid, PARAM_TEXT);
         $search_url = $filt_action_url_base . '&mode=search&q=';
         $config_url = $filt_action_url_base . '&mode=config';
         $main_input_ph = $this->_selection_enabled === true ? get_string('filt_autoc_typetosearch', 'local_eliscore') : '';
         $text_input = array($mform->createElement('text', $this->_uniqueid, $this->_label, array('placeholder' => $main_input_ph)));
         if ($this->config_allowed() === true) {
             $text_input[] = $mform->createElement('static', 'configlink', '', '<a onclick="ac_show_panel(\'' . $config_url . '\');" href="#">' . '<img src=' . $CFG->wwwroot . '/local/elisprogram/pix/configuration.png>' . '</a>');
         }
         $text_input[] = $mform->createElement('html', '<div id="search_results_outer" class="filt_ac_res filt_ac_res_inline">
                     <div id="search_status" class="filt_ac_status filt_ac_status_inline"></div>
                     <div id="search_results"></div>
                 </div>');
         $mform->addGroup($text_input, 'grp', $this->_label);
         $mform->setType($this->_uniqueid, PARAM_RAW);
         if ($this->_selection_enabled === true) {
             if ($this->_required) {
                 // This adds red * & that a required form field exists + validation
                 $mform->addGroupRule('grp', get_string('required'), 'required', null, 1, 'client');
                 if ($this->_useid) {
                     $mform->addRule($this->_uniqueid, get_string('required'), 'required', null, 'client');
                     // hidden doesn't display
                 }
             }
             $mform->addElement('html', "<link rel='stylesheet' type='text/css' href='{$CFG->wwwroot}/local/eliscore/lib/form/autocomplete.css' />");
             $mform->addElement('html', "<script src='{$CFG->wwwroot}/local/eliscore/js/jquery-1.7.1.min.js'></script>");
             $mform->addElement('html', "<script src='{$CFG->wwwroot}/local/eliscore/lib/form/autocomplete.js'></script>");
             $filter_js[] = "var search_textbox = 'id_grp_{$this->_uniqueid}';\n                        var search_results = 'search_results';\n                        var search_status = 'search_status';\n                        var search_results_outer = 'search_results_outer';\n\n                        var autocomplete = new autocomplete_ui(search_textbox,search_results,search_status,'{$search_url}','search_results_outer');\n                        autocomplete.str_searching = '" . get_string('filt_autoc_searching', 'local_eliscore') . "';\n                        autocomplete.str_typetosearch = '" . get_string('filt_autoc_typetosearch', 'local_eliscore') . "';\n\n                        \$('#'+search_textbox).focus().click(function(e){e.stopPropagation();}).keyup(function(e) {\n                            if (e.keyCode != 13) {\n                                \$('#'+search_results_outer).show().click(function(e) { e.stopPropagation() });\n                                \$('body').click(function(e){ \$('#'+search_results_outer).hide(); });\n                                var pos = \$(this).position();\n                                var height = \$(this).outerHeight();\n                                \$('#'+search_results_outer).css('left',pos.left+2).css('top',(pos.top+height+2));\n                            }\n                        });";
         } else {
             $mform->freeze('grp');
         }
         if (!empty($this->_default_label)) {
             $mform->setDefault('grp[' . $this->_uniqueid . ']', $this->_default_label);
         }
     } else {
         $popup_link = '<span id="id_' . $this->_uniqueid . '_label"></span> ';
         if ($this->_selection_enabled === true) {
             $popup_link .= '<a onclick="ac_show_panel(\'' . $filt_action_url_base . '\');" href="#">' . get_string('filt_autoc_select', 'local_eliscore') . '</a>';
         }
         $mform->addElement('static', 'selector', $this->_label, $popup_link);
         $mform->addElement('html', '<div style="display:none;">');
         $mform->addElement('text', $this->_uniqueid . '_labelsave', '');
         $mform->setType($this->_uniqueid . '_labelsave', PARAM_TEXT);
         $mform->addElement('text', $this->_uniqueid, '');
         $mform->setType($this->_uniqueid, PARAM_TEXT);
         if (!empty($this->_default_label)) {
             $mform->setDefault($this->_uniqueid . '_labelsave', $this->_default_label);
         }
         if (!empty($this->_default_id)) {
             $mform->setDefault($this->_uniqueid, $this->_default_id);
         }
         $mform->addElement('html', '</div>');
         if (!empty($this->_filterhelp) && is_array($this->_filterhelp) && isset($this->_filterhelp[2])) {
             //$mform->addHelpButton('selector', $this->_filterhelp[0], $this->_filterhelp[2]);
         }
         $filter_js[] = 'labelsave = document.getElementById(\'id_' . $this->_uniqueid . '_labelsave\');
             labeldisp = document.getElementById(\'id_' . $this->_uniqueid . '_label\');
             if (labelsave != null && labeldisp != null) {
                 labeldisp.innerHTML = labelsave.value;
             }';
     }
     $mform->addElement('html', '<script>' . implode("\n\n", $filter_js) . '</script>');
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:78,代码来源:autocomplete_base.php

示例15: apply_filter_required_rule

 /**
  * Add custom requirement rules to filter elements
  *
  * @param   object $mform  The mform object for the filter page
  * @param   string $key    The filter field key
  * @param   object $fields The filter field values object
  *
  * @return  object $mform  The modified mform object for the filter page
  */
 public static function apply_filter_required_rule($mform, $key, $fields)
 {
     $elem = "{$key}_grp";
     if ($mform->elementExists($elem)) {
         $mform->addRule($elem, get_string('required'), 'required', null, 'client');
         $mform->registerRule('custom_rule', 'function', 'course_completion_check_custom_rule');
         $mform->addRule($elem, get_string('required'), 'custom_rule', array($key, $fields));
     }
     return $mform;
 }
开发者ID:jamesmcq,项目名称:elis,代码行数:19,代码来源:course_completion_by_cluster_report.class.php


注:本文中的object::addRule方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。