You are here

function Notifications_Subscription::check_fields in Notifications 6.4

Same name and namespace in other branches
  1. 7 notifications.subscription.inc \Notifications_Subscription::check_fields()

Check all fields are there and optinally that they have a value

File

includes/notifications_subscription.class.inc, line 538
Drupal Notifications Framework - Default class file

Class

Notifications_Subscription
Message destination class

Code

function check_fields($check_values = TRUE) {
  $this
    ->set_fields();
  $instance_fields = array();
  foreach ($this
    ->get_fields() as $field) {
    if ($check_values && !isset($field->value)) {
      return FALSE;
    }
    else {
      $instance_fields[] = $field->field;
    }
  }
  $type_fields = array();
  foreach ($this
    ->get_type_fields() as $field) {
    $type_fields[] = $field->field;
  }
  if (count($instance_fields) != count($type_fields)) {
    return FALSE;
  }
  else {

    // Set the number of conditions if not set
    if (!isset($this->conditions)) {
      $this->conditions = count($instance_fields);
    }

    // Order the arrays so we can compare them. Note that we can have the same field name more than once
    asort($instance_fields);
    asort($type_fields);
    return array_values($instance_fields) == array_values($type_fields);
  }
}