Ejemplo n.º 1
0
        public override IEnumerable <Tuple <Feed, object> > GetFeeds(FeedFilter filter)
        {
            var q1 = new SqlQuery("files_folder f")
                     .Select(FolderColumns().Select(f => "f." + f).ToArray())
                     .Select(DocumentsDbHelper.GetRootFolderType("parent_id"))
                     .Select("null, null, null")
                     .Where(
                Exp.Eq("f.tenant_id", filter.Tenant) &
                Exp.Eq("f.folder_type", 0) &
                Exp.Between("f.create_on", filter.Time.From, filter.Time.To)
                );

            var q2 = new SqlQuery("files_folder f")
                     .LeftOuterJoin("files_security s",
                                    Exp.EqColumns("s.entry_id", "f.id") &
                                    Exp.Eq("s.tenant_id", filter.Tenant) &
                                    Exp.Eq("s.entry_type", (int)FileEntryType.Folder)
                                    )
                     .Select(FolderColumns().Select(f => "f." + f).ToArray())
                     .Select(DocumentsDbHelper.GetRootFolderType("parent_id"))
                     .Select("s.timestamp, s.owner, s.subject")
                     .Where(
                Exp.Eq("f.tenant_id", filter.Tenant) &
                Exp.Eq("f.folder_type", 0) &
                Exp.Lt("s.security", 3) &
                Exp.Between("s.timestamp", filter.Time.From, filter.Time.To)
                );

            List <Tuple <Folder, SmallShareRecord> > folders;

            using (var db = new DbManager(DbId))
            {
                folders = db.ExecuteList(q1.UnionAll(q2))
                          .ConvertAll(ToFolder)
                          .Where(f => f.Item1.RootFolderType != FolderType.TRASH && f.Item1.RootFolderType != FolderType.BUNCH)
                          .ToList();
            }

            var parentFolderIDs = folders.Select(r => r.Item1.ParentFolderID).ToArray();
            var parentFolders   = new FolderDao(Tenant, DbId).GetFolders(parentFolderIDs, checkShare: false);

            return(folders.Select(f => new Tuple <Feed, object>(ToFeed(f, parentFolders.FirstOrDefault(r => r.ID.Equals(f.Item1.ParentFolderID))), f)));
        }