You are here

public function RedhenOrgEntityController::delete in RedHen CRM 7

Deletes multiple orgs by id.

Parameters

array $org_ids: An array of org IDs to delete.

DatabaseTransaction $transaction: DB transaction object.

Return value

bool TRUE on success, FALSE otherwise.

Throws

Exception

Overrides EntityAPIController::delete

File

modules/redhen_org/lib/redhen_org.controller.inc, line 58
The controller for the org entity containing the CRUD operations.

Class

RedhenOrgEntityController
The controller class for orgs contains methods for the org CRUD operations. The load method is inherited from the default controller.

Code

public function delete($org_ids, DatabaseTransaction $transaction = NULL) {
  if (!empty($org_ids)) {
    $orgs = $this
      ->load($org_ids, array());

    // Ensure the orgs can actually be deleted.
    foreach ((array) $orgs as $org_id => $org) {
      if (in_array(FALSE, module_invoke_all('redhen_org_can_delete', $org))) {
        unset($orgs[$org_id]);
      }
      else {
        module_invoke_all('redhen_entity_predelete', $org, 'redhen_org');
      }
    }
    $transaction = db_transaction();
    try {
      parent::delete($org_ids, $transaction);
    } catch (Exception $e) {
      if (isset($transaction)) {
        $transaction
          ->rollback();
      }
      watchdog_exception($this->entityType, $e);
      throw $e;
    }
  }
  return TRUE;
}