PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/library/XenForo/Model/LinkForum.php

https://github.com/hanguyenhuu/DTUI_201105
PHP | 74 lines | 41 code | 8 blank | 25 comment | 1 complexity | d2622c3b818666d9030058652c030ced MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, BSD-3-Clause
  1. <?php
  2. class XenForo_Model_LinkForum extends XenForo_Model
  3. {
  4. /**
  5. * Fetches the combined node-link record for the specified node id
  6. *
  7. * @param integer $id Node ID
  8. *
  9. * @return array
  10. */
  11. public function getLinkForumById($id, array $fetchOptions = array())
  12. {
  13. $joinOptions = $this->prepareLinkForumJoinOptions($fetchOptions);
  14. return $this->_getDb()->fetchRow('
  15. SELECT node.*, link_forum.*
  16. ' . $joinOptions['selectFields'] . '
  17. FROM xf_link_forum AS link_forum
  18. INNER JOIN xf_node AS node ON (node.node_id = link_forum.node_id)
  19. ' . $joinOptions['joinTables'] . '
  20. WHERE node.node_id = ?
  21. ', $id);
  22. }
  23. /**
  24. * Checks the 'join' key of the incoming array for the presence of the FETCH_x bitfields in this class
  25. * and returns SQL snippets to join the specified tables if required
  26. *
  27. * @param array $fetchOptions Array containing a 'join' integer key build from this class's FETCH_x bitfields and other keys
  28. *
  29. * @return array Containing 'selectFields' and 'joinTables' keys. Example: selectFields = ', user.*, foo.title'; joinTables = ' INNER JOIN foo ON (foo.id = other.id) '
  30. */
  31. public function prepareLinkForumJoinOptions(array $fetchOptions)
  32. {
  33. $selectFields = '';
  34. $joinTables = '';
  35. $db = $this->_getDb();
  36. if (!empty($fetchOptions['permissionCombinationId']))
  37. {
  38. $selectFields .= ',
  39. permission.cache_value AS node_permission_cache';
  40. $joinTables .= '
  41. LEFT JOIN xf_permission_cache_content AS permission
  42. ON (permission.permission_combination_id = ' . $db->quote($fetchOptions['permissionCombinationId']) . '
  43. AND permission.content_type = \'node\'
  44. AND permission.content_id = link_forum.node_id)';
  45. }
  46. return array(
  47. 'selectFields' => $selectFields,
  48. 'joinTables' => $joinTables
  49. );
  50. }
  51. /**
  52. * Determines if the specified link forum can be viewed with the given permissions.
  53. *
  54. * @param array $linkForum Info about the link forum
  55. * @param string $errorPhraseKey Returned phrase key for a specific error
  56. * @param array|null $nodePermissions List of permissions for this page; if not provided, use visitor's permissions
  57. * @param array|null $viewingUser
  58. *
  59. * @return boolean
  60. */
  61. public function canViewLinkForum(array $linkForum, &$errorPhraseKey = '', array $nodePermissions = null, array $viewingUser = null)
  62. {
  63. $this->standardizeViewingUserReferenceForNode($linkForum['node_id'], $viewingUser, $nodePermissions);
  64. return XenForo_Permission::hasContentPermission($nodePermissions, 'view');
  65. }
  66. }