Adam Kiss Posted June 11, 2011 Share Posted June 11, 2011 Hi all, I have following setup: [only relevant part showed] HOUSE .. parcel_reference: single_page PARCELL .. reserved: checkbox/boolean Note: there is X PARCELLs and Y HOUSEs. each HOUSE has exactly one PARCELL, meaning there might be page with template PARCELL, which isn't referenced by any HOUSE page, but there can't be HOUSE page, which has no reference to PARCELL. Now, I would like to select all pages of type PARCELL (e.g. via 'parent=/parcells/'), that isn't referenced via any HOUSE page AND doesn't have 'reserved' checked. Is there any possible API way, or do I have to select all PARCELLs with no reserved checked (query: 'parent=/parcells/, reserved=0') and test this array against 'template=HOUSE' query? Link to comment Share on other sites More sharing options...
ryan Posted June 12, 2011 Share Posted June 12, 2011 Adam, good question. What you are describing seems to be a parent-children relationship between PARCELL and HOUSE? there is X PARCELLs and Y HOUSEs. each HOUSE has exactly one PARCELL, meaning there might be page with template PARCELL, which isn't referenced by any HOUSE page, but there can't be HOUSE page, which has no reference to PARCELL. In this type of situation, it might make sense to relate these things with your structure so that HOUSE pages are children of PARCELL pages. Then you can do this: parent=/parcells/, reserved=0, num_children=0 (I realized as I was writing this email that I hadn't actually implemented the num_children/numChildren field as an option in selectors yet, so I went ahead and added that to the 2.1 source and committed it. So it works now.) If you don't want to relate these things by structure (as described above) then you can't really use a selector because there is no HOUSE field on PARCELL pages (i.e. there's nothing to select). So if you need to be selecting them in this way, then it might make more sense to not have a parcel_reference field on your HOUSE pages and instead have a house_reference (multi-page) field on your PARCELL pages. Then you could select like this: parent=/parcells/, reserved=0, house_reference=0 Link to comment Share on other sites More sharing options...
Adam Kiss Posted June 12, 2011 Author Share Posted June 12, 2011 Unfortunately, it isn't possible to solve this way. It isn't in the same tree, because then it would be too complicated for content manager. It works this way: there is a number of parcell pages, which relate to place on map. Number of these places, as well as their location doesn't change. Then there is a list of shops, which I want to tie to these 'places' on map, so I can generate maps via HTML then easily. Explanation: 'HOUSE' template is for shops (thus SHOP template in following text) and PARCELL template is for PLACES on the map (in the shopping centre). I just tried to describe my problem without enclosing real purpose Proposed structure: - shops - category 1 - shop 1 - shop 2 - shop 3 - category 2 - shop 4 - shop 5 .. - internal_data - places - place 1 - place 2 Seeing this structure, due to CRUD of shops, you'll agree it's better to relate places to shops in the shop pages, so the content manager can edit everything in one place. Other option, that came to my mind: is it possible to do something like this: ? <?php //..upon saving 'shop' template, $this is the shop page I'm saving $place = $this->related_place; $place->shop_that_is_here = $this->id; $place->save('shop_that_is_here'); //..upon deleting 'shop' page $place = $this->related_place; $place->shop_that_is_here = null; $place->save('shop_that_is_here'); $this->delete; Thanks Ryan for your help Link to comment Share on other sites More sharing options...
ryan Posted June 12, 2011 Share Posted June 12, 2011 So long as any given shop isn't ever going to have more than 1 category, then the structure you mentioned is good. Admittedly though I am a little confused between house, parcell, shops, categories and places. But it looks like you are asking about a solution that effectively caches the number of shops on the place page, and that's certainly one good potential solution (and you could also setup a module to do it automatically if you wanted). Also, if there aren't going to be hundreds of parcell (place?) pages, then I think you'd be fine to do two queries too: first to find the non-reserved places, and second to determine which of them don't have any shops. Link to comment Share on other sites More sharing options...
Adam Kiss Posted June 12, 2011 Author Share Posted June 12, 2011 Sorry to confuse you, I don't know why I always try to obfuscate what I'm workin' on a little what do you mean, two queries? as in something: <?php $places = $pages->get( /*places query nonreserved*/ ); $shops = $pages->get( /* shops query */); $emptyPlaces = filterarrays ($places, $shops); ? Can I do something like this: $places = $pages->get($non-reserved-places); foreach( array of filtered IDS as $emptyID ){ $empties = $places->get($emptyID); //THIS IS WHAT IM CURIOUS ABOUT } I mean, can I query API result? Thank you Ryan, you're awarded the nicest guy on the internet, always so helpful. Link to comment Share on other sites More sharing options...
ryan Posted June 13, 2011 Share Posted June 13, 2011 What I meant by 2 queries where you would first find the parcells based on the non reserved value. Then go through those parcells as the 2nd query and look at which ones don't have any houses attached. i.e. $parcells = $pages->find("parent=/parcells/, reserved=0"); foreach($parcells as $parcel) { if(!count($parcel->houses)) { // found one } } I'm at the AEA conference here in atlanta, so a little slow on my replies today. Link to comment Share on other sites More sharing options...
Adam Kiss Posted June 13, 2011 Author Share Posted June 13, 2011 I'll write you an email, because we don't understand each other right now., Link to comment Share on other sites More sharing options...
ryan Posted June 13, 2011 Share Posted June 13, 2011 Adam, haven't gotten your email. What address did/are/you sending to? Link to comment Share on other sites More sharing options...
Adam Kiss Posted June 13, 2011 Author Share Posted June 13, 2011 I haven't written it yet. This is one horrible fucking day. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now