This repository has been archived by the owner on Jan 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewlevels.php
68 lines (63 loc) · 2.17 KB
/
viewlevels.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
// no direct access
defined( '_JEXEC' ) or die;
class plgSwaViewLevels extends JPlugin
{
/**
* Load the language file on instantiation. Note this is only available in Joomla 3.1 and higher.
* If you want to support 3.0 series you must override the constructor
*
* @var boolean
* @since 3.1
*/
protected $autoloadLanguage = false;
/**
* Plugin method with the same name as the event will be called automatically.
*/
function onJAccessGetAuthorisedViewLevels( $userId, &$authorised )
{
//TODO check com_swa is loaded before we try to do this?
//TODO XXX this is taken straight from SwaModelList::getMember. SHOULD REUSE
// Create a new query object.
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$user = JFactory::getUser( $userId );
// Select the required fields from the table.
$query->select( 'a.*' );
$query->from( $db->quoteName('#__swa_member') . ' AS a' );
$query->where( 'a.user_id = ' . $user->id );
// Join on committee table
$query->leftJoin( '#__swa_committee as committee on committee.member_id = a.id' );
$query->select( '!ISNULL(committee.id) as swa_committee' );
// Join on committee table
$query->leftJoin( '#__swa_university_member as uni_member on uni_member.member_id = a.id' );
$query->select( 'IF( uni_member.committee = "None", NULL, 1 ) as club_committee' );
// Load the result
$db->setQuery($query);
$member = $db->loadObject();
// Load the view levels for the component from the DB
$viewLevelQuery = $db->getQuery(true)
->select('id, title')
->from($db->quoteName('#__viewlevels'));
$db->setQuery($viewLevelQuery);
foreach ($db->loadAssocList() as $level) {
if( $level['title'] == 'Club Committee' ) {
$aclClubCommittee = intval( $level['id'] );
}
if( $level['title'] == 'Org Committee' ) {
$aclOrgCommittee = intval( $level['id'] );
}
}
// If one of them was not found then return
if( !isset( $aclClubCommittee ) || !isset( $aclOrgCommittee ) ) {
//TODO log?
return;
}
if( is_object( $member ) && $member->club_committee ){
$authorised[] = $aclClubCommittee;
}
if( is_object( $member ) && $member->swa_committee ){
$authorised[] = $aclOrgCommittee;
}
}
}