PageRenderTime 61ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Intraface/modules/intranetmaintenance/Controller/User/Show.php

https://github.com/intraface/intraface.dk
PHP | 283 lines | 161 code | 34 blank | 88 comment | 23 complexity | baaa6d57d456fd8cd645fbdae4bd1131 MD5 | raw file
  1. <?php
  2. class Intraface_modules_intranetmaintenance_Controller_User_Show extends k_Component
  3. {
  4. public $method = 'put';
  5. protected $user;
  6. protected $intranetmaintenance;
  7. protected $template;
  8. protected $mdb2;
  9. function __construct(k_TemplateFactory $template, MDB2_Driver_Common $mdb2)
  10. {
  11. $this->mdb2 = $mdb2;
  12. $this->template = $template;
  13. }
  14. function dispatch()
  15. {
  16. if ($this->query('intranet_id')) {
  17. if ($this->getUser()->hasIntranetAccess($this->query('intranet_id'))) {
  18. $this->url_state->set("intranet_id", $this->query('intranet_id'));
  19. } else {
  20. $this->url_state->set("intranet_id", 0);
  21. }
  22. }
  23. return parent::dispatch();
  24. }
  25. protected function map($name)
  26. {
  27. if ($name == 'permission') {
  28. return 'Intraface_modules_intranetmaintenance_Controller_User_Permission';
  29. }
  30. }
  31. function renderHtml()
  32. {
  33. $user_id = intval($this->name());
  34. $user = new UserMaintenance($this->name());
  35. $intranet = null;
  36. if (isset($_GET['return_redirect_id'])) {
  37. if ($this->query('intranet_id')) {
  38. $intranet = new IntranetMaintenance($this->query('intranet_id'));
  39. $edit_intranet_id = $intranet->get('id');
  40. }
  41. $redirect = Intraface_Redirect::factory($kernel, 'return');
  42. if ($redirect->get('identifier') == 'add_user') {
  43. $user = new UserMaintenance($redirect->getParameter('user_id'));
  44. $user->setIntranetAccess($intranet->get('id'));
  45. $user_id = $user->get('id');
  46. }
  47. }
  48. $edit_intranet_id = $this->query('intranet_id');
  49. if (!empty($edit_intranet_id)) {
  50. $intranet = new IntranetMaintenance(intval($edit_intranet_id));
  51. if ($user->hasIntranetAccess($edit_intranet_id)) {
  52. $user->setIntranetId(intval($edit_intranet_id));
  53. $address = $user->getAddress();
  54. if (isset($address)) {
  55. $value_address = $user->getAddress()->get();
  56. }
  57. }
  58. }
  59. // @todo a little hacky
  60. $this->intranetmaintenance = $intranet;
  61. $data = array(
  62. 'intranet' => $intranet,
  63. 'user' => $user);
  64. $smarty = $this->template->create(dirname(__FILE__) . '/../templates/user/show');
  65. return $smarty->render($this, $data);
  66. }
  67. function putForm()
  68. {
  69. $user = new UserMaintenance(intval($this->name()));
  70. if ($this->context->getIntranet()->get('id') != 0) {
  71. $intranet = new Intraface_Intranet($this->context->getIntranet()->get('id'));
  72. $intranet_id = $intranet->get("id");
  73. $address_value = $_POST;
  74. $address_value["name"] = $_POST["address_name"];
  75. } else {
  76. $intranet_id = 0;
  77. $address_value = array();
  78. }
  79. $value = $_POST;
  80. if ($user->update($_POST)) {
  81. if (isset($intranet)) {
  82. $user->setIntranetAccess($intranet->get('id'));
  83. $user->setIntranetId($intranet->get('id'));
  84. $user->getAddress()->save($address_value);
  85. }
  86. return new k_SeeOther($this->url(null));
  87. }
  88. return $this->render();
  89. }
  90. function renderHtmlEdit()
  91. {
  92. $smarty = $this->template->create(dirname(__FILE__) . '/../templates/user/edit');
  93. return $smarty->render($this);
  94. }
  95. function renderVcard()
  96. {
  97. // instantiate a builder object
  98. // (defaults to version 3.0)
  99. $vcard = new Contact_Vcard_Build();
  100. // set a formatted name
  101. $vcard->setFormattedName($this->getUser()->get('name'));
  102. // set the structured name parts
  103. // @todo adskille navnet i fornavn og efternavn
  104. $vcard->setName($this->getUser()->get('name'), $this->getUser()->get('name'), '', '', '');
  105. // add phone
  106. $vcard->addTelephone($this->getUser()->getAddress()->get('phone'));
  107. $vcard->addParam('TYPE', 'HOME');
  108. $vcard->addParam('TYPE', 'PREF');
  109. // add a home/preferred email
  110. $vcard->addEmail($this->getUser()->getAddress()->get('email'));
  111. $vcard->addParam('TYPE', 'HOME');
  112. $vcard->addParam('TYPE', 'PREF');
  113. // add a work address
  114. $vcard->addAddress('', '', $this->getUser()->getAddress()->get('address'), $this->getUser()->getAddress()->get('city'), '', $this->getUser()->getAddress()->get('postcode'), $this->getUser()->getAddress()->get('country'));
  115. $vcard->addParam('TYPE', 'WORK');
  116. // get back the vCard and print it
  117. return $vcard->fetch();
  118. }
  119. /*
  120. function _getValues()
  121. {
  122. $user = new UserMaintenance($this->name());
  123. $value = $user->get();
  124. $value_address = array();
  125. if (isset($_GET['intranet_id'])) {
  126. $edit_intranet_id = intval($_GET['intranet_id']);
  127. }
  128. if (isset($edit_intranet_id)) {
  129. $intranet = new IntranetMaintenance(intval($edit_intranet_id));
  130. $user->setIntranetId(intval($intranet->get('id')));
  131. $address = $user->getAddress();
  132. if (isset($address)) {
  133. $value_address = $user->getAddress()->get();
  134. }
  135. }
  136. return array_merge($value, $value_address);
  137. }
  138. */
  139. function getValues()
  140. {
  141. $user = $this->getUser();
  142. $value = $user->get();
  143. if ($this->query('intranet_id') > 0 and $user->hasIntranetAccess($this->query('intranet_id'))) {
  144. $intranet_id = intval($this->query('intranet_id'));
  145. $user->setIntranetId($intranet_id);
  146. $address_value = $user->getAddress()->get();
  147. } else {
  148. $intranet_id = 0;
  149. $address_value = array();
  150. }
  151. return array_merge($address_value, $value);
  152. }
  153. function getUser()
  154. {
  155. $module = $this->getKernel()->module("intranetmaintenance");
  156. $translation = $this->getKernel()->getTranslation('intranetmaintenance');
  157. if (is_object($this->user)) {
  158. return $this->user;
  159. }
  160. $this->user = new UserMaintenance($this->name());
  161. if ($this->query('intranet') > 0 and $this->user->hasIntranetAccess($this->query('intranet'))) {
  162. $this->user->setIntranetId($this->query('intranet_id'));
  163. }
  164. return ($this->user);
  165. }
  166. function getIntranet()
  167. {
  168. if (is_object($this->intranetmaintenance)) {
  169. return $this->intranetmaintenance;
  170. }
  171. if (method_exists($this->context, 'getIntranet') and $this->context->getIntranet()->getId() > 0) {
  172. return $this->intranetmaintenance = new IntranetMaintenance($this->context->getIntranet()->getId());
  173. }
  174. return $this->intranetmaintenance = new IntranetMaintenance($this->query('intranet_id'));
  175. }
  176. function getKernel()
  177. {
  178. return $this->context->getKernel();
  179. }
  180. /*
  181. function postForm()
  182. {
  183. $module = $this->getKernel()->module("intranetmaintenance");
  184. $user = new UserMaintenance(intval($this->name()));
  185. $intranet = new IntranetMaintenance(intval($_POST["intranet_id"]));
  186. $user->setIntranetId($intranet->get("id"));
  187. $modules = array();
  188. if (isset($_POST['module'])) {
  189. $modules = $_POST["module"];
  190. } else {
  191. $modules = array();
  192. }
  193. if (isset($_POST['sub_access'])) {
  194. $sub_access = $_POST["sub_access"];
  195. } else {
  196. $sub_access = array();
  197. }
  198. $user->flushAccess();
  199. if (!isset($_POST["intranetaccess"])) {
  200. // Access to intranet is not set. We show the user, but not with the intranet.
  201. $user_id = intval($this->name());
  202. unset($user);
  203. unset($intranet);
  204. } else {
  205. // S�tter adgang til det redigerede intranet. Id kommer tidligere ved setIntranetId
  206. $user->setIntranetAccess();
  207. // Hvis en bruger retter sig selv, i det aktive intranet, s�tter vi adgang til dette modul
  208. if ($this->getKernel()->user->get("id") == $user->get("id") && $this->getKernel()->intranet->get("id") == $intranet->get("id")) {
  209. // Finder det aktive intranet
  210. $active_module = $this->getKernel()->getPrimaryModule();
  211. // Giver adgang til det
  212. $user->setModuleAccess($active_module->getId());
  213. }
  214. for ($i = 0, $max = count($modules); $i < $max; $i++) {
  215. $user->setModuleAccess($modules[$i]);
  216. if (!empty($sub_access[$modules[$i]])) {
  217. for ($j = 0, $max1 = count($sub_access[$modules[$i]]); $j < $max1; $j++) {
  218. $user->setSubAccess($modules[$i], $sub_access[$modules[$i]][$j]);
  219. }
  220. }
  221. }
  222. $user_id = $user->get('id');
  223. $edit_intranet_id = $intranet->get('id');
  224. return new k_SeeOther($this->url(null, array('intranet_id' => $edit_intranet_id)));
  225. }
  226. }
  227. */
  228. function getIntranets()
  229. {
  230. $intranet = new IntranetMaintenance();
  231. $intranet->getDBQuery($this->getKernel())->setFilter('user_id', $this->getUser()->get('id'));
  232. return $intranet->getList();
  233. }
  234. function getModules()
  235. {
  236. $gateway = new Intraface_ModuleGateway($this->mdb2);
  237. return $gateway->getList();
  238. }
  239. }