/**
  *
  *
  * @param array $pa_group_ids
  * @param array $pa_options Supported options are:
  *		user_id - if set, only user groups owned by the specified user_id will be added
  */
 public function addACLUserGroups($pa_group_ids, $pa_options = null)
 {
     if (!($vn_id = (int) $this->getPrimaryKey())) {
         return null;
     }
     require_once __CA_MODELS_DIR__ . '/ca_acl.php';
     $vn_table_num = $this->tableNum();
     $vn_user_id = isset($pa_options['user_id']) && $pa_options['user_id'] ? $pa_options['user_id'] : null;
     $va_current_groups = $this->getACLUserGroups();
     $t_acl = new ca_acl();
     foreach ($pa_group_ids as $vn_group_id => $vn_access) {
         if ($vn_user_id) {
             // verify that group we're linking to is owned by the current user
             $t_group = new ca_user_groups($vn_group_id);
             if ($t_group->get('user_id') != $vn_user_id && $t_group->get('user_id')) {
                 continue;
             }
         }
         $t_acl->clear();
         $t_acl->load(array('group_id' => $vn_group_id, 'table_num' => $vn_table_num, 'row_id' => $vn_id));
         // try to load existing record
         $t_acl->setMode(ACCESS_WRITE);
         $t_acl->set('table_num', $vn_table_num);
         $t_acl->set('row_id', $vn_id);
         $t_acl->set('group_id', $vn_group_id);
         $t_acl->set('access', $vn_access);
         if ($t_acl->getPrimaryKey()) {
             $t_acl->update();
         } else {
             $t_acl->insert();
         }
         if ($t_acl->numErrors()) {
             $this->errors = $t_acl->errors;
             return false;
         }
     }
     return true;
 }