You are here

public function EntityLegalMethod::getDocumentsForMethod in Entity Legal 7

Same name and namespace in other branches
  1. 7.2 methods/entity_legal.method.inc \EntityLegalMethod::getDocumentsForMethod()

Get all Entity Legal Documents for a given user type and method.

Parameters

string $method: The name of the method to find entity legal documents for.

string $user_type: The type of user, existing or signup.

Return value

array All published entity legal documents required for the given user type.

4 calls to EntityLegalMethod::getDocumentsForMethod()
EntityLegalMethodMessage::execute in methods/entity_legal.message.inc
Execution method for message method.
EntityLegalMethodPopup::execute in methods/entity_legal.popup.inc
Execution method for popup method.
EntityLegalMethodProfileForm::getProfileFormMethodDocuments in methods/entity_legal.profile_form.inc
Get all legal document entities with profile form methods.
EntityLegalMethodRedirect::execute in methods/entity_legal.redirect.inc
Execution method for redirect method.

File

methods/entity_legal.method.inc, line 24
Method include file for common base class.

Class

EntityLegalMethod
Base class for entity_legal methods.

Code

public function getDocumentsForMethod($method, $user_type = ENTITY_LEGAL_USER_EXISTING) {

  // Entity Legal administrators should never be forced to accept documents.
  if (user_access('administer legal documents')) {
    return array();
  }

  // Don't run method for anonymous users.
  if ($user_type == ENTITY_LEGAL_USER_EXISTING && user_is_anonymous()) {
    return array();
  }

  // Get all active documents that must be agreed to by existing users.
  $documents = entity_legal_get_all_documents(TRUE, $user_type);

  // Remove any documents from the array set that don't use the given
  // acceptance method.
  foreach ($documents as $name => $document) {
    $agreed = !$document
      ->userMustAgree($user_type == ENTITY_LEGAL_USER_ANONYMOUS) || $document
      ->userHasAgreed();
    $is_method = $document
      ->getAcceptanceDeliveryMethod($user_type == ENTITY_LEGAL_USER_ANONYMOUS) == $method;
    if ($agreed || !$is_method) {
      unset($documents[$name]);
    }
  }
  return $documents;
}