<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of acl_user_edit_observer
 *
 * @author Igor Ratsun
 */
class acl_rule_edit_observer implements SplObserver {

    #[\ReturnTypeWillChange]
    public function update(SplSubject $subject) {
        $CI = & get_instance();
        
        $ids = $subject->get_roles_id();
        
        if (empty($ids)) {
            
            return FALSE;
        }

        $q = $CI->db->
                        select('acl_role_name')->
                        where_in('id_acl_role', $ids)->
                        get('acl_role')->result_array();

        if (!empty($q)) {
            $CI->load->helper('ciext/observer');
            $CI->lang->load('ciext/observers/acl_user');
            $save = new saveObserver();
            $save->set_access('acl', 'edit_rule');
            foreach ($q as $v) {
                $save->set_text(sprintf($CI->lang->line('Changed user rules'), $v['acl_role_name']));
                $save->save();
            }
        }
    }

}
