Ejemplo n.º 1
0
 /**
  * Create an array with the incomplete items in the profile and the relative weight.
  *
  * @param Contact $contact
  *
  * @return array;
  */
 public function getProfileInCompleteness(Contact $contact)
 {
     $inCompleteness = [];
     $totalWeight = 0;
     $totalWeight += 10;
     if (is_null($contact->getFirstName())) {
         $inCompleteness['firstName']['message'] = _("txt-first-name-is-missing");
         $inCompleteness['firstName']['weight'] = 10;
     }
     $totalWeight += 10;
     if (is_null($contact->getLastName())) {
         $inCompleteness['lastName']['message'] = _("txt-last-name-is-missing");
         $inCompleteness['lastName']['weight'] = 10;
     }
     $totalWeight += 10;
     if (sizeof($contact->getPhone()) === 0) {
         $inCompleteness['phone']['message'] = _("txt-no-telephone-number-known");
         $inCompleteness['phone']['weight'] = 10;
     }
     $totalWeight += 10;
     if (sizeof($contact->getAddress()) === 0) {
         $inCompleteness['address']['message'] = _("txt-no-address-known");
         $inCompleteness['address']['weight'] = 10;
     }
     $totalWeight += 10;
     if (sizeof($contact->getPhoto()) === 0) {
         $inCompleteness['photo']['message'] = _("txt-no-profile-photo-given");
         $inCompleteness['photo']['weight'] = 10;
     }
     $totalWeight += 10;
     if (is_null($contact->getSaltedPassword())) {
         $inCompleteness['password']['message'] = _("txt-no-password-given");
         $inCompleteness['password']['weight'] = 10;
     }
     $totalWeight += 20;
     if (is_null($contact->getContactOrganisation()) === 0) {
         $inCompleteness['organisation']['message'] = _("txt-no-organisation-known");
         $inCompleteness['organisation']['weight'] = 20;
     }
     /*
      * Determine the total weight
      */
     $incompletenessWeight = 0;
     /*
      * Update the values in the table to create a total weight of 100%
      */
     foreach ($inCompleteness as &$itemPerType) {
         $itemPerType['weight'] = $itemPerType['weight'] / $totalWeight * 100;
         $incompletenessWeight += $itemPerType['weight'];
     }
     return ['items' => $inCompleteness, 'incompletenessWeight' => $incompletenessWeight];
 }