Remove category children if that option is chosen

This commit is contained in:
Nathan Gray 2011-02-04 17:29:24 +00:00
parent efc61a3243
commit 146ff34de1

View File

@ -783,12 +783,29 @@ class addressbook_so
*/ */
function delete_category($data) function delete_category($data)
{ {
// Get addresses that use the category // get all cats if you want to drop sub cats
$ids = $this->search(array('cat_id' => $data['cat_id']), array('contact_id', 'cat_id')); $drop_subs = ($data['drop_subs'] && !$data['modify_subs']);
foreach($ids as &$info) if($drop_subs)
{ {
$info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), array($data['cat_id']))); $cats = new categories('', 'addressbook');
$this->save($info); $cat_ids = $cats->return_all_children($data['cat_id']);
}
else
{
$cat_ids = array($data['cat_id']);
}
// Get addresses that use the category
@set_time_limit( 0 );
$ids = array();
foreach($cat_ids as $cat_id)
{
$ids = $this->search(array('cat_id' => $cat_id), array('contact_id', 'cat_id'));
foreach($ids as &$info)
{
$info['cat_id'] = implode(',',array_diff(explode(',',$info['cat_id']), $cat_ids));
$this->save($info);
}
} }
} }