Here's the situation:
I have 3 modules (2 custom) with relationships:
Accounts one-to-many with Items Module
Accounts one-to-many with DVR Module
DVR one-to-many with Items Module
DVR is basically a container for Items.
I need to change the account for each item related to DVR to match whenever the account is changed on the DVR using a logic_hook. I'm thinking this would best be done using after_save. I'm sure there is an easier way to do this by referencing the subpanel beans, but I can't figure out how to reference those. Here is the code I have so far. By the way I'm using 5.5.0 CE Stack Installer.
Logic Hook:
PHP Code:Code:<?php //Logic Hook to change item's account relationship when its related DVR account when relationship is changed $hook_version = 1; $hook_array['after_save'][] = Array(1, 'itemMover', 'custom/customCode/move_items.php', 'itemMover', 'moveItems'); ?>
I've successfully implemented logic_hooks to format Account text fields to upper case and to format phone numbers before_save and I'm using these as a template, however my code in this case is much more complex. I'm also not sure how to see what is contained in the $bean array to troubleshoot. I've tried setting the description field to $bean->description = print_r($bean) to see the contents but no luck, not even if specify the value $bean->description = '1234'. Any help would be greatly appreciated.Code:<?php //if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); class itemMover { function moveItems(&$bean, $event, $arguments){ //Check if Account Field changed //if($bean->account_id != $bean->fetched_row['account_id']){} //Will implement when everything else is working //Get items attached to DVR $i = 0; $item_array = Array(); $id = $bean->id; $acct_id = $bean->account_id; $query = "SELECT * FROM inv_dvrs_inv_items WHERE inv_dvrs_i38aenv_dvrs_ida = '".$id."' AND deleted = 0"; $results = $bean->db->query($query, true); while($row = $bean->db->fetchByAssoc($results)){ $item_array[$i] = $row['inv_dvrs_iaf07v_items_idb']; $i++; } //Set Account for items to match DVR account foreach($item_array as $item){ $query = "UPDATE inv_items_accounts_c SET inv_items_5455ccounts_ida = '".$acct_id."' WHERE inv_items_bf35v_items_idb = '".$item."'"; } } } ?>
Also, not sure if this makes a difference here or not, but when opening a custom popup via a button (using Enhanced Studio) .htaccess would not allow it because /modules/ was forbidden and the path was custom/modules/. I had to move the popup file backwards into custom/. I don't really think this is the case here because my other logic_hooks execute but I figured it was worth mentioning.


LinkBack URL
About LinkBacks



Reply With Quote



Bookmarks