| Quintiq file version 2.0 | 
| #parent: #root | 
| StaticMethod GetEntitiesToSave ( | 
|   Entitys checkEntities | 
| ) as owning Entitys | 
| { | 
|   Description: | 
|   [* | 
|     Web introduced new bookmark logic. Keep bookmark as short as possible. | 
|     If all children (and descendants) checked, store the parent only. If partial, then no choice we store the checked children. | 
|   *] | 
|   TextBody: | 
|   [* | 
|     result := construct( Entitys ); // Entities to bookmark | 
|      | 
|     // Filter out system (WIP) entities and parent entities | 
|     checkLeafEntities := selectset( checkEntities, Elements, c, not c.GetIsSystem() and c.ChildEntity( relsize ) = 0 ); | 
|      | 
|     // Based on filtered entities, get all their parents | 
|     allParentsSorted := selectsortedset( Entity::GetAllParents( checkLeafEntities ),  | 
|                                          Elements, e,  | 
|                                          e.ChildEntity( relsize ) > 0, // Filter out the leaf as GetAllParents return the entity itself as well | 
|                                          e.DisplayIndex() );           // Sort from root down to lower level entities  | 
|      | 
|     // Important to start with root, as we will remove 'intersecting' leaf entities as we loop | 
|     traverse( allParentsSorted, Elements, parent, checkLeafEntities.Size() > 0 ) // Continue as long as there's entities to be considered | 
|     { | 
|       leafDescendants := parent.GetLeafDescendants();  | 
|      | 
|       // If current parent's leaf descendants are found in user checked entities | 
|       // We only bookmark the parent and remove leaf descendants from the list and proceed next parent | 
|       // Example (Food demo): Add unit Plants if ALL Denmark, Hungary and France machines are part of user checked entities | 
|       if( checkLeafEntities.ContainsAll( leafDescendants ) ) | 
|       { | 
|         checkLeafEntities.Remove( leafDescendants );   | 
|         result.Add( parent );   | 
|       } | 
|     } | 
|      | 
|     // If there's leaf entities left (not all siblings check), add them to the result | 
|     if( checkLeafEntities.Size() > 0 ) | 
|     { | 
|       result := result.Union( checkLeafEntities ); | 
|     } | 
|      | 
|     return &result; | 
|   *] | 
| } |