docs: def get_collection_tree(collection_ident, cursor):
      """Build and retrieve json tree representation of a book."""
      cursor.execute('''
      WITH RECURSIVE t(node, parent, document, path) AS (
          SELECT tr.nodeid, tr.parent_id, tr.documentid, ARRAY[tr.nodeid]
          FROM trees tr
          WHERE tr.documentid = %s and tr.is_collated = 'False'
      UNION ALL
          SELECT c.nodeid, c.parent_id, c.documentid, path || ARRAY[c.nodeid]
          FROM trees c JOIN t ON c.parent_id = t.node
          WHERE NOT c.nodeid = ANY(t.path)
      )
      SELECT t.document, m.portal_type
      FROM t JOIN modules m
      ON t.document = m.module_ident''', [collection_ident])
      for i in cursor.fetchall():
          yield i