Source for file registrar_factory.php

Documentation is available at registrar_factory.php

  1. <?php
  2.  
  3. class net_nemein_registrations_registrar_factory {
  4. var $_debug_prefix;
  5.  
  6. var $_config;
  7. var $_topic;
  8. var $_auth;
  9. var $_group;
  10. var $_l10n;
  11. var $_l10n_midcom;
  12. var $_person_cache;
  13. var $_mail_to_person_map;
  14. function net_nemein_registrations_registrar_factory(&$topic, &$config, &$auth, &$group) {
  15. $this->_debug_prefix = "net.nemein.registrations registrar_factory::";
  16. debug_push($this->_debug_prefix . "constructor");
  17. $this->_config =& $config;
  18. $this->_topic =& $topic;
  19. $this->_auth =& $auth;
  20. $this->_group =& $group;
  21. $i18n =& $GLOBALS["midcom"]->get_service("i18n");
  22. $this->_l10n = $i18n->get_l10n("net.nemein.registrations");
  23. $this->_l10n_midcom = $i18n->get_l10n("midcom");
  24. $this->_person_cache = Array();
  25. $this->_mail_to_person_map = Array();
  26. $this->update_cache();
  27. debug_pop();
  28. }
  29. function update_cache () {
  30. if (! $this->_su())
  31. return false;
  32. debug_push ($this->_debug_prefix . "update_cache");
  33. $this->_person_cache = Array();
  34. $this->_mail_to_person_map = Array();
  35. $members = mgd_list_members($this->_group->id);
  36. if ($members) {
  37. while($members->fetch()){
  38. $id = $members->uid;
  39. $person = mgd_get_person($id);
  40. if (! $person) {
  41. debug_print_r("Could not load Person $id (" . mgd_errstr()
  42. . "), this is strange as the ID $id comes out of this fetchable:",
  43. $members
  44. );
  45. continue;
  46. }
  47. $this->_person_cache[$id] = $person;
  48. $this->_mail_to_person_map[$person->email] =& $this->_person_cache[$id];
  49. }
  50. } else {
  51. debug_add("No active accounts found.");
  52. }
  53. debug_print_r("mailtopersonmap:", $this->_mail_to_person_map);
  54. $this->_su(false);
  55. debug_pop();
  56. return true;
  57. }
  58. function getby_id ($id) {
  59. if ($this->exists_id($id))
  60. return $this->_person_cache[$id];
  61. else
  62. return null;
  63. }
  64. function getby_email ($mail) {
  65. if ($this->exists_email($mail))
  66. return $this->_mail_to_person_map[$mail];
  67. else
  68. return null;
  69. }
  70. function exists_id ($id) {
  71. return array_key_exists($id, $this->_person_cache);
  72. }
  73. function exists_email ($email) {
  74. return array_key_exists($email, $this->_mail_to_person_map);
  75. }
  76. function _su ($on = true) {
  77. if ($on) {
  78. if (! mgd_auth_midgard ($this->_config->get("admin_user"), $this->_config->get("admin_password"), false)) {
  79. debug_add("mgd_auth_midgard to admin level user failed:" . mgd_errstr());
  80. return false;
  81. } else {
  82. /* Call mgd_get_midgard, seems to be required according to emile/piotras */
  83. $midgard = mgd_get_midgard();
  84. debug_print_r("New midgard object is: ", $midgard);
  85. return true;
  86. }
  87. } else {
  88. $result = mgd_unsetuid();
  89. /* Call mgd_get_midgard, seems to be required according to emile/piotras */
  90. $unused = mgd_get_midgard();
  91. return $result;
  92. }
  93. }
  94. }
  95.  
  96. ?>

Documentation generated on Mon, 21 Nov 2005 18:21:10 +0100 by phpDocumentor 1.3.0RC3