public function configure()
 {
     $snsConfig = sfConfig::get('openpne_sns_config');
     $category = sfConfig::get('openpne_sns_category');
     if (empty($category[$this->getOption('category')])) {
         return false;
     }
     foreach ($category[$this->getOption('category')] as $configName) {
         if (empty($snsConfig[$configName])) {
             continue;
         }
         $this->setWidget($configName, opFormItemGenerator::generateWidget($snsConfig[$configName]));
         $this->setValidator($configName, opFormItemGenerator::generateValidator($snsConfig[$configName]));
         $this->widgetSchema->setLabel($configName, $snsConfig[$configName]['Caption']);
         if (isset($snsConfig[$configName]['Help'])) {
             $this->widgetSchema->setHelp($configName, $snsConfig[$configName]['Help']);
         }
         $value = opConfig::get($configName);
         if ($value instanceof sfOutputEscaperArrayDecorator) {
             $value = $value->getRawValue();
         }
         $this->setDefault($configName, $value);
     }
     $this->widgetSchema->setNameFormat('sns_config[%s]');
 }
 public function setConfigWidget($name)
 {
     $config = $this->configSettings[$name];
     $this->widgetSchema[$name] = opFormItemGenerator::generateWidget($config);
     $this->widgetSchema->setLabel($name, $config['Caption']);
     $communityConfig = Doctrine::getTable('CommunityConfig')->retrieveByNameAndCommunityId($name, $this->community->getId());
     if ($communityConfig) {
         $this->setDefault($name, $communityConfig->getValue());
     }
     $this->validatorSchema[$name] = opFormItemGenerator::generateValidator($config);
 }
 public function setup()
 {
     foreach (sfConfig::get('app_inquiry_form_widgets') as $key => $value) {
         $obj = opFormItemGenerator::generateWidget($value);
         $this->setWidget($key, $obj);
         $this->setValidator($key, opFormItemGenerator::generateValidator($value));
         $this->widgetSchema->setLabel($key, $value['Caption']);
         $this->widgetSchema->setHelp($key, $value['Help']);
     }
     $this->widgetSchema->setNameFormat('inquiry[%s]');
 }
 public function setup()
 {
     foreach ($this->adapter->getAuthConfigSettings() as $key => $value) {
         if (isset($value['IsConfig']) && !$value['IsConfig']) {
             continue;
         }
         $obj = opFormItemGenerator::generateWidget($value);
         $this->setWidget($key, $obj);
         $this->setValidator($key, opFormItemGenerator::generateValidator($value));
     }
     $this->widgetSchema->setNameFormat('auth' . $this->adapter->getAuthModeName() . '[%s]');
 }
 protected function setConfigWidget()
 {
     sfContext::getInstance()->getConfiguration()->loadHelpers(array('Escaping'));
     $application = $this->memberApplication->getApplication();
     $settings = $application->getSettings();
     foreach ($settings as $key => $setting) {
         $param = array();
         $choices = array();
         $validatorBool = new sfValidatorBoolean();
         $param['IsRequired'] = $validatorBool->clean($setting['required']);
         $param['Caption'] = sfOutputEscaper::escape(sfConfig::get('sf_escaping_method'), $setting['displayName']);
         if (empty($setting['datatype']) || $setting['datatype'] == 'HIDDEN') {
             continue;
         }
         switch ($setting['datatype']) {
             case 'BOOL':
                 $param['FormType'] = 'radio';
                 $choices = array('1' => 'Yes', '0' => 'No');
                 break;
             case 'ENUM':
                 $param['FormType'] = 'select';
                 $enumValues = array();
                 if (!is_array($setting['enumValues'])) {
                     continue;
                 }
                 foreach ($setting['enumValues'] as $value) {
                     $enumValues[$value['value']] = $value['displayValue'];
                 }
                 $choices = $enumValues;
                 break;
             default:
                 $param['FormType'] = 'input';
                 $param['ValueType'] = '';
         }
         $this->widgetSchema[$key] = opFormItemGenerator::generateWidget($param, $choices);
         $this->validatorSchema[$key] = opFormItemGenerator::generateValidator($param, array_keys($choices));
         if ($setting['defaultValue']) {
             $this->setDefault($key, $setting['defaultValue']);
         }
     }
     $userSettings = $this->memberApplication->getUserSettings();
     foreach ($userSettings as $name => $value) {
         if (!empty($value)) {
             $this->setDefault($name, $value);
         }
     }
 }
 protected function setConfigWidget()
 {
     $application = $this->memberApplication->getApplication();
     $settings = $application->getSettings();
     foreach ($settings as $key => $setting) {
         $param = array();
         $choices = array();
         $param['IsRequired'] = false;
         $param['Caption'] = $setting['displayName'];
         if (empty($setting['datatype']) || $setting['datatype'] == 'HIDDEN') {
             continue;
         }
         switch ($setting['datatype']) {
             case 'BOOL':
                 $param['FormType'] = 'checkbox';
                 $choices = array('1' => '');
                 break;
             case 'ENUM':
                 $param['FormType'] = 'select';
                 $enumValues = array();
                 if (!is_array($setting['enumValues'])) {
                     continue;
                 }
                 foreach ($setting['enumValues'] as $value) {
                     $enumValues[$value['value']] = $value['displayValue'];
                 }
                 $choices = $enumValues;
                 break;
             default:
                 $param['FormType'] = 'input';
                 $param['ValueType'] = '';
         }
         $this->widgetSchema[$key] = opFormItemGenerator::generateWidget($param, $choices);
         $this->validatorSchema[$key] = opFormItemGenerator::generateValidator($param, array_keys($choices));
         if ($setting['defaultValue']) {
             $this->setDefault($key, $setting['defaultValue']);
         }
     }
     $userSettings = $this->memberApplication->getUserSettings();
     foreach ($userSettings as $name => $value) {
         if (!empty($value)) {
             $this->setDefault($name, $value);
         }
     }
 }
 public function __construct(Gadget $gadget, $options = array(), $CSRFSecret = null)
 {
     $this->gadget = $gadget;
     parent::__construct(array(), $options, $CSRFSecret);
     $config = Doctrine::getTable('Gadget')->getGadgetConfigListByType($options['type']);
     if (empty($config[$gadget->getName()]['config'])) {
         throw new RuntimeException('The gadget has not registered or it doesn\'t have any configuration items.');
     }
     $gadgetConfig = $config[$gadget->getName()]['config'];
     foreach ($gadgetConfig as $key => $value) {
         $this->setWidget($key, opFormItemGenerator::generateWidget($value));
         $this->setValidator($key, opFormItemGenerator::generateValidator($value));
         $config = Doctrine::getTable('GadgetConfig')->retrieveByGadgetIdAndName($gadget->getId(), $key);
         if ($config) {
             $this->setDefault($key, $config->getValue());
         }
     }
     $this->widgetSchema->setNameFormat('gadget_config[%s]');
 }
 public function setMemberConfigWidget($name)
 {
     $config = $this->memberConfigSettings[$name];
     $this->widgetSchema[$name] = opFormItemGenerator::generateWidget($config);
     $this->widgetSchema->setLabel($name, $config['Caption']);
     $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($name, $this->member->getId());
     if ($memberConfig) {
         $this->setDefault($name, $memberConfig->getValue());
     }
     $this->validatorSchema[$name] = opFormItemGenerator::generateValidator($config);
     if (!empty($config['IsConfirm'])) {
         $this->validatorSchema[$name . '_confirm'] = $this->validatorSchema[$name];
         $this->widgetSchema[$name . '_confirm'] = $this->widgetSchema[$name];
         $this->widgetSchema->setLabel($name . '_confirm', $config['Caption'] . ' (Confirm)');
         $this->mergePostValidator(new sfValidatorSchemaCompare($name, '==', $name . '_confirm'));
     }
     if (!empty($config['IsUnique'])) {
         $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'isUnique'), 'arguments' => array('name' => $name))));
     }
     if (!empty($config['Info'])) {
         $this->widgetSchema->setHelp($name, $config['Info']);
     }
 }
 protected function setProfileWidgets($profiles)
 {
     $presetList = opToolkit::getPresetProfileList();
     foreach ($profiles as $profile) {
         $profileI18n = $profile->Translation[sfContext::getInstance()->getUser()->getCulture()]->toArray();
         $profileWithI18n = $profile->toArray() + $profileI18n;
         $widgetOptions = array('widget' => opFormItemGenerator::generateWidget($profileWithI18n, $this->getFormOptionsValue($profile->getId())));
         $validatorOptions = array('validator' => opFormItemGenerator::generateValidator($profileWithI18n, $this->getFormOptions($profile->getId())));
         if ($profile->getIsEditPublicFlag()) {
             $widgetOptions['is_edit_public_flag'] = $validatorOptions['is_edit_public_flag'] = true;
             if (!$this->getDefault($profile->getName())) {
                 $this->setDefault($profile->getName(), array('public_flag' => $profile->getDefaultPublicFlag()));
             }
         }
         $this->widgetSchema[$profile->getName()] = new opWidgetFormProfile($widgetOptions);
         $this->validatorSchema[$profile->getName()] = new opValidatorProfile($validatorOptions);
         $this->widgetSchema[$profile->getName()]->profile = $profile;
         $this->validatorSchema[$profile->getName()]->profile = $profile;
         $this->widgetSchema->setHelp($profile->getName(), $profileWithI18n['info']);
         if ($profile->isPreset()) {
             $this->widgetSchema->setLabel($profile->getName(), $presetList[$profile->getRawPresetName()]['Caption']);
             if ('op_preset_self_introduction' === $profile->getName()) {
                 $this->widgetSchema->setHelp($profile->getName(), 'This Profile supported markdown format');
             }
         }
     }
 }
 protected function setProfileWidgets($profiles)
 {
     $presetList = opToolkit::getPresetProfileList();
     foreach ($profiles as $profile) {
         if ('mobile_frontend' === sfConfig::get('sf_app')) {
             if ('op_preset_country' === $profile->getName() || 'op_preset_region' === $profile->getName()) {
                 continue;
             }
         }
         $profileI18n = $profile->Translation[sfContext::getInstance()->getUser()->getCulture()]->toArray();
         $profileWithI18n = $profile->toArray() + $profileI18n;
         $widgetOptions = array('widget' => opFormItemGenerator::generateWidget($profileWithI18n, $this->getFormOptionsValue($profile->getId())));
         $validatorOptions = array('validator' => opFormItemGenerator::generateValidator($profileWithI18n, $this->getFormOptions($profile->getId())));
         if ($profile->getIsEditPublicFlag()) {
             $widgetOptions['is_edit_public_flag'] = $validatorOptions['is_edit_public_flag'] = true;
             if (!$this->getDefault($profile->getName())) {
                 $this->setDefault($profile->getName(), array('public_flag' => $profile->getDefaultPublicFlag()));
             }
         }
         $this->widgetSchema[$profile->getName()] = new opWidgetFormProfile($widgetOptions);
         $this->validatorSchema[$profile->getName()] = new opValidatorProfile($validatorOptions);
         $this->widgetSchema[$profile->getName()]->profile = $profile;
         $this->validatorSchema[$profile->getName()]->profile = $profile;
         $this->widgetSchema->setHelp($profile->getName(), $profileWithI18n['info']);
         if ($profile->isPreset()) {
             $this->widgetSchema->setLabel($profile->getName(), $presetList[$profile->getRawPresetName()]['Caption']);
             if ('op_preset_birthday' === $profile->getName()) {
                 $this->widgetSchema->setHelp($profile->getName(), 'The public_flag for your age can be configure at "Settings" page.');
             }
         }
     }
 }
 public function setMemberConfigWidget($name)
 {
     $config = $this->memberConfigSettings[$name];
     $this->widgetSchema[$name] = opFormItemGenerator::generateWidget($config);
     $this->widgetSchema->setLabel($name, $config['Caption']);
     $memberConfig = Doctrine::getTable('MemberConfig')->retrieveByNameAndMemberId($name, $this->member->getId());
     if ($memberConfig) {
         $this->setDefault($name, $memberConfig->getValue());
     }
     $this->validatorSchema[$name] = opFormItemGenerator::generateValidator($config);
     if (!empty($config['IsUnique'])) {
         $uniqueValidator = new sfValidatorCallback(array('callback' => array($this, 'isUnique'), 'arguments' => array('name' => $name), 'empty_value' => $this->validatorSchema[$name]->getOption('empty_value')));
         $this->validatorSchema[$name] = new sfValidatorAnd(array($this->validatorSchema[$name], $uniqueValidator), array('required' => $this->validatorSchema[$name]->getOption('required'), 'empty_value' => $this->validatorSchema[$name]->getOption('empty_value'), 'halt_on_error' => true));
     }
     if (!empty($config['IsConfirm'])) {
         $this->validatorSchema[$name . '_confirm'] = $this->validatorSchema[$name];
         $this->widgetSchema[$name . '_confirm'] = $this->widgetSchema[$name];
         $this->widgetSchema->setLabel($name . '_confirm', $config['Caption'] . ' (Confirm)');
         $this->mergePreValidator(new sfValidatorCallback(array('callback' => array($this, 'preValidateConfirmField'), 'arguments' => array('name' => $name))));
         $this->mergePostValidator(new sfValidatorCallback(array('callback' => array($this, 'postValidateConfirmField'), 'arguments' => array('name' => $name, 'validator' => $this->validatorSchema[$name]))));
     }
     if (!empty($config['Info'])) {
         $this->widgetSchema->setHelp($name, $config['Info']);
     }
 }