You are here

public function FlexiformFCHandler::completeness in Flexiform 7

Overrides fcComplete::completeness

File

flexiform_webform/flexiform_webform.fc.inc, line 153
Contains the Field Comlete handler for the FlexiformWebform Module.

Class

FlexiformFCHandler
@file Contains the Field Comlete handler for the FlexiformWebform Module.

Code

public function completeness() {
  $form = $this
    ->getForm();
  if ($form == '__none') {
    return parent::completeness();
  }
  $flexiform = entity_load_single('flexiform', $form);
  if (!$flexiform) {
    throw new Exception(t('Completeness Calculation Failed: The flexiform %form does not exist.'));
  }

  // Get the Entities.
  $this->entities = $flexiform
    ->getBuilder($this->entity)
    ->getEntityManager()
    ->getEntities();
  $this->completeness = array();
  foreach ($flexiform->elements as $element_namespace => $element_settings) {
    $elementComplete = $this
      ->getElementCompleteness($flexiform, $element_namespace);
  }
  $count_fields = count($this->completeness);
  $complete_fields = count(array_filter($this->completeness));
  $this->complete = $count_fields == $complete_fields;
  $this->percentage = $count_fields ? (int) ($complete_fields * 100 / $count_fields) : 100;
}