code/Subsite.php
/**
	 * Return the subsites that the current user can access.
	 * Look for one of the given permission codes on the site.
	 *
	 * Sites and Templates will only be included if they have a Title
	 *
	 * @param $permCode array|string Either a single permission code or an array of permission codes.
	 * @param $includeMainSite If true, the main site will be included if appropriate.
	 * @param $mainSiteTitle The label to give to the main site
	 */
Return the subsites that the current user can access.
Look for one of the given permission codes on the site.

Sites and Templates will only be included if they have a Title

@param $permCode array|string Either a single permission code or an array of permission codes.
@param $includeMainSite If true, the main site will be included if appropriate.
@param $mainSiteTitle The label to give to the main site
Return the subsites that the current user can access . Look for one of the given permission codes on the site . Sites and Templates will only be included if they have a Title @param $permCode array|string Either a single permission code or an array of permission codes . @param $includeMainSite If true the main site will be included if appropriate . @param $mainSiteTitle The label to give to the main site
function accessible_sites($permCode, $includeMainSite = false, $mainSiteTitle = "Main site", $member = null) {
		if(!$member) $member = Member::currentUser();
		if(!$member) return new DataObjectSet();
		if(!is_object($member)) $member = DataObject::get_by_id('Member', $member);
		if(is_array($permCode))	$SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
		else $SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
		$templateClassList = "'" . implode("', '", ClassInfo::subclassesFor("Subsite_Template")) . "'";
		$subsites = DataObject::get(
			'Subsite',
			"\"Subsite\".\"Title\" != ''",
			'',
			"LEFT JOIN \"Group_Subsites\" 
				ON \"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"
			INNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\"
				OR \"Group\".\"AccessAllSubsites\" = 1
			INNER JOIN \"Group_Members\" 
				ON \"Group_Members\".\"GroupID\"=\"Group\".\"ID\"
				AND \"Group_Members\".\"MemberID\" = $member->ID
			INNER JOIN \"Permission\" 
				ON \"Group\".\"ID\"=\"Permission\".\"GroupID\"
				AND \"Permission\".\"Code\" IN ($SQL_codes, 'ADMIN')"
		);
		$rolesSubsites = DataObject::get(
			'Subsite',
			"\"Subsite\".\"Title\" != ''",
			'',
			"LEFT JOIN \"Group_Subsites\" 
				ON \"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"
			INNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\"
				OR \"Group\".\"AccessAllSubsites\" = 1
			INNER JOIN \"Group_Members\" 
				ON \"Group_Members\".\"GroupID\"=\"Group\".\"ID\"
				AND \"Group_Members\".\"MemberID\" = $member->ID
			INNER JOIN \"Group_Roles\"
				ON \"Group_Roles\".\"GroupID\"=\"Group\".\"ID\"
			INNER JOIN \"PermissionRole\"
				ON \"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\"
			INNER JOIN \"PermissionRoleCode\"
				ON \"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\"
				AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'ADMIN')"
		);
		if(!$subsites && $rolesSubsites) return $rolesSubsites;
		if($rolesSubsites) foreach($rolesSubsites as $subsite) {
			if(!$subsites->containsIDs(array($subsite->ID))) {
				$subsites->push($subsite);
			}
		}
		if(!$subsites) $subsites = new DataObjectSet();
		if($includeMainSite) {
			if(!is_array($permCode)) $permCode = array($permCode);
			if(self::hasMainSitePermission($member, $permCode)) {
				$mainSite = new Subsite();
				$mainSite->Title = $mainSiteTitle;
				$subsites->insertFirst($mainSite);
			}
		}
		return $subsites;
	}
function accessible_sites ( $ permCode , $ includeMainSite = false , $ mainSiteTitle = " Main site " , $ member = null ) { if ( ! $ member ) $ member = Member :: currentUser ( ) ; if ( ! $ member ) return new DataObjectSet ( ) ; if ( ! is_object ( $ member ) ) $ member = DataObject :: get_by_id ( 'Member' , $ member ) ; if ( is_array ( $ permCode ) ) $ SQL_codes = " ' " . implode ( " ', ' " , Convert :: raw2sql ( $ permCode ) ) . " ' " ; else $ SQL_codes = " ' " . Convert :: raw2sql ( $ permCode ) . " ' " ; $ templateClassList = " ' " . implode ( " ', ' " , ClassInfo :: subclassesFor ( " Subsite_Template " ) ) . " ' " ; $ subsites = DataObject :: get ( 'Subsite' , " \" Subsite \" . \" Title \"  != '' " , '' , " LEFT JOIN  \" Group_Subsites \"  
				ON  \" Group_Subsites \" . \" SubsiteID \"  =  \" Subsite \" . \" ID \" 
			INNER JOIN  \" Group \"  ON  \" Group \" . \" ID \"  =  \" Group_Subsites \" . \" GroupID \" 
				OR  \" Group \" . \" AccessAllSubsites \"  = 1
			INNER JOIN  \" Group_Members \"  
				ON  \" Group_Members \" . \" GroupID \" = \" Group \" . \" ID \" 
				AND  \" Group_Members \" . \" MemberID \"  =  $ member -> ID 
			INNER JOIN  \" Permission \"  
				ON  \" Group \" . \" ID \" = \" Permission \" . \" GroupID \" 
				AND  \" Permission \" . \" Code \"  IN ( $ SQL_codes , 'ADMIN') " ) ; $ rolesSubsites = DataObject :: get ( 'Subsite' , " \" Subsite \" . \" Title \"  != '' " , '' , " LEFT JOIN  \" Group_Subsites \"  
				ON  \" Group_Subsites \" . \" SubsiteID \"  =  \" Subsite \" . \" ID \" 
			INNER JOIN  \" Group \"  ON  \" Group \" . \" ID \"  =  \" Group_Subsites \" . \" GroupID \" 
				OR  \" Group \" . \" AccessAllSubsites \"  = 1
			INNER JOIN  \" Group_Members \"  
				ON  \" Group_Members \" . \" GroupID \" = \" Group \" . \" ID \" 
				AND  \" Group_Members \" . \" MemberID \"  =  $ member -> ID 
			INNER JOIN  \" Group_Roles \" 
				ON  \" Group_Roles \" . \" GroupID \" = \" Group \" . \" ID \" 
			INNER JOIN  \" PermissionRole \" 
				ON  \" Group_Roles \" . \" PermissionRoleID \" = \" PermissionRole \" . \" ID \" 
			INNER JOIN  \" PermissionRoleCode \" 
				ON  \" PermissionRole \" . \" ID \" = \" PermissionRoleCode \" . \" RoleID \" 
				AND  \" PermissionRoleCode \" . \" Code \"  IN ( $ SQL_codes , 'ADMIN') " ) ; if ( ! $ subsites && $ rolesSubsites ) return $ rolesSubsites ; if ( $ rolesSubsites ) foreach ( $ rolesSubsites as $ subsite ) { if ( ! $ subsites -> containsIDs ( array ( $ subsite -> ID ) ) ) { $ subsites -> push ( $ subsite ) ; } } if ( ! $ subsites ) $ subsites = new DataObjectSet ( ) ; if ( $ includeMainSite ) { if ( ! is_array ( $ permCode ) ) $ permCode = array ( $ permCode ) ; if ( self :: hasMainSitePermission ( $ member , $ permCode ) ) { $ mainSite = new Subsite ( ) ; $ mainSite -> Title = $ mainSiteTitle ; $ subsites -> insertFirst ( $ mainSite ) ; } } return $ subsites ; }
Return the subsites that the current user can access.
Return the subsites that the current user can access .
// Rationalise member arguments // Include the main site