示例#1
0
 /**
  * Creates a form model given a token.
  *
  * @param int   $id     The user ID.
  * @param array $config name-value pairs that will be used to initialize the object properties
  * @throws \yii\base\InvalidParamException if token is empty or not valid
  */
 public function __construct($id, $config = [])
 {
     // Volunteer can be new or have an existing entry.
     $this->_volunteer = Volunteer::findOne($id);
     if (!$this->_volunteer) {
         $this->_volunteer = new Volunteer();
         $this->_volunteer->accountID = $id;
     } else {
         // Initialise form values.
         foreach ($this::$interestBits as $key => $value) {
             if ($key & $this->_volunteer->interests) {
                 $this->interests[] = $key;
             }
         }
         foreach ($this::$availabilityBits as $key => $value) {
             if ($key & $this->_volunteer->availability) {
                 $this->availability[] = $key;
             }
             if ($key & $this->_volunteer->experience) {
                 $this->experience[] = $key;
             }
         }
         $this->daysAvailable = $this->_volunteer->daysAvailable;
         $this->skills = $this->_volunteer->skills;
         $this->mobile = User::findOne($id)->details->mobile;
     }
     parent::__construct($config);
 }