Forum for discussing general topics related to Couch.
16 posts Page 1 of 2
I have made a cloned page. When I would save a certain cloned page, I would like to be able to compare that record with the other available records, and if some checks appear to be true, I want to be able to edit the other records within the same clonable page and on other clonable pages. Is this possible? If yes, how to do this?
@cowgirl, could you maybe provide an example? I am sure, you know that calcs, checks and comparisons can be made in the background - while page loads in browser - and accordingly, different content can be outputted. I have never heard of simultaneous edits of 2 clonable pages in backend though.. But, I guess, everything can be done if it is worthy :)


cowgirl wrote: I have made a cloned page. When I would save a certain cloned page, I would like to be able to compare that record with the other available records, and if some checks appear to be true, I want to be able to edit the other records within the same clonable page and on other clonable pages. Is this possible? If yes, how to do this?
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
My idea was to link pages together that are in the same cloned page template. I tried to do this using relations, but can't seem to get that to work because I can't get it to filter part of the result. Now I've filtered it and put the results in a dropdown. In order when page A links to page B, I also want page B to link to page A, if that makes sence?
cowgirl wrote: My idea was to link pages together that are in the same cloned page template. I tried to do this using relations, but can't seem to get that to work because I can't get it to filter part of the result. Now I've filtered it and put the results in a dropdown. In order when page A links to page B, I also want page B to link to page A, if that makes sence?

Absolutely. Let me rephrase a bit here, so you can say if I got you correctly. Ok?

When you relate page A to the same template, which holds pages A, B, C, D with relation editable, you assign then some pages, which will be 'linked' to page A. Now, what you expect is to visit pages, linked to A and see that their relation editables also show relation to A. I'm very sorry if it's not what you want, so need your help here.

In case above, the relation editable must be assigned dynamically by providing (and storing) relevant id's taken from the other part of the relation. I guess, this can be done with dynamic parameter of the editables and db_persist. So, upon save (and imminent reload) of page A, a dynamic snippet would run through the linked pages and store id of page A as values of relation editables of other linked pages.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Yeah, something like that, but a little bit more complicated.
I have a variable amount of options (ex. option A, option B, option C,...) = cloned page.
I have products that can be linked together (ex. product 1, product 2, product 3, product 4,...) (=also cloned page). I have regular dropdown or a dropdown with a one to many relationship to the options (not sure which one is best to use at this point) to give each product his own option (ex. product 1, with option A).
Let's assume
Product 1 has option A
Product 2 has option A
Product 3 has option B
Product 4 has option B
Product 5 has option C
Product 6 has option C

