using System; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.PortalControls; using CMS.SiteProvider; public partial class CMSWebParts_Community_Friends_FriendsDataSource : CMSAbstractWebPart { #region "Variables" private UserInfo mCurrentUser = null; #endregion #region "Stop processing" /// /// Returns true if the control processing should be stopped. /// public override bool StopProcessing { get { return base.StopProcessing; } set { base.StopProcessing = value; srcFriends.StopProcessing = value; } } #endregion #region "Properties" /// /// Gets or sets WHERE condition. /// public string WhereCondition { get { return ValidationHelper.GetString(GetValue("WhereCondition"), ""); } set { SetValue("WhereCondition", value); srcFriends.WhereCondition = value; } } /// /// Gets or sets UserId. /// [Obsolete("Use UserName instead")] public int UserID { get { return CurrentUser.UserID; } set { SetValue("UserID", value); srcFriends.UserID = value; } } /// /// User name. /// public string UserName { get { return CurrentUser.UserName; } set { SetValue("UserName", value); } } /// /// Gets or sets current user object. /// public new UserInfo CurrentUser { get { if (mCurrentUser == null) { mCurrentUser = UserInfoProvider.GetUserInfo(ValidationHelper.GetString(GetValue("UserName"), string.Empty)); } if (mCurrentUser == null) { // Backward compatibility int userId = ValidationHelper.GetInteger(GetValue("UserID"), srcFriends.UserID); if (userId > 0) { mCurrentUser = UserInfoProvider.GetUserInfo(userId); } else { mCurrentUser = SiteContext.CurrentUser; } } if (mCurrentUser == null) { mCurrentUser = CMSContext.CurrentUser; } return mCurrentUser; } } /// /// Gets or sets ORDER BY condition. /// public string OrderBy { get { return ValidationHelper.GetString(GetValue("OrderBy"), string.Empty); } set { SetValue("OrderBy", value); srcFriends.OrderBy = value; } } /// /// Gets or sets status of friends to be selected. /// public FriendshipStatusEnum FriendStatus { get { return (FriendshipStatusEnum)ValidationHelper.GetInteger(GetValue("FriendStatus"), 0); } set { SetValue("FriendStatus", (int)value); srcFriends.FriendStatus = value; } } /// /// Gets or sets the source filter name. /// public string FilterName { get { return ValidationHelper.GetString(GetValue("FilterName"), ""); } set { SetValue("FilterName", value); srcFriends.SourceFilterName = value; } } /// /// Gets or sets the cache item name. /// public override string CacheItemName { get { return base.CacheItemName; } set { base.CacheItemName = value; srcFriends.CacheItemName = value; } } /// /// Cache dependencies, each cache dependency on a new line. /// public override string CacheDependencies { get { return ValidationHelper.GetString(base.CacheDependencies, srcFriends.CacheDependencies); } set { base.CacheDependencies = value; srcFriends.CacheDependencies = value; } } /// /// Gets or sets the cache minutes. /// public override int CacheMinutes { get { return base.CacheMinutes; } set { base.CacheMinutes = value; srcFriends.CacheMinutes = value; } } /// /// Gest or sets selected columns. /// public string Columns { get { return ValidationHelper.GetString(GetValue("Columns"), string.Empty); } set { SetValue("Columns", value); srcFriends.SelectedColumns = value; } } #endregion #region "Methods" /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing || (CurrentUser == null)) { // Do nothing } else { srcFriends.WhereCondition = WhereCondition; srcFriends.OrderBy = OrderBy; srcFriends.UserID = CurrentUser.UserID; srcFriends.FilterName = ID; srcFriends.SourceFilterName = FilterName; srcFriends.CacheItemName = CacheItemName; srcFriends.CacheDependencies = CacheDependencies; srcFriends.CacheMinutes = CacheMinutes; srcFriends.FriendStatus = FriendStatus; srcFriends.SelectedColumns = Columns; } } /// /// Clears cache. /// public override void ClearCache() { srcFriends.ClearCache(); } #endregion }