public PrimitiveApplicationInfo(Core core, Primitive owner, long applicationId) : base(core) { this.owner = owner; ItemLoad += new ItemLoadHandler(PrimitiveApplicationInfo_ItemLoad); SelectQuery query = new SelectQuery(PrimitiveApplicationInfo.GetTable(typeof(PrimitiveApplicationInfo))); query.AddFields(PrimitiveApplicationInfo.GetFieldsPrefixed(core, typeof(PrimitiveApplicationInfo))); query.AddCondition("application_id", applicationId); query.AddCondition("item_id", owner.Id); query.AddCondition("item_type_id", owner.TypeId); DataTable appDataTable = db.Query(query); if (appDataTable.Rows.Count == 1) { DataRow appRow = appDataTable.Rows[0]; try { loadItemInfo(appRow); } catch (InvalidItemException) { throw new InvalidPrimitiveAppInfoException(); } } else { throw new InvalidPrimitiveAppInfoException(); } }
public EventInvite(Core core, long eventId, Primitive invitee) : base(core) { this.ItemLoad += new ItemLoadHandler(EventInvite_ItemLoad); SelectQuery query = EventInvite.GetSelectQueryStub(core, typeof(EventInvite)); query.AddCondition("event_id", eventId); query.AddCondition("item_id", invitee.Id); query.AddCondition("item_type_id", invitee.TypeId); System.Data.Common.DbDataReader inviteReader = db.ReaderQuery(query); try { if (inviteReader.HasRows) { inviteReader.Read(); loadItemInfo(inviteReader); } inviteReader.Close(); inviteReader.Dispose(); } catch (InvalidItemException) { inviteReader.Close(); inviteReader.Dispose(); throw new InvalidEventInviteException(); } }
public Calendar(Core core, Primitive owner) : base(core) { if (core == null) { throw new NullCoreException(); } if (owner == null) { throw new InvalidUserException(); } this.owner = owner; ItemLoad += new ItemLoadHandler(Calendar_ItemLoad); try { LoadItem("calendar_item_id", "calendar_item_type_id", owner); } catch (InvalidItemException) { throw new InvalidCalendarException(); } }
public UploadForm(Core core, PPage page) { this.core = core; this.page = page; this.db = core.Db; this.template = core.Template; this.Owner = page.Owner; this.LoggedInMember = core.Session.LoggedInMember; }
/// <summary> /// Initializes a new instance of the ControlPanelSubModule class. /// </summary> /// <param name="core">The Core token.</param> public ControlPanelSubModule(Core core, Primitive owner) { this.core = core; this.db = core.Db; this.session = core.Session; this.tz = core.Tz; this.LoggedInMember = session.LoggedInMember; this.Owner = owner; core.Prose.AddApplication(Assembly.GetAssembly(this.GetType()).GetName().Name); }
internal Access(Core core, ItemKey key, Primitive leafOwner) { if (core == null) { throw new NullCoreException(); } this.core = core; this.item = null; this.owner = leafOwner; this.itemKey = key; this.viewer = core.Session.LoggedInMember; }
public Access(Core core, IPermissibleItem item) { if (core == null) { throw new NullCoreException(); } this.core = core; this.item = item; this.owner = item.Owner; this.itemKey = item.ItemKey; this.viewer = core.Session.LoggedInMember; }
public Project(Core core, Primitive owner, string key) : base(core) { ItemLoad += new ItemLoadHandler(Project_ItemLoad); try { LoadItem("project_item_id", "project_item_type_id", owner, new FieldValuePair("project_key", key)); } catch (InvalidItemException) { throw new InvalidProjectException(); } }
public DnsRecord(Core core, Primitive owner) : base(core) { ItemLoad += new ItemLoadHandler(DnsRecord_ItemLoad); try { LoadItem("dns_owner_id", "dns_owner_type", owner); } catch (InvalidItemException) { throw new InvalidDnsRecordException(); } }
public ForumMember(Core core, Primitive owner, User user) : base(core) { ItemLoad += new ItemLoadHandler(ForumMember_ItemLoad); // load the info into a the new object being created this.userInfo = user.UserInfo; this.userProfile = user.Profile; this.userStyle = user.Style; this.userId = user.UserId; this.userName = user.UserName; this.domain = user.UserDomain; this.emailAddresses = user.EmailAddresses; SelectQuery sQuery = ForumMember.GetSelectQueryStub(core, typeof(ForumMember)); sQuery.AddCondition("user_id", user.Id); sQuery.AddCondition("item_id", owner.Id); sQuery.AddCondition("item_type_id", owner.TypeId); try { System.Data.Common.DbDataReader memberReader = core.Db.ReaderQuery(sQuery); if (memberReader.HasRows) { memberReader.Read(); loadItemInfo(memberReader); memberReader.Close(); memberReader.Dispose(); } else { memberReader.Close(); memberReader.Dispose(); throw new InvalidForumMemberException(); } } catch (InvalidItemException) { throw new InvalidForumMemberException(); } }
public BlogEntry(Core core, Blog blog, Primitive owner, System.Data.Common.DbDataReader postEntryReader) : base(core) { ItemLoad += new ItemLoadHandler(BlogEntry_ItemLoad); this.blog = blog; this.owner = owner; loadItemInfo(postEntryReader); }
public List<Event> GetEvents(Core core, Primitive owner, long startTimeRaw, long endTimeRaw) { List<Event> events = new List<Event>(); SelectQuery sQuery = Item.GetSelectQueryStub(core, typeof(Event)); sQuery.AddCondition("event_item_id", owner.Id); sQuery.AddCondition("event_item_type_id", owner.TypeId); QueryCondition sqc2 = sQuery.AddCondition("event_time_start_ut", ConditionEquality.GreaterThanEqual, startTimeRaw); sqc2.AddCondition("event_time_start_ut", ConditionEquality.LessThanEqual, endTimeRaw); QueryCondition sqc3 = sqc2.AddCondition(ConditionRelations.Or, "event_time_end_ut", ConditionEquality.GreaterThanEqual, startTimeRaw); sqc3.AddCondition("event_time_end_ut", ConditionEquality.LessThanEqual, endTimeRaw); QueryCondition sqc4 = sqc3.AddCondition(ConditionRelations.Or, "event_time_start_ut", ConditionEquality.LessThan, startTimeRaw); sqc4.AddCondition("event_time_end_ut", ConditionEquality.GreaterThan, endTimeRaw); sQuery.AddSort(SortOrder.Ascending, "event_time_start_ut"); { System.Data.Common.DbDataReader eventsReader = db.ReaderQuery(sQuery); while (eventsReader.Read()) { events.Add(new Event(core, eventsReader)); } eventsReader.Close(); eventsReader.Dispose(); } if (owner.TypeId == ItemKey.GetTypeId(core, typeof(User))) { // now select events invited to SelectQuery query = Event.GetSelectQueryStub(core, typeof(Event)); query.AddFields("event_invites.item_id", "event_invites.item_type_id", "event_invites.inviter_id", "event_invites.event_id"); query.AddJoin(JoinTypes.Left, new DataField(typeof(Event), "event_id"), new DataField("event_invites", "event_id")); query.AddCondition("item_id", core.LoggedInMemberId); query.AddCondition("item_type_id", ItemKey.GetTypeId(core, typeof(User))); QueryCondition qc2 = query.AddCondition("event_time_start_ut", ConditionEquality.GreaterThanEqual, startTimeRaw); qc2.AddCondition("event_time_start_ut", ConditionEquality.LessThanEqual, endTimeRaw); QueryCondition qc3 = qc2.AddCondition(ConditionRelations.Or, "event_time_end_ut", ConditionEquality.GreaterThanEqual, startTimeRaw); qc3.AddCondition("event_time_end_ut", ConditionEquality.LessThanEqual, endTimeRaw); QueryCondition qc4 = qc3.AddCondition(ConditionRelations.Or, "event_time_start_ut", ConditionEquality.LessThan, startTimeRaw); qc4.AddCondition("event_time_end_ut", ConditionEquality.GreaterThan, endTimeRaw); System.Data.Common.DbDataReader eventsReader = db.ReaderQuery(sQuery); while (eventsReader.Read()) { events.Add(new Event(core, eventsReader)); } eventsReader.Close(); eventsReader.Dispose(); User user = (User)owner; List<UserRelation> friends = user.GetFriendsBirthdays(startTimeRaw, endTimeRaw); foreach (UserRelation friend in friends) { try { events.Add(new BirthdayEvent(core, user, friend, core.Tz.DateTimeFromMysql(startTimeRaw).Year)); } catch (InvalidEventException) { // Not a reciprocol friend, ignore } } } events.Sort(); return events; }
public static void Show(Core core, TPage page, Primitive owner, int year, int month, int day) { core.Template.SetTemplate("Calendar", "viewcalendarday"); // 15 year window if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5) { core.Functions.Generate404(); } if (month < 1 || month > 12) { core.Functions.Generate404(); } if (day < 1 || day > DateTime.DaysInMonth(year, month)) { core.Functions.Generate404(); } /* pages */ core.Display.ParsePageList(owner, true); core.Template.Parse("PAGE_TITLE", day.ToString() + " " + core.Functions.IntToMonth(month) + " " + year.ToString()); core.Template.Parse("CURRENT_DAY", day.ToString()); core.Template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month)); core.Template.Parse("CURRENT_YEAR", year.ToString()); long startTime = core.Tz.GetUnixTimeStamp(new DateTime(year, month, day, 0, 0, 0)); long endTime = startTime + 60 * 60 * 24; Calendar cal = null; try { cal = new Calendar(core, owner); } catch (InvalidCalendarException) { cal = Calendar.Create(core, owner); } if (cal.Access.Can("CREATE_EVENTS")) { core.Template.Parse("U_NEW_EVENT", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-event", true, string.Format("year={0}", year), string.Format("month={0}", month), string.Format("day={0}", day))); } List<Event> events = cal.GetEvents(core, owner, startTime, endTime); bool hasAllDaysEvents = false; foreach (Event calendarEvent in events) { if (calendarEvent.AllDay) { hasAllDaysEvents = true; VariableCollection eventVariableCollection = core.Template.CreateChild("event"); eventVariableCollection.Parse("TITLE", calendarEvent.Subject); eventVariableCollection.Parse("URI", calendarEvent.Uri); } } if (hasAllDaysEvents) { core.Template.Parse("ALL_DAY_EVENTS", "TRUE"); } VariableCollection[] hours = new VariableCollection[24]; for (int hour = 0; hour < 24; hour++) { VariableCollection timeslotVariableCollection = core.Template.CreateChild("timeslot"); DateTime hourTime = new DateTime(year, month, day, hour, 0, 0); timeslotVariableCollection.Parse("TIME", hourTime.ToString("h tt").ToLower()); hours[hour] = timeslotVariableCollection; } showHourEvents(core, owner, year, month, day, hours, events); List<string[]> calendarPath = new List<string[]>(); calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") }); calendarPath.Add(new string[] { year.ToString(), year.ToString() }); calendarPath.Add(new string[] { month.ToString(), core.Functions.IntToMonth(month) }); calendarPath.Add(new string[] { day.ToString(), day.ToString() }); owner.ParseBreadCrumbs(calendarPath); }
public static void Show(Core core, TPage page, Primitive owner, int year, int month) { core.Template.SetTemplate("Calendar", "viewcalendarmonth"); if (month < 1 || month > 12) { core.Functions.Generate404(); } // 15 year window if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5) { core.Functions.Generate404(); } /* pages */ core.Display.ParsePageList(owner, true); core.Template.Parse("PAGE_TITLE", core.Functions.IntToMonth(month) + " " + year.ToString()); core.Template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month)); core.Template.Parse("CURRENT_YEAR", year.ToString()); core.Template.Parse("U_PREVIOUS_MONTH", Calendar.BuildMonthUri(core, owner, YearOfPreviousMonth(year, month), PreviousMonth(month))); core.Template.Parse("U_NEXT_MONTH", Calendar.BuildMonthUri(core, owner, YearOfNextMonth(year, month), NextMonth(month))); Calendar cal = null; try { cal = new Calendar(core, owner); } catch (InvalidCalendarException) { cal = Calendar.Create(core, owner); } if (cal.Access.Can("CREATE_EVENTS")) { core.Template.Parse("U_NEW_EVENT", core.Hyperlink.BuildAccountSubModuleUri(owner, "calendar", "new-event", true, string.Format("year={0}", year), string.Format("month={0}", month), string.Format("day={0}", ((month == core.Tz.Now.Month) ? core.Tz.Now.Day : 1)))); } int days = DateTime.DaysInMonth(year, month); DayOfWeek firstDay = new DateTime(year, month, 1).DayOfWeek; int offset = Calendar.GetFirstDayOfMonthOffset(firstDay); int weeks = (int)Math.Ceiling((days + offset) / 7.0); int daysPrev = DateTime.DaysInMonth(YearOfPreviousMonth(year, month), PreviousMonth(month)); long startTime = 0; if (offset > 0) { // the whole month including entry days startTime = core.Tz.GetUnixTimeStamp(new DateTime(YearOfPreviousMonth(year, month), PreviousMonth(month), daysPrev - offset + 1, 0, 0, 0)); } else { // the whole month startTime = core.Tz.GetUnixTimeStamp(new DateTime(year, month, 1, 0, 0, 0)); } // the whole month including exit days long endTime = startTime + 60 * 60 * 24 * weeks * 7; List<Event> events = cal.GetEvents(core, owner, startTime, endTime); /*if (startTime == -8885289600 || startTime == 11404281600 || endTime == -8885289600 || endTime == 11404281600) { Functions.Generate404(); return; }*/ for (int week = 0; week < weeks; week++) { VariableCollection weekVariableCollection = core.Template.CreateChild("week"); weekVariableCollection.Parse("WEEK", (week + 1).ToString()); /* lead in week */ if (week + 1 == 1) { int daysPrev2 = DateTime.DaysInMonth(YearOfPreviousMonth(year, month), PreviousMonth(month)); /* days in month prior */ for (int i = offset - 1; i >= 0; i--) { int day = daysPrev2 - i; Calendar.showDayEvents(core, owner, YearOfPreviousMonth(year, month), PreviousMonth(month), day, weekVariableCollection, events); } /* first days in month */ for (int i = offset; i < 7; i++) { int day = i - offset + 1; Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events); } } /* lead out week */ else if (week + 1 == weeks) { /* last days in month */ for (int i = week * 7 - offset; i < days; i++) { int day = i + 1; Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events); } /* days in month upcoming */ for (int i = 0; i < weeks * 7 - days - offset; i++) { int day = i + 1; Calendar.showDayEvents(core, owner, YearOfNextMonth(year, month), NextMonth(month), day, weekVariableCollection, events); } } else { for (int i = 0; i < 7; i++) { int day = week * 7 + i + 1 - offset; Calendar.showDayEvents(core, owner, year, month, day, weekVariableCollection, events); } } } List<string[]> calendarPath = new List<string[]>(); calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") }); calendarPath.Add(new string[] { year.ToString(), year.ToString() }); calendarPath.Add(new string[] { month.ToString(), core.Functions.IntToMonth(month) }); owner.ParseBreadCrumbs(calendarPath); }
public static void Show(Core core, TPage page, Primitive owner, int year) { core.Template.SetTemplate("Calendar", "viewcalendaryear"); // 15 year window if (year < DateTime.Now.Year - 10 || year > DateTime.Now.Year + 5) { core.Functions.Generate404(); } /* pages */ core.Display.ParsePageList(owner, true); core.Template.Parse("PAGE_TITLE", year.ToString()); core.Template.Parse("CURRENT_YEAR", year.ToString()); if (year - 1 >= DateTime.Now.Year - 10) { core.Template.Parse("U_PREVIOUS_YEAR", Calendar.BuildYearUri(core, owner, year - 1)); } if (year + 1 <= DateTime.Now.Year + 5) { core.Template.Parse("U_NEXT_YEAR", Calendar.BuildYearUri(core, owner, year + 1)); } for (int i = 1; i <= 12; i++) { DisplayMiniCalendar(core, core.Template.CreateChild("month"), owner, year, i); } List<string[]> calendarPath = new List<string[]>(); calendarPath.Add(new string[] { "calendar", core.Prose.GetString("CALENDAR") }); calendarPath.Add(new string[] { year.ToString(), year.ToString() }); owner.ParseBreadCrumbs(calendarPath); }
public static void Show(Core core, TPage page, Primitive owner) { Show(core, page, owner, core.Tz.Now.Year, core.Tz.Now.Month); }
private static void showHourEvents(Core core, Primitive owner, int year, int month, int day, VariableCollection[] timeslotVariableCollections, List<Event> events) { bool hasEvents = false; long startOfDay = core.Tz.GetUnixTimeStamp(new DateTime(year, month, day, 0, 0, 0)); long endOfDay = startOfDay + 60 * 60 * 24; long[] heights = new long[events.Count]; long[] tops = new long[events.Count]; double[] widths = new double[events.Count]; double[] lefts = new double[events.Count]; int[] eventCount = new int[96]; int[] eventNumber = new int[96]; int hourHeight = 32; List<Event> expired = new List<Event>(); int i = 0; foreach (Event calendarEvent in events) { if (calendarEvent.AllDay) { continue; } long startTime = calendarEvent.StartTimeRaw; long endTime = calendarEvent.EndTimeRaw; if (endTime > endOfDay) { endTime = endOfDay; } if (startTime < startOfDay) { startTime = startOfDay; } DateTime startDateTime = core.Tz.DateTimeFromMysql(startTime); DateTime endDateTime = core.Tz.DateTimeFromMysql(endTime - 1); long startMinute = startDateTime.Minute; long startHour = startDateTime.Hour; long endMinute = endDateTime.Minute; long endHour = endDateTime.Hour; int startFifteen = (int)Math.Floor(startHour * 4.0 + startMinute / 15.0); int endFifteen = (int)Math.Floor(endHour * 4.0 + endMinute / 15.0); for (int j = startFifteen; j <= endFifteen; j++) { eventCount[j]++; } heights[i] = (endTime - startTime) * hourHeight / 60 / 60; tops[i] = startMinute * 36 / 60; widths[i] = 100.0; lefts[i] = 100 - 100.0 / Math.Max(1, eventCount[startFifteen]); i++; } i = 0; foreach (Event calendarEvent in events) { if (calendarEvent.AllDay) { continue; } long startTime = calendarEvent.StartTimeRaw; long endTime = calendarEvent.EndTimeRaw; if (endTime > endOfDay) { endTime = endOfDay; } if (startTime < startOfDay) { startTime = startOfDay; } DateTime startDateTime = core.Tz.DateTimeFromMysql(startTime); DateTime endDateTime = core.Tz.DateTimeFromMysql(endTime - 1); long startMinute = startDateTime.Minute; long startHour = startDateTime.Hour; long endMinute = endDateTime.Minute; long endHour = endDateTime.Hour; int startFifteen = (int)Math.Floor(startHour * 4.0 + startMinute / 15.0); int endFifteen = (int)Math.Floor(endHour * 4.0 + endMinute / 15.0); int maxEventsOnFifteen = 0; for (int j = startFifteen; j <= endFifteen; j++) { eventNumber[j]++; if (eventCount[j] > maxEventsOnFifteen) { maxEventsOnFifteen = eventCount[j]; } } lefts[i] = 100 - 100.0 * eventNumber[startFifteen] / Math.Max(1, maxEventsOnFifteen); widths[i] /= Math.Max(1, maxEventsOnFifteen); VariableCollection eventVariableCollection = timeslotVariableCollections[startHour].CreateChild("event"); eventVariableCollection.Parse("TITLE", calendarEvent.Subject); eventVariableCollection.Parse("URI", calendarEvent.Uri); eventVariableCollection.Parse("LEFT", lefts[i].ToString()); eventVariableCollection.Parse("WIDTH", widths[i].ToString()); eventVariableCollection.Parse("TOP", tops[i].ToString()); eventVariableCollection.Parse("HEIGHT", heights[i].ToString()); timeslotVariableCollections[startHour].Parse("EVENTS", "TRUE"); expired.Add(calendarEvent); i++; } foreach (Event calendarEvent in expired) { events.Remove(calendarEvent); } }
private static void DisplayMiniCalendar(Core core, Template template, VariableCollection vc1, Primitive owner, int year, int month) { int days = DateTime.DaysInMonth(year, month); DayOfWeek firstDay = new DateTime(year, month, 1).DayOfWeek; int offset = Calendar.GetFirstDayOfMonthOffset(firstDay); int weeks = (int)Math.Ceiling((days + offset) / 7.0); if (template != null) { template.Parse("CURRENT_MONTH", core.Functions.IntToMonth(month)); template.Parse("CURRENT_YEAR", year.ToString()); } else { vc1.Parse("MONTH", core.Functions.IntToMonth(month)); vc1.Parse("U_MONTH", BuildMonthUri(core, owner, year, month)); } for (int week = 0; week < weeks; week++) { VariableCollection weekVariableCollection; if (template != null) { weekVariableCollection = template.CreateChild("week"); } else { weekVariableCollection = vc1.CreateChild("week"); } weekVariableCollection.Parse("WEEK", (week + 1).ToString()); if (week + 1 == 1) { int daysPrev = DateTime.DaysInMonth(year - (month - 1) / 12, (month - 1) % 12 + 1); for (int i = offset - 1; i >= 0; i--) { int day = daysPrev - i; VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day"); dayVariableCollection.Parse("DATE", day.ToString()); dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year - (month - 2) / 12, (month - 2) % 12 + 1, day)); } for (int i = offset; i < 7; i++) { int day = i - offset + 1; VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day"); dayVariableCollection.Parse("DATE", day.ToString()); dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year, month, day)); } } else if (week + 1 == weeks) { for (int i = week * 7 - offset; i < days; i++) { int day = i + 1; VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day"); dayVariableCollection.Parse("DATE", day.ToString()); dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year, month, day)); } for (int i = 0; i < weeks * 7 - days - offset; i++) { int day = i + 1; VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day"); dayVariableCollection.Parse("DATE", day.ToString()); dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year + (month) / 12, (month) % 12 + 1, day)); } } else { for (int i = 0; i < 7; i++) { int day = week * 7 + i + 1 - offset; VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day"); dayVariableCollection.Parse("DATE", day.ToString()); dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year, month, day)); } } } }
internal static string BuildDateUri(Core core, Primitive owner, int year, int month, int day) { return core.Hyperlink.AppendSid(string.Format("{0}calendar/{1}/{2}/{3}", owner.UriStub, year, month, day)); }
public List<Task> GetTasks(Core core, Primitive owner, long startTimeRaw, long endTimeRaw) { return GetTasks(core, owner, startTimeRaw, endTimeRaw, false); }
/// <summary> /// Initializes a new instance of the AccountBlogDrafts class. /// </summary> /// <param name="core">The Core token.</param> public AccountBlogDrafts(Core core, Primitive owner) : base(core, owner) { this.Load += new EventHandler(AccountBlogDrafts_Load); this.Show += new EventHandler(AccountBlogDrafts_Show); }
public static List<PrimitivePermissionGroup> Network_GetPrimitiveGroups(Core core, Primitive owner) { List<PrimitivePermissionGroup> ppgs = new List<PrimitivePermissionGroup>(); if (owner is User) { List<Network> networks = Network.GetUserNetworks(core, (User)owner); foreach (Network network in networks) { ppgs.Add(new PrimitivePermissionGroup(network.TypeId, network.Id, network.DisplayName, string.Empty)); } } return ppgs; }
public List<Task> GetTasks(Core core, Primitive owner, long startTimeRaw, long endTimeRaw, bool overdueTasks) { List<Task> tasks = new List<Task>(); SelectQuery query = Item.GetSelectQueryStub(core, typeof(Task)); query.AddCondition("task_item_id", owner.Id); query.AddCondition("task_item_type_id", owner.TypeId); QueryCondition qc1 = query.AddCondition("task_due_date_ut", ConditionEquality.GreaterThanEqual, startTimeRaw); qc1.AddCondition("task_due_date_ut", ConditionEquality.LessThanEqual, endTimeRaw); query.AddSort(SortOrder.Ascending, "task_due_date_ut"); if (overdueTasks) { QueryCondition qc2 = qc1.AddCondition(ConditionRelations.Or, "task_due_date_ut", ConditionEquality.LessThan, UnixTime.UnixTimeStamp()); qc2.AddCondition("task_percent_complete", ConditionEquality.LessThan, 100); System.Data.Common.DbDataReader tasksReader = db.ReaderQuery(query); while (tasksReader.Read()) { tasks.Add(new Task(core, owner, tasksReader)); } tasksReader.Close(); tasksReader.Dispose(); } else { DataTable tasksTable = db.Query(query); System.Data.Common.DbDataReader tasksReader = db.ReaderQuery(query); while (tasksReader.Read()) { tasks.Add(new Task(core, owner, tasksReader)); } tasksReader.Close(); tasksReader.Dispose(); } return tasks; }
/// <summary> /// Initialses a new instance of the BlogEntry class. /// </summary> /// <param name="core">Core Token</param> /// <param name="owner">Owner whose blog post has been retrieved</param> /// <param name="postEntryRow">Raw data row of blog entry</param> public BlogEntry(Core core, Primitive owner, DataRow postEntryRow) : base(core) { ItemLoad += new ItemLoadHandler(BlogEntry_ItemLoad); this.owner = owner; loadItemInfo(postEntryRow); }
internal static string BuildYearUri(Core core, Primitive owner, int year) { return core.Hyperlink.AppendSid(string.Format("{0}calendar/{1}", owner.UriStub, year)); }
/// <summary> /// Creates a new blog for the logged in user. /// </summary> /// <param name="core"></param> /// <returns></returns> public static Calendar Create(Core core, Primitive owner) { if (core == null) { throw new NullCoreException(); } InsertQuery iQuery = new InsertQuery(GetTable(typeof(Calendar))); iQuery.AddField("calendar_item_id", owner.Id); iQuery.AddField("calendar_item_type_id", owner.TypeId); iQuery.AddField("calendar_simple_permissions", true); long calendarId = core.Db.Query(iQuery); Calendar newCalendar = new Calendar(core, owner); if (owner is User) { Access.CreateAllGrantsForOwner(core, newCalendar); newCalendar.Access.CreateGrantForPrimitive(Friend.GetFriendsGroupKey(core), "VIEW"); } if (owner is UserGroup) { newCalendar.Access.CreateGrantForPrimitive(UserGroup.GetGroupOperatorsGroupKey(core), "VIEW", "CREATE_EVENTS", "CREATE_TASKS", "ASSIGN_TASKS", "EDIT_EVENTS", "EDIT_TASKS"); newCalendar.Access.CreateGrantForPrimitive(UserGroup.GetGroupOfficersGroupKey(core), "VIEW", "CREATE_EVENTS", "CREATE_TASKS", "ASSIGN_TASKS", "EDIT_EVENTS", "EDIT_TASKS"); newCalendar.Access.CreateGrantForPrimitive(User.GetEveryoneGroupKey(core), "VIEW"); newCalendar.Access.CreateGrantForPrimitive(User.GetCreatorKey(core), "EDIT_EVENTS", "EDIT_TASKS"); } return newCalendar; }
private static void showDayEvents(Core core, Primitive owner, int year, int month, int day, VariableCollection weekVariableCollection, List<Event> events) { VariableCollection dayVariableCollection = weekVariableCollection.CreateChild("day"); dayVariableCollection.Parse("DATE", day.ToString()); dayVariableCollection.Parse("URI", Calendar.BuildDateUri(core, owner, year, month, day)); DateTime now = core.Tz.Now; if (year == now.Year && month == now.Month && day == now.Day) { dayVariableCollection.Parse("CLASS", "today"); } bool hasEvents = false; List<Event> expired = new List<Event>(); foreach (Event calendarEvent in events) { // if the event starts after the end of the day, skip this day if (calendarEvent.GetStartTime(core.Tz).CompareTo(new DateTime(year, month, day, 23, 59, 59)) > 0) { break; } VariableCollection eventVariableCollection = dayVariableCollection.CreateChild("event"); eventVariableCollection.Parse("TITLE", calendarEvent.Subject); if (calendarEvent.GetStartTime(core.Tz).Day != day) { eventVariableCollection.Parse("START_TIME", calendarEvent.GetStartTime(core.Tz).ToString("d MMMM h:mmt").ToLower()); } else { eventVariableCollection.Parse("START_TIME", calendarEvent.GetStartTime(core.Tz).ToString("h:mmt").ToLower()); } eventVariableCollection.Parse("URI", calendarEvent.Uri); if (calendarEvent is BirthdayEvent) { BirthdayEvent birthdayEvent = (BirthdayEvent)calendarEvent; eventVariableCollection.Parse("BIRTH_DATE", birthdayEvent.User.Profile.DateOfBirth.Day + " " + core.Tz.MonthToString(birthdayEvent.User.Profile.DateOfBirth.Month)); } hasEvents = true; // if the event ends before the end of the day, finish up the event if (calendarEvent.GetEndTime(core.Tz).CompareTo(new DateTime(year, month, day, 23, 59, 59)) <= 0) { expired.Add(calendarEvent); } } if (hasEvents) { dayVariableCollection.Parse("EVENTS", "TRUE"); } foreach (Event calendarEvent in expired) { events.Remove(calendarEvent); } }
public static void DisplayMiniCalendar(Core core, Template template, Primitive owner, int year, int month) { DisplayMiniCalendar(core, template, null, owner, year, month); }
public override SearchResult DoSearch(string input, int pageNumber, Primitive filterByOwner, Type filterByType) { Initialise(); int perPage = 10; int start = (pageNumber - 1) * perPage; List<ISearchableItem> results = new List<ISearchableItem>(); List<ItemKey> itemKeys = new List<ItemKey>(); List<long> applicationIds = new List<long>(); IndexSearcher searcher = new IndexSearcher(directory); QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "item_string", analyzer); BooleanQuery query = new BooleanQuery(); Query bodyQuery = parser.Parse(input); query.Add(bodyQuery, Occur.MUST); BooleanQuery accessQuery = new BooleanQuery(); TermQuery accessPublicQuery = new TermQuery(new Term("item_public", "1")); accessQuery.Add(accessPublicQuery, Occur.SHOULD); if (core.Session.IsLoggedIn) { List<long> friends = core.Session.LoggedInMember.GetFriendsWithMeIds(); BooleanQuery accessFriendQuery = new BooleanQuery(); TermQuery friendQuery = new TermQuery(new Term("item_public", "2")); accessFriendQuery.Add(friendQuery, Occur.MUST); string userTypeId = ItemType.GetTypeId(core, typeof(User)).ToString(); foreach (long friendId in friends) { BooleanQuery ownerQuery = new BooleanQuery(); TermQuery ownerIdQuery = new TermQuery(new Term("owner_id", friendId.ToString())); TermQuery ownerTypeQuery = new TermQuery(new Term("owner_type_id", userTypeId)); ownerQuery.Add(ownerIdQuery, Occur.MUST); ownerQuery.Add(ownerTypeQuery, Occur.MUST); accessFriendQuery.Add(ownerQuery, Occur.SHOULD); } accessQuery.Add(accessFriendQuery, Occur.SHOULD); } query.Add(accessQuery, Occur.MUST); if (filterByType != null) { TermQuery typeQuery = new TermQuery(new Term("item_type_id", ItemType.GetTypeId(core, filterByType).ToString())); query.Add(typeQuery, Occur.MUST); } if (filterByOwner != null) { TermQuery ownerIdQuery = new TermQuery(new Term("owner_id", filterByOwner.Id.ToString())); TermQuery ownerTypeIdQuery = new TermQuery(new Term("owner_type_id", filterByOwner.TypeId.ToString())); query.Add(ownerIdQuery, Occur.MUST); query.Add(ownerTypeIdQuery, Occur.MUST); } TopScoreDocCollector collector = TopScoreDocCollector.Create(start + perPage, true); searcher.Search(query, collector); ScoreDoc[] hits = collector.TopDocs().ScoreDocs; int totalResults = collector.TotalHits; int returnResults = hits.Length; int end = Math.Min(hits.Length, start + perPage); for (int i = start; i < end; i++) { Document doc = searcher.Doc(hits[i].Doc); long itemId = 0; long itemTypeId = 0; long applicationId = 0; long.TryParse(doc.GetField("item_id").StringValue, out itemId); long.TryParse(doc.GetField("item_type_id").StringValue, out itemTypeId); long.TryParse(doc.GetField("application_id").StringValue, out applicationId); ItemKey key = new ItemKey(itemId, itemTypeId); if (!applicationIds.Contains(applicationId)) { applicationIds.Add(applicationId); } itemKeys.Add(key); } // Force each application with results to load for (int i = 0; i < applicationIds.Count; i++) { if (applicationIds[i] > 0) { ApplicationEntry ae = new ApplicationEntry(core, applicationIds[i]); BoxSocial.Internals.Application.LoadApplication(core, AppPrimitives.Any, ae); } } List<IPermissibleItem> tempResults = new List<IPermissibleItem>(); foreach (ItemKey key in itemKeys) { core.ItemCache.RequestItem(key); } foreach (ItemKey key in itemKeys) { try { NumberedItem thisItem = core.ItemCache[key]; if (thisItem != null) { if (thisItem is IPermissibleItem) { tempResults.Add((IPermissibleItem)thisItem); } if (thisItem is IPermissibleSubItem) { tempResults.Add(((IPermissibleSubItem)thisItem).PermissiveParent); } results.Add((ISearchableItem)thisItem); } } catch (InvalidItemException) { } } if (tempResults.Count > 0) { core.AcessControlCache.CacheGrants(tempResults); } return new SearchResult(results, totalResults); }
public static void DisplayMiniCalendar(Core core, VariableCollection vc1, Primitive owner, int year, int month) { DisplayMiniCalendar(core, null, vc1, owner, year, month); }