public function configure() { $widgets = array(); $validators = array(); if ($this->getOption('is_use_id')) { $widgets += array('id' => new sfWidgetFormInputText()); $validators += array('id' => new sfValidatorPass()); } $widgets += array('name' => new sfWidgetFormInputText()); $validators += array('name' => new opValidatorSearchQueryString(array('required' => false))); $culture = sfContext::getInstance()->getUser()->getCulture(); foreach ($this->getProfiles() as $profile) { $profileI18n = $profile->Translation[$culture]->toArray(); if ($profile->isPreset()) { $config = $profile->getPresetConfig(); $profileI18n['caption'] = sfContext::getInstance()->getI18n()->__($config['Caption']); } $profileWithI18n = $profile->toArray() + $profileI18n; $widget = opFormItemGenerator::generateSearchWidget($profileWithI18n, array('' => '') + $profile->getOptionsArray()); if ($widget) { $widgets[self::$profileFieldPrefix . $profile->getName()] = $widget; $validators[self::$profileFieldPrefix . $profile->getName()] = new sfValidatorPass(); } } $this->setWidgets($widgets); $this->setValidators($validators); $this->widgetSchema->setLabel('name', '%nickname%'); $this->widgetSchema->setNameFormat('member[%s]'); }
public function configure() { $widgets = array(); $validators = array(); // if ($this->getOption('is_use_id')) // { $widgets += array('id' => new sfWidgetFormInputText()); $validators += array('id' => new sfValidatorPass()); // } foreach ($this->getProfiles() as $profile) { if (ProfileTable::PUBLIC_FLAG_PRIVATE == $profile->default_public_flag && !$profile->is_edit_public_flag) { continue; } $profileI18n = $profile->Translation[$culture]->toArray(); if ($profile->isPreset()) { $config = $profile->getPresetConfig(); $profileI18n['caption'] = sfContext::getInstance()->getI18n()->__($config['Caption']); } $profileWithI18n = $profile->toArray() + $profileI18n; $widget = opFormItemGenerator::generateSearchWidget($profileWithI18n, array('' => '') + $profile->getOptionsArray()); if ($widget) { $widgets[self::$profileFieldPrefix . $profile->getName()] = $widget; $validators[self::$profileFieldPrefix . $profile->getName()] = new sfValidatorPass(); } } $this->setWidgets($widgets); $this->setValidators($validators); // $this->widgetSchema->setLabel('name', '%nickname%'); // $this->widgetSchema->setNameFormat('member[%s]'); }
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 filterMemberIdByProfile($ids, $column, $value, Profile $item, $publicFlag = 1) { $_result = array(); $q = Doctrine::getTable('MemberProfile')->createQuery('m'); $q = opFormItemGenerator::filterSearchQuery($q, 'm.' . $column, $value, $item->toArray())->select('m.member_id')->andWhere('m.profile_id = ?', $item->getId()); $isCheckPublicFlag = is_integer($publicFlag); if (!$item->getIsEditPublicFlag()) { if (ProfileTable::PUBLIC_FLAG_SNS == $item->getDefaultPublicFlag() || ProfileTable::PUBLIC_FLAG_WEB == $item->getDefaultPublicFlag()) { $isCheckPublicFlag = false; } else { return array(); } } if ($isCheckPublicFlag) { $publicFlags = (array) $publicFlag; if (1 == $publicFlag) { $publicFlags[] = 4; } if ($item->isMultipleSelect() && 'date' !== $item->getFormType()) { $q->addFrom('MemberProfile pm')->andWhere('m.tree_key = pm.id')->andWhereIn('pm.public_flag', $publicFlags); } else { $q->andWhereIn('m.public_flag', $publicFlags); } } $list = $q->execute(); foreach ($list as $v) { $_result[] = $v->getMemberId(); } if (is_array($ids)) { $ids = array_values(array_intersect($ids, $_result)); } else { $ids = array_values($_result); } if ($isCheckPublicFlag && 'op_preset_birthday' === $item->getName()) { if ('%-' !== substr($value, 0, 2)) { $ids = $this->filterMemberIdsByAgePublicFlag($ids); } } return $ids; }
public function filterMemberIdByProfile($ids, $column, $value, Profile $item, $publicFlag = 1) { $_result = array(); $q = Doctrine::getTable('MemberProfile')->createQuery('m'); $q = opFormItemGenerator::filterSearchQuery($q, 'm.' . $column, $value, $item->toArray())->select('m.member_id')->andWhere('m.profile_id = ?', $item->getId()); if (is_integer($publicFlag)) { if ($item->isMultipleSelect() && $item->getFormType() !== 'date') { $q->addFrom('MemberProfile pm')->andWhere('m.tree_key = pm.id')->andWhere('pm.public_flag <= ?', $publicFlag); } else { $q->andWhere('m.public_flag <= ?', $publicFlag); } } $list = $q->execute(); foreach ($list as $value) { $_result[] = $value->getMemberId(); } if (is_array($ids)) { $ids = array_values(array_intersect($ids, $_result)); } else { $ids = array_values($_result); } return $ids; }
protected function bindFields($data) { $event = new sfEvent(null, 'op_csv.import_filter_field'); sfContext::getInstance()->getEventDispatcher()->filter($event, $data); $fields = $event->getReturnValue(); foreach ($this->requireFields as $name) { $names = explode('|', $name); if (is_array($names)) { if (1 < count($name)) { $valid = false; foreach ($names as $name) { if (in_array($name, $fields)) { $valid = true; break; } } if (!$valid) { throw new RuntimeException(); } } elseif (1 === count($name)) { if (!in_array($names[0], $fields)) { throw new RuntimeException(); } } } } $clean = array(); foreach ($fields as $key => $field) { if (preg_match('/^profile\\[(.*)\\]$/', $field, $match)) { $object = Doctrine::getTable('Profile')->findOneByName($match[1]); if (!$object) { throw new RuntimeException('Unknown profile field.'); } if ($object->isMultipleSelect()) { throw new RuntimeException('Unsported profile item of date and checkbox.'); } $choices = array(); if ($object->isSingleSelect()) { $profileOptions = Doctrine::getTable('ProfileOption')->retrieveByProfileId($object->getId()); foreach ($profileOptions as $option) { $choices[] = $object->getId(); } } $validator = opFormItemGenerator::generateValidator($object->getValueType(), $choices); $clean[$key] = array('is_profile' => true, 'name' => $match[1], 'object' => $object, 'validator' => $validator); continue; } $clean[$key] = array('is_profile' => false, 'name' => $field); } $this->fields = $clean; }
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']); } }