Exemplo n.º 1
0
 /**
  * Create a new instance of a I2CE_User_Form object.
  * If the username isn't given then it will be determined from the session array.
  * @param I2CE_FieldContainer_Factory $factory
  * @param string $form The name of this form.  Should be 'user'.
  * @param string $username
  */
 public function __construct($factory, $form, $username = '******')
 {
     parent::__construct($factory, $form, $username);
     $this->user = new I2CE_User($username, true, false, false);
     $access = I2CE::getUserAccess();
     if ($access instanceof I2CE_UserAccess_Mechanism) {
         $this->allowedDetails = $access->getAllowedDetails();
     } else {
         $this->allowedDetails = array();
     }
     foreach ($this->allowedDetails as $detail) {
         if (array_key_exists($detail, $this->fields)) {
             continue;
         }
         if ($detail == 'locale') {
             $header = I2CE_User::getDetailName('locale');
             $options = array('in_db' => true, 'required' => I2CE_User::isRequired('locale'), 'meta' => array('limits' => array('default' => array('locale' => array('operator' => 'FIELD_LIMIT', 'field' => 'selectable', 'style' => 'yes', 'data' => array()))), 'display' => array('default' => array('fields' => 'locale+name'))));
             $this->fields['locale'] = new I2CE_FormField_MAP('locale', $options);
             $this->fields['locale']->setHeaders(array('default' => $header));
             $this->fields['locale']->setContainer($this);
             $locale = I2CE_Locales::ensureSelectableLocale($this->fields['locale']->getDBValue());
             $this->fields['locale']->setFromDB('locale|' . $locale);
             $this->user->locale = $locale;
         } else {
             $this->fields[$detail] = new I2CE_FormField_STRING_LINE($detail, array('in_db' => true, 'required' => I2CE_User::isRequired($detail)));
             $this->fields[$detail]->setHeaders(array('default' => I2CE_User::getDetailName($detail)));
             $this->fields[$detail]->setContainer($this);
         }
     }
     $this->fields['username'] = new I2CE_FormField_STRING_LINE('username', array('in_db' => true, 'required' => true));
     $this->fields['username']->setHeaders(array('default' => 'Username'));
     $this->fields['username']->setContainer($this);
 }