/// <summary> /// /// </summary> /// <param name="core">Core token</param> /// <param name="galleryItem"></param> /// <param name="owner"></param> /// <param name="member"></param> /// <param name="location"></param> /// <returns></returns> public static UserTag Create(Core core, GalleryItem galleryItem, User owner, User member, Point location) { if (core == null) { throw new NullCoreException(); } InsertQuery query = new InsertQuery("user_tags"); query.AddField("user_id", owner.UserId); query.AddField("tag_user_id", member.UserId); query.AddField("gallery_item_id", galleryItem.ItemId); query.AddField("tag_x", location.X); query.AddField("tag_y", location.Y); if (owner.UserId != member.UserId) { query.AddField("tag_approved", false); } else { query.AddField("tag_approved", true); } long tagId = core.Db.Query(query); UserTag tag = new UserTag(core, galleryItem, tagId); NotifyTag(core, tag); return tag; }
/// <summary> /// Notify users affected by a tag of the tag /// </summary> /// <param name="core">Core token</param> /// <param name="tag">Tag to notify of</param> private static void NotifyTag(Core core, UserTag tag) { if (tag.tagApproved) { if (tag.TaggedMember.UserInfo.EmailNotifications) { RawTemplate emailTemplate = new RawTemplate(core.Http.TemplateEmailPath, "photo_tag_notification.eml"); emailTemplate.Parse("TO_NAME", tag.TaggedMember.DisplayName); emailTemplate.Parse("FROM_NAME", core.Session.LoggedInMember.DisplayName); emailTemplate.Parse("FROM_USERNAME", core.Session.LoggedInMember.UserName); emailTemplate.Parse("U_PHOTO", core.Hyperlink.StripSid(core.Hyperlink.AppendAbsoluteSid(tag.TaggedGalleryItem.BuildUri()))); core.Email.SendEmail(tag.TaggedMember.UserInfo.PrimaryEmail, string.Format("{0} tagged you in a photo", core.Session.LoggedInMember.DisplayName), emailTemplate.ToString()); } } }
/// <summary> /// Approves a user tag for public display. /// </summary> /// <param name="core">Core token</param> /// <param name="tag">User tag to approve</param> /// <returns>True on success</returns> public static bool ApproveTag(Core core, UserTag tag) { UpdateQuery query = new UpdateQuery("user_tags"); query.AddField("tag_approved", true); query.AddCondition("tag_id", tag.TagId); query.AddCondition("user_id", core.LoggedInMemberId); if (core.Db.Query(query) == 1) { tag.tagApproved = true; // we can update private members NotifyTag(core, tag); return true; } else { return false; } }