作者:Beyzi
项目:Garde
public function ApplyTheme($OriginalPath, $CachePath, $InsertNames = TRUE)
{
// Get the theme settings.
$SQL = Gdn::SQL();
if (is_null($this->ThemeSettings)) {
$Data = $SQL->Get('ThemeSetting')->ResultArray();
$Data = ConsolidateArrayValuesByKey($Data, 'Name', 'Setting', '');
$this->ThemeSettings = $Data;
}
$Css = file_get_contents($OriginalPath);
// Process the urls.
$Css = preg_replace_callback(self::UrlRegEx, array($this, '_ApplyUrl'), $Css);
// Go through the css and replace its colors with the theme colors.
$Css = preg_replace_callback(self::RegEx, array($this, '_ApplyThemeSetting'), $Css);
// Insert the missing settings into the database.
if ($InsertNames) {
foreach ($this->MissingSettings as $Name => $Setting) {
$SQL->Insert('ThemeSetting', array('Name' => $Name, 'Setting' => $Setting));
}
$this->MissingSettings = array();
}
// Save the theme to the cache path.
file_put_contents($CachePath, $Css);
return $CachePath;
}
作者:elpu
项目:TgaForumBundl
/**
* Grabs all new notifications and adds them to the sender's inform queue.
*
* This method gets called by dashboard's hooks file to display new
* notifications on every pageload.
*
* @since 2.0.18
* @access public
*
* @param Gdn_Controller $Sender The object calling this method.
*/
public static function InformNotifications($Sender)
{
$Session = Gdn::Session();
if (!$Session->IsValid()) {
return;
}
$ActivityModel = new ActivityModel();
// Get five pending notifications.
$Where = array('NotifyUserID' => Gdn::Session()->UserID, 'Notified' => ActivityModel::SENT_PENDING);
// If we're in the middle of a visit only get very recent notifications.
$Where['DateUpdated >'] = Gdn_Format::ToDateTime(strtotime('-5 minutes'));
$Activities = $ActivityModel->GetWhere($Where, 0, 5)->ResultArray();
$ActivityIDs = ConsolidateArrayValuesByKey($Activities, 'ActivityID');
$ActivityModel->SetNotified($ActivityIDs);
foreach ($Activities as $Activity) {
if ($Activity['Photo']) {
$UserPhoto = Anchor(Img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon');
} else {
$UserPhoto = '';
}
$Excerpt = Gdn_Format::Display($Activity['Story']);
$ActivityClass = ' Activity-' . $Activity['ActivityType'];
$Sender->InformMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon'));
}
}
作者:kerph
项目:Garde
public function DefaultRoles()
{
$this->Permission('Garden.Roles.Manage');
$this->AddSideMenu('');
$this->Title(T('Default Roles'));
// Load roles for dropdowns.
$RoleModel = new RoleModel();
$this->SetData('RoleData', $RoleModel->Get());
if ($this->Form->AuthenticatedPostBack() === FALSE) {
// Get a list of default member roles from the config.
$DefaultRoles = C('Garden.Registration.DefaultRoles');
$this->Form->SetValue('DefaultRoles', $DefaultRoles);
// Get the guest roles.
$GuestRolesData = $RoleModel->GetByUserID(0);
$GuestRoles = ConsolidateArrayValuesByKey($GuestRolesData, 'RoleID');
$this->Form->SetValue('GuestRoles', $GuestRoles);
// The applicant role.
$ApplicantRoleID = C('Garden.Registration.ApplicantRoleID', '');
$this->Form->SetValue('ApplicantRoleID', $ApplicantRoleID);
} else {
$DefaultRoles = $this->Form->GetFormValue('DefaultRoles');
$ApplicantRoleID = $this->Form->GetFormValue('ApplicantRoleID');
SaveToConfig(array('Garden.Registration.DefaultRoles' => $DefaultRoles, 'Garden.Registration.ApplicantRoleID' => $ApplicantRoleID));
$GuestRoles = $this->Form->GetFormValue('GuestRoles');
$UserModel = new UserModel();
$UserModel->SaveRoles(0, $GuestRoles, FALSE);
$this->StatusMessage = T("Saved");
}
$this->Render();
}
作者:nerdgir
项目:Forums-ILoveBadT
public function GetData($Limit = 10) {
$this->Data = FALSE;
if (Gdn::Session()->IsValid() && C('Vanilla.Modules.ShowBookmarkedModule', TRUE)) {
$BookmarkIDs = Gdn::SQL()
->Select('DiscussionID')
->From('UserDiscussion')
->Where('UserID', Gdn::Session()->UserID)
->Where('Bookmarked', 1)
->Get()->ResultArray();
$BookmarkIDs = ConsolidateArrayValuesByKey($BookmarkIDs, 'DiscussionID');
if (count($BookmarkIDs)) {
$DiscussionModel = new DiscussionModel();
DiscussionModel::CategoryPermissions();
$DiscussionModel->SQL->WhereIn('d.DiscussionID', $BookmarkIDs);
$this->Data = $DiscussionModel->Get(
0,
$Limit
);
} else {
$this->Data = FALSE;
}
}
}
作者:kidma
项目:Garde
public function GetUserInfo($UserReference = '')
{
$this->Roles = array();
if ($UserReference == '') {
$Session = Gdn::Session();
$this->User = $this->UserModel->Get($Session->UserID);
} else {
$UserReference = is_numeric($UserReference) ? $UserReference : urldecode($UserReference);
$this->User = $this->UserModel->Get($UserReference);
}
if ($this->User === FALSE) {
return $this->ReDispatch('garden/home/filenotfound');
} else {
$this->RoleData = $this->UserModel->GetRoles($this->User->UserID);
if ($this->RoleData !== FALSE && $this->RoleData->NumRows() > 0) {
$this->Roles = ConsolidateArrayValuesByKey($this->RoleData->ResultArray(), 'Name');
}
}
// Make sure the userphoto module gets added to the page
$UserPhotoModule = new UserPhotoModule($this);
$UserPhotoModule->User = $this->User;
$this->AddModule($UserPhotoModule);
$this->AddSideMenu();
return TRUE;
}
作者:robi-bob
项目:Garde
/**
* Returns an array of RoleID => RoleName pairs.
*
* @return array
*/
public function GetArray()
{
// $RoleData = $this->GetEditablePermissions();
$RoleData = $this->Get();
$RoleIDs = ConsolidateArrayValuesByKey($RoleData->ResultArray(), 'RoleID');
$RoleNames = ConsolidateArrayValuesByKey($RoleData->ResultArray(), 'Name');
return ArrayCombine($RoleIDs, $RoleNames);
}
作者:seedban
项目:old-rep
public function AvailableLocales()
{
// Get the list of locales that are supported.
$Locales = array_unique(ConsolidateArrayValuesByKey($this->AvailableLocalePacks(), 'Locale'), SORT_STRING);
asort($Locales);
$Locales = array_combine($Locales, $Locales);
return $Locales;
}
作者:seedban
项目:old-rep
protected function attachBadge($sender)
{
$roles = array();
$userModel = new UserModel();
$roleData = $userModel->GetRoles($sender->EventArguments['Author']->UserID);
if ($roleData !== FALSE && $roleData->NumRows(DATASET_TYPE_ARRAY) > 0) {
$roles = ConsolidateArrayValuesByKey($roleData->Result(), 'Name');
}
foreach ($roles as $role) {
echo '<span class="RoleBadges ' . $role . 'Badge"></span>';
}
}
作者:nerdgir
项目:Forums-ILoveBadT
public function ApplyBan($NewBan = NULL, $OldBan = NULL) {
if (!$NewBan && !$OldBan)
return;
$OldUsers = array();
$OldUserIDs = array();
$NewUsers = array();
$NewUserIDs = array();
$AllBans = $this->AllBans();
if ($NewBan) {
// Get a list of users affected by the new ban.
if (isset($NewBan['BanID']))
$AllBans[$NewBan['BanID']] = $NewBan;
$NewUsers = $this->SQL
->Select('u.UserID, u.Banned')
->From('User u')
->Where($this->BanWhere($NewBan))
->Get()->ResultArray();
$NewUserIDs = ConsolidateArrayValuesByKey($NewUsers, 'UserID');
} elseif (isset($OldBan['BanID'])) {
unset($AllBans[$OldBan['BanID']]);
}
if ($OldBan) {
// Get a list of users affected by the old ban.
$OldUsers = $this->SQL
->Select('u.UserID, u.LastIPAddress, u.Name, u.Email, u.Banned')
->From('User u')
->Where($this->BanWhere($OldBan))
->Get()->ResultArray();
$OldUserIDs = ConsolidateArrayValuesByKey($OldUsers, 'UserID');
}
// Check users that need to be unbanned.
foreach ($OldUsers as $User) {
if (in_array($User['UserID'], $NewUserIDs))
continue;
// TODO check the user against the other bans.
$this->SaveUser($User, FALSE);
}
// Check users that need to be banned.
foreach ($NewUsers as $User) {
if ($User['Banned'])
continue;
$this->SaveUser($User, TRUE);
}
}
作者:SatiricMa
项目:addon
/**
* @param Gdn_Controller $Sender
* @param array $Args
*/
public function EntryController_Render_Before($Sender, $Args)
{
if ($Sender->RequestMethod != 'passwordreset') {
return;
}
if (isset($Sender->Data['User'])) {
// Get all of the users with the same email.
$Email = $Sender->Data('User.Email');
$Users = Gdn::SQL()->Select('Name')->From('User')->Where('Email', $Email)->Get()->ResultArray();
$Names = ConsolidateArrayValuesByKey($Users, 'Name');
SetValue('Name', $Sender->Data['User'], implode(', ', $Names));
}
}
作者:SatiricMa
项目:addon
public function GetFacebookIDs($Datas, $UserIDColumn)
{
$UserIDs = array();
foreach ($Datas as $Data) {
if ($UserID = GetValue($UserIDColumn, $Data)) {
$UserIDs[] = $UserID;
} else {
$IDs = ConsolidateArrayValuesByKey($Data, $UserIDColumn);
$UserIDs = array_merge($UserIDs, $IDs);
}
}
$FbIDs = Gdn::SQL()->WhereIn('UserID', array_unique($UserIDs))->GetWhere('UserAuthentication', array('ProviderKey' => 'facebook'))->ResultArray();
$Result = ConsolidateArrayValuesByKey($FbIDs, 'UserID', 'ForeignUserKey');
return $Result;
}
作者:edward-tsa
项目:vanilla4chin
public function GetData()
{
if (Gdn::Session()->IsValid()) {
$BookmarkIDs = Gdn::SQL()->Select('DiscussionID')->From('UserDiscussion')->Where('UserID', Gdn::Session()->UserID)->Where('Bookmarked', 1)->Get()->ResultArray();
$BookmarkIDs = ConsolidateArrayValuesByKey($BookmarkIDs, 'DiscussionID');
if (count($BookmarkIDs)) {
$DiscussionModel = new DiscussionModel();
DiscussionModel::CategoryPermissions();
$DiscussionModel->SQL->WhereIn('d.DiscussionID', $BookmarkIDs);
$Bookmarks = $DiscussionModel->Get(0, $this->Limit, array('w.Bookmarked' => '1'));
$this->SetData('Bookmarks', $Bookmarks);
} else {
$this->SetData('Bookmarks', new Gdn_DataSet());
}
}
}
作者:sirno
项目:Garde
public function Index()
{
$this->AddJsFile('activity.js');
$this->Title(T('Recent Activity'));
$Session = Gdn::Session();
$this->ActivityData = $this->ActivityModel->Get();
if ($this->ActivityData->NumRows() > 0) {
$ActivityData = $this->ActivityData->ResultArray();
$ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
$this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
} else {
$this->CommentData = FALSE;
}
$this->View = 'all';
$this->Render();
}
作者:remobject
项目:Garde
/**
* Delete all of the Vanilla related information for a specific user.
* @param int $UserID The ID of the user to delete.
* @param array $Options An array of options:
* - DeleteMethod: One of delete, wipe, or NULL
* @since 2.1
*/
public function DeleteUserData($UserID, $Options = array(), &$Data = NULL)
{
$SQL = Gdn::SQL();
// Remove discussion watch records and drafts.
$SQL->Delete('UserDiscussion', array('UserID' => $UserID));
Gdn::UserModel()->GetDelete('Draft', array('InsertUserID' => $UserID), $Data);
// Comment deletion depends on method selected
$DeleteMethod = GetValue('DeleteMethod', $Options, 'delete');
if ($DeleteMethod == 'delete') {
// Clear out the last posts to the categories.
$SQL->Update('Category c')->Join('Discussion d', 'd.DiscussionID = c.LastDiscussionID')->Where('d.InsertUserID', $UserID)->Set('c.LastDiscussionID', NULL)->Set('c.LastCommentID', NULL)->Put();
$SQL->Update('Category c')->Join('Comment d', 'd.CommentID = c.LastCommentID')->Where('d.InsertUserID', $UserID)->Set('c.LastDiscussionID', NULL)->Set('c.LastCommentID', NULL)->Put();
// Grab all of the discussions that the user has engaged in.
$DiscussionIDs = $SQL->Select('DiscussionID')->From('Comment')->Where('InsertUserID', $UserID)->GroupBy('DiscussionID')->Get()->ResultArray();
$DiscussionIDs = ConsolidateArrayValuesByKey($DiscussionIDs, 'DiscussionID');
Gdn::UserModel()->GetDelete('Comment', array('InsertUserID' => $UserID), $Data);
// Update the comment counts.
$CommentCounts = $SQL->Select('DiscussionID')->Select('CommentID', 'count', 'CountComments')->Select('CommentID', 'max', 'LastCommentID')->WhereIn('DiscussionID', $DiscussionIDs)->GroupBy('DiscussionID')->Get('Comment')->ResultArray();
foreach ($CommentCounts as $Row) {
$SQL->Put('Discussion', array('CountComments' => $Row['CountComments'] + 1, 'LastCommentID' => $Row['LastCommentID']), array('DiscussionID' => $Row['DiscussionID']));
}
// Update the last user IDs.
$SQL->Update('Discussion d')->Join('Comment c', 'd.LastCommentID = c.CommentID', 'left')->Set('d.LastCommentUserID', 'c.InsertUserID', FALSE, FALSE)->Set('d.DateLastComment', 'c.DateInserted', FALSE, FALSE)->WhereIn('d.DiscussionID', $DiscussionIDs)->Put();
// Update the last posts.
$Discussions = $SQL->WhereIn('DiscussionID', $DiscussionIDs)->Where('LastCommentUserID', $UserID)->Get('Discussion');
// Delete the user's dicussions
Gdn::UserModel()->GetDelete('Discussion', array('InsertUserID' => $UserID), $Data);
// Update the appropriat recent posts in the categories.
$CategoryModel = new CategoryModel();
$Categories = $CategoryModel->GetWhere(array('LastDiscussionID' => NULL))->ResultArray();
foreach ($Categories as $Category) {
$CategoryModel->SetRecentPost($Category['CategoryID']);
}
} else {
if ($DeleteMethod == 'wipe') {
// Erase the user's dicussions
$SQL->Update('Discussion')->Set('Body', T('The user and all related content has been deleted.'))->Set('Format', 'Deleted')->Where('InsertUserID', $UserID)->Put();
// Erase the user's comments
$SQL->From('Comment')->Join('Discussion d', 'c.DiscussionID = d.DiscussionID')->Delete('Comment c', array('d.InsertUserID' => $UserID));
$SQL->Update('Comment')->Set('Body', T('The user and all related content has been deleted.'))->Set('Format', 'Deleted')->Where('InsertUserID', $UserID)->Put();
} else {
// Leave comments
}
}
// Remove the user's profile information related to this application
$SQL->Update('User')->Set(array('CountDiscussions' => 0, 'CountUnreadDiscussions' => 0, 'CountComments' => 0, 'CountDrafts' => 0, 'CountBookmarks' => 0))->Where('UserID', $UserID)->Put();
}
作者:edward-tsa
项目:vanilla4chin
/**
* Get all tutorials, or a specific one.
*/
function GetTutorials($TutorialCode = '')
{
// Define all Tutorials
$Tutorials = array(array('Code' => 'introduction', 'Name' => 'Introduction to Vanilla', 'Description' => 'This video gives you a brief overview of the Vanilla administrative dashboard and the forum itself.', 'VideoID' => '31043422'), array('Code' => 'using-the-forum', 'Name' => 'Using the Forum', 'Description' => 'Learn how to start, announce, close, edit and delete discussions and comments.', 'VideoID' => '31502992'), array('Code' => 'private-conversations', 'Name' => 'Private Conversations', 'Description' => 'Learn how to start new private conversations and add people to them.', 'VideoID' => '31498383'), array('Code' => 'user-profiles', 'Name' => 'User Profiles', 'Description' => 'Learn how to use and manage your user profile. ', 'VideoID' => '31499266'), array('Code' => 'appearance', 'Name' => 'Changing the appearance of your forum', 'Description' => 'This tutorial takes you through the "Appearance" section of the Vanilla Forums administrative dashboard.', 'VideoID' => '31089641'), array('Code' => 'roles-and-permissions', 'Name' => 'Managing Roles and Permissions in Vanilla', 'Description' => 'This tutorial walks you through how to create new roles and how to use permissions.', 'VideoID' => '31091056'), array('Code' => 'users', 'Name' => 'Finding & Managing Users', 'Description' => 'This tutorial shows you how to search for and manage users.', 'VideoID' => '31094514'), array('Code' => 'category-management-and-advanced-settings', 'Name' => 'Category Management & Advanced Settings', 'Description' => 'Learn how to add, edit, and manage categories. Also learn about advanced forum settings.', 'VideoID' => '31492046'), array('Code' => 'user-registration', 'Name' => 'User Registration', 'Description' => 'Learn to control how new users get into your community.', 'VideoID' => '31493119'));
// Default Thumbnails
$Thumbnail = Asset('applications/dashboard/design/images/help-tn-200.jpg');
$LargeThumbnail = Asset('applications/dashboard/design/images/help-tn-640.jpg');
for ($i = 0; $i < count($Tutorials); $i++) {
$Tutorials[$i]['Thumbnail'] = $Thumbnail;
$Tutorials[$i]['LargeThumbnail'] = $LargeThumbnail;
}
if ($TutorialCode != '') {
$Keys = ConsolidateArrayValuesByKey($Tutorials, 'Code');
$Index = array_search($TutorialCode, $Keys);
if ($Index === FALSE) {
return FALSE;
}
// Not found!
// Found it, so define it's thumbnail location
$Tutorial = GetValue($Index, $Tutorials);
$VideoID = GetValue('VideoID', $Tutorial);
try {
$Vimeo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $Tutorial['VideoID'] . ".php"));
$Tutorial['Thumbnail'] = GetValue('thumbnail_medium', GetValue('0', $Vimeo));
$Tutorial['LargeThumbnail'] = GetValue('thumbnail_large', GetValue('0', $Vimeo));
} catch (Exception $Ex) {
// Do nothing
}
return $Tutorial;
} else {
// Loop through each tutorial populating the thumbnail image location
try {
foreach ($Tutorials as $Key => $Tutorial) {
$Vimeo = unserialize(file_get_contents("http://vimeo.com/api/v2/video/" . $Tutorial['VideoID'] . ".php"));
$Tutorials[$Key]['Thumbnail'] = GetValue('thumbnail_medium', GetValue('0', $Vimeo));
$Tutorials[$Key]['LargeThumbnail'] = GetValue('thumbnail_large', GetValue('0', $Vimeo));
}
} catch (Exception $Ex) {
// Do nothing
}
return $Tutorials;
}
}
作者:unligh
项目:MassDeliver
protected function GetUserEmails($FormValues)
{
$SQL = Gdn::SQL();
$UserModel = Gdn::UserModel();
if (ArrayValue('SendMeOnly', $FormValues)) {
$Session = Gdn::Session();
$UserID = GetValueR('User.UserID', $Session);
$User = $UserModel->Get($UserID);
$Result[$User->Email] = $User->Name;
return $Result;
}
$Roles = ArrayValue('Roles', $FormValues);
if (is_array($Roles) && count($Roles) > 0) {
$DataSet = $SQL->Select('u.Name, u.Email')->From('UserRole r')->Join('User u', 'u.UserID = r.UserID')->WhereIn('r.RoleID', $Roles)->Get();
} else {
$DataSet = $SQL->Select('u.Name, u.Email')->From('User u')->Get();
}
$Result = ConsolidateArrayValuesByKey($DataSet->ResultArray(), 'Email', 'Name');
return $Result;
}
作者:jhamph
项目:Garde
public function Index()
{
if ($this->Head) {
$this->Head->AddScript('/applications/garden/js/activity.js');
$this->Head->Title(Translate('Recent Activity'));
}
$Session = Gdn::Session();
$this->ActivityData = $this->ActivityModel->Get();
if ($this->ActivityData->NumRows() > 0) {
$ActivityData = $this->ActivityData->ResultArray();
$ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
$this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
} else {
$this->CommentData = FALSE;
}
$GuestModule = new GuestModule($this);
$GuestModule->MessageCode = "Just checking up on recent activity? When you're ready to get involved, click one of these buttons!";
$this->AddModule($GuestModule);
$this->View = 'all';
$this->Render();
}
作者:tautomer
项目:knoopvszombie
public function Index($RoleID = '')
{
$this->Permission('Garden.Activity.View');
// Limit to specific RoleIDs?
if ($RoleID != '') {
$RoleID = explode(',', $RoleID);
}
$this->AddJsFile('activity.js');
$this->Title(T('Recent Activity'));
$Session = Gdn::Session();
$Comment = $this->Form->GetFormValue('Comment');
$this->CommentData = FALSE;
if ($Session->UserID > 0 && $this->Form->AuthenticatedPostBack() && !StringIsNullOrEmpty($Comment)) {
$Comment = substr($Comment, 0, 1000);
// Limit to 1000 characters...
// Update About if necessary
$ActivityType = 'WallComment';
$NewActivityID = $this->ActivityModel->Add($Session->UserID, $ActivityType, $Comment);
if ($this->_DeliveryType === DELIVERY_TYPE_ALL) {
Redirect('activity');
} else {
// Load just the single new comment
$this->HideActivity = TRUE;
$this->ActivityData = $this->ActivityModel->GetWhere('ActivityID', $NewActivityID);
$this->View = 'activities';
}
} else {
$this->ActivityData = is_array($RoleID) ? $this->ActivityModel->GetForRole($RoleID) : $this->ActivityModel->Get();
if ($this->ActivityData->NumRows() > 0) {
$ActivityData = $this->ActivityData->ResultArray();
$ActivityIDs = ConsolidateArrayValuesByKey($ActivityData, 'ActivityID');
$this->CommentData = $this->ActivityModel->GetComments($ActivityIDs);
}
$this->View = 'all';
}
$this->Render();
}
作者:bishop
项目:vanill
/**
* Returns the xhtml for a list of checkboxes; sorted into groups related to
* the TextField value of the dataset.
*
* @param string $FieldName The name of the field that is being displayed/posted with this input. It
* should related directly to a field name in a user junction table.
* ie. LUM_UserRole.RoleID
*
* @param mixed $DataSet The data to fill the options in the select list. Either an associative
* array or a database dataset. ie. RoleID, Name from LUM_Role.
*
* @param mixed $ValueDataSet The data that should be checked in $DataSet. Either an associative array
* or a database dataset. ie. RoleID from LUM_UserRole for a single user.
*
* @param array $Attributes An associative array of attributes for the select. Here is a list of
* "special" attributes and their default values:
*
* Attribute Options Default
* ------------------------------------------------------------------------
* ValueField The name of the field in 'value'
* $DataSet that contains the
* option values.
* TextField The name of the field in 'text'
* $DataSet that contains the
* option text.
*
* @return string
*/
public function CheckBoxGrid($FieldName, $DataSet, $ValueDataSet, $Attributes)
{
// Never display individual inline errors for these CheckBoxes
$Attributes['InlineErrors'] = FALSE;
$Return = '';
$CheckedValues = $ValueDataSet;
if (is_object($ValueDataSet)) {
$CheckedValues = ConsolidateArrayValuesByKey($ValueDataSet->ResultArray(), $FieldName);
}
$i = 1;
if (is_object($DataSet)) {
$ValueField = ArrayValueI('ValueField', $Attributes, 'value');
$TextField = ArrayValueI('TextField', $Attributes, 'text');
$LastGroup = '';
$Group = array();
$Rows = array();
$Cols = array();
$CheckBox = '';
foreach ($DataSet->Result() as $Data) {
// Define the checkbox
$Instance = $Attributes;
$Instance = RemoveKeyFromArray($Instance, array('TextField', 'ValueField'));
$Instance['value'] = $Data->{$ValueField};
$Instance['id'] = $FieldName . $i;
if (is_array($CheckedValues) && in_array($Data->{$ValueField}, $CheckedValues)) {
$Instance['checked'] = 'checked';
}
$CheckBox = $this->CheckBox($FieldName . '[]', '', $Instance);
// Organize the checkbox into an array for this group
$CurrentTextField = $Data->{$TextField};
$aCurrentTextField = explode('.', $CurrentTextField);
$aCurrentTextFieldCount = count($aCurrentTextField);
$GroupName = array_shift($aCurrentTextField);
$ColName = array_pop($aCurrentTextField);
if ($aCurrentTextFieldCount >= 3) {
$RowName = implode('.', $aCurrentTextField);
if ($GroupName != $LastGroup && $LastGroup != '') {
// Render the last group
$Return .= $this->GetCheckBoxGridGroup($LastGroup, $Group, $Rows, $Cols);
// Clean out the $Group array & Rowcount
$Group = array();
$Rows = array();
$Cols = array();
}
if (array_key_exists($ColName, $Group) === FALSE || is_array($Group[$ColName]) === FALSE) {
$Group[$ColName] = array();
if (!in_array($ColName, $Cols)) {
$Cols[] = $ColName;
}
}
if (!in_array($RowName, $Rows)) {
$Rows[] = $RowName;
}
$Group[$ColName][$RowName] = $CheckBox;
$LastGroup = $GroupName;
}
++$i;
}
}
/*elseif (is_array($DataSet)) {
foreach ($DataSet as $Text => $ID) {
$Instance = $Attributes;
$Instance = RemoveKeyFromArray($Instance, array('TextField', 'ValueField'));
$Instance['id'] = $FieldName.$i;
if (is_numeric($Text))
$Text = $ID;
$Instance['value'] = $ID;
if (in_array($ID, $CheckedValues))
$Instance['checked'] = 'checked';
$Return .= $this->CheckBox($FieldName.'[]', $Text, $Instance)."\n";
//.........这里部分代码省略.........
作者:nerdgir
项目:Forums-ILoveBadT
/**
* Retrieve the user to be manipulated. If no params are passed, this will
* retrieve the current user from the session.
*/
public function GetUserInfo($UserReference = '', $Username = '', $UserID = '') {
if ($this->_UserInfoRetrieved)
return;
if (!C('Garden.Profile.Public') && !Gdn::Session()->IsValid())
Redirect('dashboard/home/permission');
// If a UserID was provided as a querystring parameter, use it over anything else:
if ($UserID) {
$UserReference = $UserID;
$Username = 'Unknown'; // Fill this with a value so the $UserReference is assumed to be an integer/userid.
}
$this->Roles = array();
if ($UserReference == '') {
$this->User = $this->UserModel->Get(Gdn::Session()->UserID);
} else if (is_numeric($UserReference) && $Username != '') {
$this->User = $this->UserModel->Get($UserReference);
} else {
$this->User = $this->UserModel->GetByUsername($UserReference);
}
if ($this->User === FALSE) {
throw NotFoundException();
} else if ($this->User->Deleted == 1) {
Redirect('dashboard/home/deleted');
} else {
$this->RoleData = $this->UserModel->GetRoles($this->User->UserID);
if ($this->RoleData !== FALSE && $this->RoleData->NumRows(DATASET_TYPE_ARRAY) > 0)
$this->Roles = ConsolidateArrayValuesByKey($this->RoleData->Result(), 'Name');
$this->SetData('Profile', $this->User);
$this->SetData('UserRoles', $this->Roles);
// If the photo contains an http://, it is just an icon (probably from facebook or some external service), don't show it here because the Photo property is used to define logic around allowing thumbnail edits, etc.
if ($this->User->Photo != '' && in_array(strtolower(substr($this->User->Photo, 0, 7)), array('http://', 'https:/')))
$this->User->Photo = '';
}
// Make sure the userphoto module gets added to the page
$UserPhotoModule = new UserPhotoModule($this);
$UserPhotoModule->User = $this->User;
$this->AddModule($UserPhotoModule);
$this->AddSideMenu();
$this->_UserInfoRetrieved = TRUE;
return TRUE;
}