/**
  * Delete group
  *
  * @param int $id
  * @return bool
  */
 public function delete($id)
 {
     // Delete all records from table of the links
     $user_groups_model = new waUserGroupsModel();
     $user_groups_model->deleteByField('group_id', $id);
     // Delete group
     return $this->deleteById($id);
 }
 /**
  * Delete one or more contacts and fire event сontacts.delete
  *
  * @event contacts.delete
  *
  * @param int|array $id - contact id or array of contact ids
  * @return bool
  */
 public function delete($id, $send_event = true)
 {
     if ($send_event) {
         // Fire @event contacts.delete allowing other applications to clean up their data
         if (!is_array($id)) {
             $id = array($id);
         }
         wa()->event(array('contacts', 'delete'), $id);
     }
     if (is_array($id)) {
         $nid = array();
         foreach ($id as $i) {
             $nid[] = -(int) $i;
         }
     } else {
         $nid = -(int) $id;
     }
     // Delete rights
     $right_model = new waContactRightsModel();
     $right_model->deleteByField('group_id', $nid);
     // Delete settings
     $setting_model = new waContactSettingsModel();
     $setting_model->deleteByField('contact_id', $id);
     // Delete emails
     $contact_email_model = new waContactEmailsModel();
     $contact_email_model->deleteByField('contact_id', $id);
     // Delete from groups
     $user_groups_model = new waUserGroupsModel();
     $user_groups_model->deleteByField('contact_id', $id);
     // Delete from contact lists
     if (class_exists('contactsContactListsModel')) {
         // @todo: Use plugin for contacts
         $contact_lists_model = new contactsContactListsModel();
         $contact_lists_model->deleteByField('contact_id', $id);
     }
     // Delete from contact rights
     $contact_rights_model = new contactsRightsModel();
     $contact_rights_model->deleteByField('group_id', $nid);
     // Delete data
     $contact_data_model = new waContactDataModel();
     $contact_data_model->deleteByField('contact_id', $id);
     $contact_data_text_model = new waContactDataTextModel();
     $contact_data_text_model->deleteByField('contact_id', $id);
     //        // Delete contact from logs
     //        $login_log_model = new waLoginLogModel();
     //        $login_log_model->deleteByField('contact_id', $id);
     // Clear references
     $this->updateByField(array('company_contact_id' => $id), array('company_contact_id' => 0));
     // Delete contact
     return $this->deleteById($id);
 }