Forums / Developer / Change object relations from template

Change object relations from template

Author Message

David Boman

Saturday 09 September 2006 8:17:29 am

Hi,

For the moment I'm working on a membership management system on my site. I have the standard user class and two new classes; 'payment' which stores payments made by the user - it has attributes for amount, date and an object relation attribute pointing to the user who owns the payment. Also a 'membership' class containing membership information like status (aktive, inactive etc) and object relations attribute pointing to the member and to the payment representing the membership fee.

Currently I have the following line view template which will list all members and their corresponding payments (when called from a surronding view template). It also has an action to delete the membership fee but this is were the problems come in...

Currenly the payment object gets deleted (natually, cause I'm calling the action/remove) but what I want to accomplish is that I just want to remove the relation to that payment instead. How to I accomplish this in my input form? Somehow I want to modify the membership object but I don't want to call the edit template for that object - just change the value redisplay the listing again. Any ideas?

{def $payment_object_id_array=$node.object.data_map.payment.content.relation_list}
{foreach $payment_object_id_array as $payment_object_key => $payment_object_id}
	<tr>
		<td>
			{def $user_object_id=$node.object.data_map.user.content.id}
			{def $user_object=fetch( 'content', 'object', hash( 'object_id', $user_object_id ) )}
			{def $user_node=fetch( 'content', 'node', hash( 'node_id', $user_object.main_node_id ) )}
			{if $payment_object_key|eq( '0' )}
				<a href='/{$user_node.url_alias}'|ezurl()>{$user_object.name}</a>
			{/if}
		</td>
		<td>
			{def $payment_node=fetch( 'content', 'node', hash( 'node_id', $payment_object_id.node_id ) )}
			<a href={$payment_node.url_alias|ezurl()}>{$payment_node.object.data_map.payment_amount.content} kr</a>
		</td>
		<td>
			{def $payment_date=$payment_node.object.data_map.payment_date.content}
			{$payment_date.year}-{$payment_date.month}-{$payment_date.day}
		</td>
		<td>
			<form name="payment_{$payment_node.node_id}" method="post" action={'/content/action'|ezurl}>
				<input type="hidden" name="ContentNodeID" value="{$payment_node.node_id}" />
				<input type="hidden" name="ContentObjectID" value="{$payment_node.object.id}" />
				<input type="hidden" name="ActionRemove" value="Remove" />
				<a href="#" onclick="document.forms['payment_{$payment_node.node_id}'].submit();return false;">Delete</a>
			</form>
	</tr>
{/foreach}

David Boman

Wednesday 13 September 2006 11:34:20 pm

No one that have any ideas? Have I been thinking completly wrong or am I just not making my self clear?

Xavier Dutoit

Thursday 14 September 2006 1:14:58 am

Hi,

Not sure what you want to do. Anyway, you can use enhanced object relation for instance, to get a list of all the payments and check/uncheck them to associate (related object) to a member.

When you uncheck a payment, it just deletes the relation, not the payment.

Why don''t you store the payments under each member ? Seems easier to me.

X+

http://www.sydesy.com