/**
  * Updates UserRow $user with $attributes in DB.
  *
  * @param UserRow $userRow
  * @param array $attributes
  * @return UserRow $updatedUser
  */
 protected function updateUserRow(UserRow $userRow, $attributes)
 {
     foreach ($attributes as $key => $value) {
         $userRow->{$key} = $value;
     }
     if (!isset($userRow->email)) {
         $userRow->email = '';
     }
     if (!isset($userRow->firstname)) {
         $userRow->firstname = '';
     }
     if (!isset($userRow->lastname)) {
         $userRow->lastname = '';
     }
     // Save/Update user in database
     $userRow->save();
     return $userRow;
 }
Beispiel #2
0
 /**
  * This method picks up non-empty values from $from into $into UserRow, which are
  * probably more appreciated than current values within $into UserRow.
  *
  * This method <b>DOES NOT DELETE</b> any UserRow.
  *
  * It also doesn't handle cat_username neither home_library as those were previously
  * set by UserRow::activateBestLibraryCard method.
  *
  * @param UserRow $from
  * @param UserRow $into
  * @return void
  */
 protected function mergeUserRows(UserRow $from, UserRow $into)
 {
     $mergedSomething = false;
     $basicNonEmptyMerge = ["firstname", "lastname", "email", "password", "pass_hash", "verify_hash"];
     foreach ($basicNonEmptyMerge as $column) {
         // Replace current value only if it is empty
         if (empty($into->{$column}) && !empty($from->{$column})) {
             $into->{$column} = $from->{$column};
             $mergedSomething = true;
         }
     }
     $basicMerge = ["major", "college"];
     foreach ($basicMerge as $column) {
         // Merge not needed if the columns are identical
         if (!empty($from->{$column}) && $into->{$column} !== $from->{$column}) {
             // Replace current value only if it is empty
             if (empty($into->{$column})) {
                 $into->{$column} = $from->{$column};
                 $mergedSomething = true;
             } else {
                 // If are both set, then merge those using ';' delimiter
                 $into->{$column} .= ';' . $from->{$column};
                 $mergedSomething = true;
             }
         }
     }
     if ($mergedSomething) {
         $into->save();
     }
 }