* If product 1 has option A, it can only be linked with no other products, it can be linked with 1 product of option B, (so prod. 3 or 4), or it can be linked to 1 product with option C (so prod. 5 or 6), or with one product of option B combined with one product of option C (so (3 or 4) and (5 or 6). It can never be linked to another product with an option A, or multiple products with the same option. If that makes sense?
In short
- Each product has 1 option
- Each product can never be linked with another product that has the same option
- Each product with another option can be linked maximum 1 time to the product.

So our product 1 has option A and we want to link it to product 4 (B) and product 6 (C). Then product 4 and 6 are taken and can't be linked, because product 1 links to 4 and 6, product 4 links to 1 and 6 and 6 links to 1 and 4

We can leave product 2 as a standalone, so no links.
And we can link product 3 and 5 together.

(optional would be that if I would like to link product 1 to 3 and 5, it would be removed from 4 and 6 and would be added to 3 and 5, but that's no priority, I would be very satisfied if I could get the above to work already)


My first idea was something like this:
options.php
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title="Options" clonable="1">
    <cms:editable name="code" type="text"></cms:editable>   
    <cms:editable name="description" type="text"></cms:editable>
<!-- add some other details later that are not relevant to the main problem etc. -->
</cms:template>

<?php COUCH::invoke(); ?>


products.php
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title="Products" clonable="1">
    <!-- Start generate options with dropdown -->
<cms:set available_options="---Select---=\"\"" scope='global'/>

<cms:pages masterpage='options.php'>
    <cms:set available_options="<cms:concat available_options '|' k_page_title '=' k_page_name />" scope='global' />
</cms:pages>

<cms:editable
    type='dropdown' 
    name='current_option'
    opt_values=available_options
    required='1'
/>
<!-- end generate options with dropdown -->

<!-- Start generate options with relationship -->
    <cms:editable type='relation' masterpage='options.php' name ='current_option2' has='one' reverse_has='many' />
<!-- end generate options with relationship -->

<!-- Start looping through other options and put related products in dropdown-->

<cms:pages masterpage='options.php'>
    <cms:set link_option=k_page_name scope='global' />
    <cms:set dropdown_name="<cms:concat k_page_name '_link' />" scope='global'/>
    <cms:set available_options="---Select---=\"\"" scope='global'/>
    <cms:pages masterpage='products.php' >
        <cms:if current_option = link_option >
            <cms:set available_options="<cms:concat available_options '|' k_page_title '=' k_page_name />" scope='global' />
        </cms:if>
    </cms:pages>

    <cms:editable
        type='dropdown'
        name=dropdown_name
        required='0'
        opt_values=available_options
    />
</cms:pages>

<!-- problems with this:
        * product of same option need to be hidden, maybe some javascript to hide one on select op the own option or something?
        * other products don't get linked back
        * products that are already linked are still available
-->
<!-- End looping through other option and put other products in relationships -->

<!-- Start looping through other option and put other products in relationships -->
<cms:pages masterpage='options.php'>
    <cms:set rel_name="<cms:concat k_page_name '_link2' />" />
    <cms:editable type='relation' name=rel_name masterpage='products.php' has='one' reverse_has='one'/>
</cms:pages>
<!-- problems with this:
        * product of same option need to be hidden, maybe some javascript to hide one on select op the own option or something?
        * other products don't get linked back
        * every product is visible in every option specific dropdown, so that means product with for example option A are also available as option B or C!
          ? filter the relationship display?
    + products that are already linked aren't still available. If product 5 is used as a link with option C, there is no other product 5 anywhere else available in an option C
      so this is an improvement
-->
<!-- End looping through current_option dropdown into other product links relationship -->

</cms:template>

<?php COUCH::invoke(); ?>



As you can see I've been experimenting with possible solutions, but I haven't found one yet.
Cool! I'll come up with something this weekend :) Have to experiment a bit myself with this.
On the first thought i'd say there got to be a separate template which can hold cross-linking, but probably can be done some other way. Hold on :D
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
I've found that I could alter the edit page but I'm not sure if I can use the page as is and only edit the db_persist form or something... I do need to make sure I'm not creating loops or something then...

I've found the examples at the bottom of http://docs.couchcms.com/concepts/databound-forms.html page, I've worked with altered lists already, but I'm not sure how to get the form back on the my_edit.html snippet without doing the entire databound form things. I don't want to alter much at the forms them selves, rather the behaviour of certain fields when saved.
Hi, cowgirl :)

It was a tricky setup, but I think I have solved it.
demo: http://koro.tk/cowgirl/ admin:admin

3 templates: Products, Options, Groups. Relation editable exists only in Products, which is related to Options.

I will try to describe the logic behind the solution. First, we need to specify an option for each product. Then we go to Groups and create a new group. Every group (clonable page in Groups) has an editable checkbox. It has no static op_values, only dynamic ones. Through this checkbox editable with dynamic values, I run a snippet, which enumerates options and then product for each option, creating a customized selection region:
download (1).png
download (1).png (23.37 KiB) Viewed 3079 times

You can see here rows, which is one row per Option. Total, I have 6 products and 4 options, but as no products associated with 4th option D, then it is not shown. Instruction for user is provided to select only one product per row and this will help you to have one product per option.

Now, upon selection and save of this page, you can immediately visit 'linked' products in Products template and see that an editable checkbox appeared, dynamically showing related products. This is only for visuals, and there is no need to click there. Basically, upon every load of this page a dynamic snippet runs and looks for any group that consists of name of this product (this is done with custom_field parameter and intentional use of '=' instead of '==' inside that custom_field parameter of cms:pages).
download (2).png
download (2).png (17.97 KiB) Viewed 3079 times

Now, let's go to create a new group of products. As far as we have dynamic showing of available products, we can filter our those, that already were used in other groups.
download (3).png
download (3).png (16.52 KiB) Viewed 3079 times

This can be a bit difficult, is more like magic. How do I show all products for the first group and only 'unused' ones for the next group? I have created a list of all used products as a variable linked_products. Then in cms:pages loop, I add page_name parameter:
Code: Select all
page_name="<cms:if linked_products >NOT <cms:show linked_products /></cms:if>"

It makes possible to have page_name="" for the first group and page_name="NOT product-2, product-4, product-5" for the new group. For the very next, third, group the list of linked_products will be again updated and therefore ready to be grouped. Another trick is to exclude current page from linked_products , because we don't want to select products to group and have them disappeared :) so, need to include this parameter while creating list of linked_products
Code: Select all
id="NOT <cms:show k_page_id />"


Probably, with the setup above I could wrap up the solution, but we'll add a bit of usability to it. On every load of clonable group, a snippet runs and checks page titles of groups. It is very nice to have a meaningful group name, instead of some arbitrary and silent titles like 'Group 1, Group 2'. So, if script encounters a bad naming, it automatically renames other pages to something like this (totally customizable):
download (4).png
download (4).png (8.63 KiB) Viewed 3079 times


I hope you check the demo and find it helpful.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Hi @trendoman,

Just wanted to say I liked what you did here, very neat..!
I load frameworks and write bugs on top of them, after that I rearrange the code so that it looks like a cool product.
Tomarnst wrote: Hi @trendoman,

Just wanted to say I liked what you did here, very neat..!


Hi, @Tomarnst, thank you! Couch has many nice features and featurettes :)
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
16 posts Page 1 of 2