PageRenderTime 129ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/user/profile/field/menu/define.class.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 41 lines | 25 code | 12 blank | 4 comment | 1 complexity | f5de623f605e45e9eb8f4c81094c3cf0 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-3.0
  1. <?php
  2. class profile_define_menu extends profile_define_base {
  3. function define_form_specific($form) {
  4. /// Param 1 for menu type contains the options
  5. $form->addElement('textarea', 'param1', get_string('profilemenuoptions', 'admin'), array('rows' => 6, 'cols' => 40));
  6. $form->setType('param1', PARAM_TEXT);
  7. /// Default data
  8. $form->addElement('text', 'defaultdata', get_string('profiledefaultdata', 'admin'), 'size="50"');
  9. $form->setType('defaultdata', PARAM_TEXT);
  10. }
  11. function define_validate_specific($data, $files) {
  12. $err = array();
  13. $data->param1 = str_replace("\r", '', $data->param1);
  14. /// Check that we have at least 2 options
  15. if (($options = explode("\n", $data->param1)) === false) {
  16. $err['param1'] = get_string('profilemenunooptions', 'admin');
  17. } elseif (count($options) < 2) {
  18. $err['param1'] = get_string('profilemenutoofewoptions', 'admin');
  19. /// Check the default data exists in the options
  20. } elseif (!empty($data->defaultdata) and !in_array($data->defaultdata, $options)) {
  21. $err['defaultdata'] = get_string('profilemenudefaultnotinoptions', 'admin');
  22. }
  23. return $err;
  24. }
  25. function define_save_preprocess($data) {
  26. $data->param1 = str_replace("\r", '', $data->param1);
  27. return $data;
  28. }
  29. }