本文整理汇总了PHP中DataObjectSet::insertFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectSet::insertFirst方法的具体用法?PHP DataObjectSet::insertFirst怎么用?PHP DataObjectSet::insertFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataObjectSet
的用法示例。
在下文中一共展示了DataObjectSet::insertFirst方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DataObjectSet
/**
* 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)
{
// Rationalise member arguments
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\" \n\t\t\t\tON \"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"\n\t\t\tINNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\"\n\t\t\t\tOR \"Group\".\"AccessAllSubsites\" = 1\n\t\t\tINNER JOIN \"Group_Members\" \n\t\t\t\tON \"Group_Members\".\"GroupID\"=\"Group\".\"ID\"\n\t\t\t\tAND \"Group_Members\".\"MemberID\" = {$member->ID}\n\t\t\tINNER JOIN \"Permission\" \n\t\t\t\tON \"Group\".\"ID\"=\"Permission\".\"GroupID\"\n\t\t\t\tAND \"Permission\".\"Code\" IN ({$SQL_codes}, 'ADMIN')");
$rolesSubsites = DataObject::get('Subsite', "\"Subsite\".\"Title\" != ''", '', "LEFT JOIN \"Group_Subsites\" \n\t\t\t\tON \"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"\n\t\t\tINNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\"\n\t\t\t\tOR \"Group\".\"AccessAllSubsites\" = 1\n\t\t\tINNER JOIN \"Group_Members\" \n\t\t\t\tON \"Group_Members\".\"GroupID\"=\"Group\".\"ID\"\n\t\t\t\tAND \"Group_Members\".\"MemberID\" = {$member->ID}\n\t\t\tINNER JOIN \"Group_Roles\"\n\t\t\t\tON \"Group_Roles\".\"GroupID\"=\"Group\".\"ID\"\n\t\t\tINNER JOIN \"PermissionRole\"\n\t\t\t\tON \"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\"\n\t\t\tINNER JOIN \"PermissionRoleCode\"\n\t\t\t\tON \"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\"\n\t\t\t\tAND \"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);
}
}
}
// Include the main site
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;
}