/XoopsEngine/lib/Engine/Xoops/Registry/User.php

https://github.com/xoops-pi/engine · PHP · 180 lines · 130 code · 14 blank · 36 comment · 34 complexity · c846e465b8da0666534b6494d7a091b0 MD5 · raw file

  1. <?php
  2. /**
  3. * XOOPS user meta registry
  4. *
  5. * You may not change or alter any portion of this comment or credits
  6. * of supporting developers from this source code or any supporting source code
  7. * which is considered copyrighted (c) material of the original comment or credit authors.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Different actions -
  13. *
  14. * For edit:
  15. * null method - use default form element "Text"
  16. * empty method - hide the element
  17. * method is string - use system form element
  18. * method is array([module], element, [options]) - use module form element
  19. *
  20. * For admin:
  21. * null method - inherite from edit
  22. * otherwise - same mehtods as edit
  23. *
  24. * For view:
  25. * null method - use raw data
  26. * empty method - hide the data
  27. * method is array(module, element) - transform raw data via the module_profile::method
  28. *
  29. * @copyright Xoops Engine http://www.xoopsengine.org/
  30. * @license http://www.fsf.org/copyleft/gpl.html GNU public license
  31. * @author Taiwen Jiang <phppp@users.sourceforge.net>
  32. * @since 3.0
  33. * @package Xoops_Core
  34. * @subpackage Registry
  35. * @version $Id$
  36. */
  37. namespace Engine\Xoops\Registry;
  38. class User extends \Kernel\Registry
  39. {
  40. //protected $registry_key = "registry_role";
  41. protected function loadDynamic($options = array())
  42. {
  43. $parseView = function ($row)
  44. {
  45. $view = array();
  46. if (!empty($row->view)) {
  47. $view["method"] = array($row->module . "_profile", $row->view);
  48. } elseif (!empty($row->options)) {
  49. $view["options"] = unserialize($row->options);
  50. }
  51. return $view;
  52. };
  53. $parseEdit = function ($row, $action)
  54. {
  55. if ($action == "admin") {
  56. $input = is_null($row->admin) ? $row->edit : $row->admin;
  57. } else {
  58. $input = $row->edit;
  59. }
  60. if (!empty($input)) {
  61. $input = unserialize($input);
  62. if (is_string($input) && !empty($input)) {
  63. $input = array("type" => $input);
  64. }
  65. if (empty($input["options"]["multiOptions"])) {
  66. if (!empty($row->options)) {
  67. $input["options"]["multiOptions"] = unserialize($row->options);
  68. }
  69. }
  70. if (!empty($input["module"])) {
  71. $input["module"] = $row->module;
  72. }
  73. }
  74. if (!empty($input) || is_null($input)) {
  75. $input["options"]["label"] = $row->title;
  76. if ($row->required) {
  77. $meta["options"]["required"] = 1;
  78. }
  79. }
  80. return $input;
  81. };
  82. $parseSearch = function ($row)
  83. {
  84. if (!is_null($row->search)) {
  85. $input = $row->search;
  86. } elseif (!empty($row->edit)) {
  87. $input = $row->edit;
  88. } elseif (!empty($row->admin)) {
  89. $input = $row->admin;
  90. }
  91. if (!empty($input)) {
  92. $input = unserialize($input);
  93. if (is_string($input) && !empty($input)) {
  94. $input = array("type" => $input);
  95. }
  96. if (empty($input["options"]["multiOptions"])) {
  97. if (!empty($row->options)) {
  98. $input["options"]["multiOptions"] = unserialize($row->options);
  99. }
  100. }
  101. if (!empty($input["module"])) {
  102. $input["module"] = $row->module;
  103. }
  104. }
  105. if (!empty($input) || is_null($input)) {
  106. $input["options"]["label"] = $row->title;
  107. }
  108. return $input;
  109. };
  110. $model = \Xoops::getModel("user_meta");
  111. $select = $model->select()->where("active = ?", 1)->order("id ASC");
  112. $rowset = $model->fetchAll($select);
  113. $data = array();
  114. foreach ($rowset as $row) {
  115. if ($options["action"] == "edit") {
  116. if ($meta = $parseEdit($row, "edit")) {
  117. $data[$row->key] = $meta;
  118. }
  119. continue;
  120. }
  121. if ($options["action"] == "admin") {
  122. if ($meta = $parseEdit($row, "admin")) {
  123. $data[$row->key] = $meta;
  124. }
  125. continue;
  126. }
  127. if ($options["action"] == "search") {
  128. if ($meta = $parseSearch($row)) {
  129. $data[$row->key] = $meta;
  130. }
  131. continue;
  132. }
  133. if (isset($row->view)) {
  134. $data[$row->key] = $parseView($row);
  135. }
  136. $data[$row->key]["title"] = $row->title;
  137. }
  138. return $data;
  139. }
  140. public function read($action = "view", $meta = null)
  141. {
  142. $options = compact("action");
  143. $data = $this->loadData($options);
  144. if (isset($meta)) {
  145. $result = isset($data[$meta]) ? $data[$meta] : false;
  146. } else {
  147. $result = $data;
  148. }
  149. return $result;
  150. }
  151. public function create($action = "view")
  152. {
  153. self::delete($action);
  154. self::read($action);
  155. return true;
  156. }
  157. public function delete($action = null)
  158. {
  159. $options = compact("action");
  160. return $this->cache->clean('matchingTag', self::createTags($options));
  161. }
  162. public function flush()
  163. {
  164. return self::delete();
  165. }
  166. }