Ejemplo n.º 1
0
 /**
  * inactivates other phonees owned by this user with the same 
  * phone type
  */
 private function _inactivate_all_actives()
 {
     $phones = new Phones($this->pidm);
     $phones->load();
     $active = $phones->active_by_type($this->tele_code);
     foreach ($active as $phone) {
         $phone->set_inactive();
         $phone->save();
     }
     //end foreach
 }
Ejemplo n.º 2
0
 /**
  * save the Rave phone
  *
  * @param $option \b Rave save option (false, opted_out, deferred, resend, no_confirm)
  */
 public function save($option = false)
 {
     if (!$this->wp_id) {
         throw new UnexpectedValueException('A user id (wp_id) is required before saving. No user id was provided.');
     }
     //end if
     $args = $this->sanitize();
     // we need to get the current phone for the user.
     // load the phones
     $phones = new Phones($this->wp_id);
     $phones->load();
     // grab the most recent, active number whose type matches this phone's type
     $current = $phones->current($phones->type($args['phone_type']));
     if ($current || $option == 'deferred' || $option == 'opted_out') {
         /* it will enter the following if (not the ifesles) when:
          *   1) they have a current phone that doesn't match the phone they are saving, OR
          *   2) they are deferring, OR
          *   3) they are opting out, OR
          *   4) they have a current phone that matches the phone they are saving AND they 
          *        are either continuing/not confirming AND the current phone is set to optout or deferred
          */
         if ($current && $current->phone != $args['phone'] || $option == 'deferred' || $option == 'opted_out' || $current && $current->phone == $args['phone'] && ($option == 'continue' || $option == 'no_confirm') && ($current->opt_nocell || $current->opt_notnow)) {
             \PSU::db('emergency_notificationt')->StartTrans();
             if ($current && !($current->phone == $args['phone'] && $option == 'continue')) {
                 $current->unconfirm($current->phone);
             }
             //end if
             // if we get here, we're going to be adding a new phone number.  Expire
             //   all of the active ones that match this number's type
             self::expire_all_active($args['wp_id'], $args['phone_type']);
             $do_final_commit = true;
         } elseif ($option === 'resend') {
             $rave_user = \PSU\Rave\User::get($this->wp_id);
             return $rave_user->save(true);
         } else {
             // phone has not changed, do nothing
             return true;
         }
         // end else
     }
     //end if
     // assume we want to actually commit...we'll cancel
     // the commit later if there was an error
     $commit = true;
     if ($ok = $this->_insert($args, $option)) {
         // if we get in here, the insert worked swimmingly
         if (!($ok = $this->_rave_save($args['phone'], $option))) {
             // if we get in here, Rave had an error
             // explicitly fail the transaction
             $commit = false;
         }
         // end rollback
         \PSU::db('emergency_notificationt')->CompleteTrans($commit);
         if ($do_final_commit) {
             \PSU::db('emergency_notificationt')->CompleteTrans($commit);
         }
         return $ok;
     }
     // end if
     return false;
 }