protected function _init_()
 {
     $data = sfYaml::load(sfConfig::get('sf_lib_dir') . '/task/RandomData.yml');
     $this->series = SeriesTable::getChoicesForSelect();
     $this->letters = $data['letters'];
     $this->tags = $data['tags'];
     $this->items = $data['short_texts'];
     $this->terms = $data['long_texts'];
     $this->companies = $data['company_names'];
     $this->names = $data['names'];
     $this->lastnames = $data['lastnames'];
     $this->taxes = array();
     foreach ($q = Doctrine_Query::create()->from('Tax t')->execute() as $tax) {
         $this->taxes[] = $tax->getId();
     }
     $customers = array('name' => array(), 'email' => array(), 'id' => array(), 'company' => array());
     for ($i = 0; $i < mt_rand(20, 100); $i++) {
         $customers['id'][] = str_pad(mt_rand(11111, 99999) . mt_rand(11111, 99999), 10, '0', STR_PAD_LEFT) . $this->letters[array_rand($this->letters)];
         $name = $this->names[array_rand($this->names)] . " " . $this->lastnames[array_rand($this->lastnames)];
         $customers['name'][] = $name;
         $customers['email'][] = str_replace(' ', '_', strtolower($name)) . '@example.com';
         $customers['company'][] = $this->companies[array_rand($this->companies)];
     }
     $this->customers = $customers;
 }
示例#2
0
 public function configure()
 {
     $decorator = new myFormSchemaFormatter($this->getWidgetSchema());
     $this->widgetSchema->addFormFormatter('custom', $decorator);
     $this->widgetSchema->setFormFormatterName('custom');
     $common_fields = Doctrine::getTable(self::getModelName())->getColumnNames();
     $model_fields = Doctrine::getTable($this->getModelName())->getColumnNames();
     foreach (array_diff($common_fields, $model_fields) as $extra) {
         unset($this[$extra]);
     }
     $this->widgetSchema['customer_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['recurring_invoice_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['tags'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['type'] = new sfWidgetFormInputHidden(array(), array('value' => $this->getModelName()));
     $this->widgetSchema['series_id'] = new sfWidgetFormSelect(array('choices' => SeriesTable::getChoicesForSelect()));
     $this->widgetSchema['series_id']->setDefault(sfContext::getInstance()->getUser()->getProfile()->getSeries());
     $this->widgetSchema['invoicing_address'] = new sfWidgetFormTextarea();
     $this->widgetSchema['shipping_address'] = new sfWidgetFormTextarea();
     $this->widgetSchema['terms'] = new sfWidgetFormTextarea();
     $common_defaults = array('customer_name' => 'Client Name', 'customer_identification' => 'Client Legal Id', 'contact_person' => 'Contact Person', 'invoicing_address' => 'Invoicing Address', 'shipping_address' => 'Shipping Address', 'customer_email' => 'Client Email Address');
     $this->widgetSchema->setHelps(array_merge($this->widgetSchema->getHelps(), $common_defaults));
     $this->setDefault('tags', implode(',', $this->object->getTags()));
     $this->setDefault('terms', PropertyTable::get('legal_terms'));
     // validators
     $this->validatorSchema['tags'] = new sfValidatorString(array('required' => false));
     $this->validatorSchema['customer_email'] = new sfValidatorEmail(array('max_length' => 100, 'required' => false), array('invalid' => 'Invalid client email address'));
     $this->validatorSchema['customer_name'] = new sfValidatorString(array('required' => true));
     $this->validatorSchema['series_id'] = new sfValidatorString(array('required' => true), array('required' => 'The invoice serie is mandatory'));
     $iforms = array();
     foreach ($this->object->getItems() as $item) {
         $iforms[$item->id] = new ItemForm($item);
     }
     $itemForms = new FormsContainer($iforms, 'ItemForm');
     $this->embedForm('Items', $itemForms);
 }
示例#3
0
 public function configure()
 {
     $user = $this->getOption('user');
     $this->widgetSchema['sf_guard_user_id'] = new sfWidgetFormInputHidden();
     $this->widgetSchema['language'] = new sfWidgetFormI18nChoiceLanguage(array('culture' => $user->getLanguage(), 'languages' => CultureTools::getAvailableLanguages()));
     $this->widgetSchema['country'] = new sfWidgetFormI18nChoiceCountry(array('add_empty' => true, 'culture' => $user->getLanguage(), 'countries' => CultureTools::getCountriesForLanguage($this->getOption('language'))));
     $this->widgetSchema['search_filter'] = new sfWidgetFormSelect(array('choices' => InvoiceSearchForm::getQuickDates()));
     $this->widgetSchema['series'] = new sfWidgetFormSelect(array('choices' => SeriesTable::getChoicesForSelect()));
     $this->widgetSchema['old_password'] = new sfWidgetFormInputPassword();
     $this->widgetSchema['new_password'] = new sfWidgetFormInputPassword();
     $this->widgetSchema['new_password2'] = new sfWidgetFormInputPassword();
     $this->validatorSchema['sf_guard_user_id'] = new sfValidatorAnd(array(new sfValidatorDoctrineChoice(array('model' => 'sfGuardUser', 'required' => true), array('invalid' => "The user does not exist!")), new CompareValueValidator(array('value' => $user->getGuardUser()->getId()))));
     $this->validatorSchema['language'] = new sfValidatorI18nChoiceLanguage(array('required' => true));
     $this->validatorSchema['country'] = new sfValidatorI18nChoiceCountry(array('required' => false));
     $this->validatorSchema['series'] = new sfValidatorDoctrineChoice(array('model' => 'Series'), array('required' => 'The default invoicing series is mandatory'));
     $this->validatorSchema['search_filter'] = new sfValidatorChoice(array('required' => false, 'choices' => array_keys(InvoiceSearchForm::getQuickDates())));
     $this->validatorSchema['email'] = new sfValidatorEmail(array('max_length' => 100, 'required' => true));
     $this->validatorSchema['old_password'] = new sfValidatorPass();
     $vdPassword = new sfValidatorCallback(array('callback' => array($this, 'checkPassword')), array('invalid' => 'Wrong password', 'required' => 'Old password required'));
     $passwd_min_length = sfConfig::get('app_password_min_length', 4);
     $this->validatorSchema['new_password'] = new sfValidatorPass();
     $vdNewPassword = new sfValidatorString(array('min_length' => 1, 'required' => false), array('min_length' => 'Password length must be ' . "greater than {$passwd_min_length}"));
     $this->validatorSchema['new_password2'] = new sfValidatorPass();
     $vd = new sfValidatorSchema(array('old_password' => $vdPassword, 'new_password' => $vdNewPassword, 'new_password2' => new sfValidatorPass()));
     $vd->setPostValidator(new sfValidatorSchemaCompare('new_password', '==', 'new_password2', array(), array('invalid' => "Passwords don't match")));
     $this->validatorSchema->setPostValidator(new SiwappConditionalValidator(array('control_field' => 'new_password', 'validator_schema' => $vd, 'callback' => array('Tools', 'checkLength'))));
     $this->widgetSchema->setLabels(array('nb_display_results' => 'Results to display in listings', 'language' => 'Interface language', 'series' => 'Default invoicing series', 'old_password' => 'Old password', 'new_password' => 'New password', 'new_password2' => 'New password (confirmation)', 'first_name' => 'First Name', 'last_name' => 'Last Name'));
     $this->setDefaults(array('nb_display_results' => 10, 'language' => $user->getLanguage(), 'country' => $user->getCountry()));
     $this->widgetSchema->setNameFormat('config[%s]');
 }
 public function configure()
 {
     $this->setWidgets(array('query' => new sfWidgetFormInputText(), 'series_id' => new sfWidgetFormChoice(array('choices' => array('' => '') + SeriesTable::getChoicesForSelect(false))), 'period_type' => new sfWidgetFormChoice(array('choices' => array('' => '') + RecurringInvoiceTable::$period_types)), 'tags' => new sfWidgetFormInputHidden(), 'status' => new sfWidgetFormInputHidden()));
     $this->widgetSchema->setLabels(array('query' => 'Search', 'series' => 'Series'));
     $dateRangeValidatorOptions = array('required' => false);
     $this->setValidators(array('query' => new sfValidatorString(array('required' => false, 'trim' => true)), 'series' => new sfValidatorString(array('required' => false, 'trim' => true)), 'tags' => new sfValidatorString(array('required' => false, 'trim' => true)), 'status' => new sfValidatorString(array('required' => false, 'trim' => true))));
     $this->widgetSchema->setNameFormat('search[%s]');
     $this->widgetSchema->setFormFormatterName('list');
 }
 public function configure()
 {
     $startYear = sfConfig::get('app_year_range_start', date('Y') - 5);
     $years = range($startYear, date('Y') + 5);
     $sfWidgetFormI18nJQueryDateOptions = array('culture' => $this->getOption('culture', 'en'), 'image' => image_path('icons/calendar.png'), 'config' => "{ duration: '' }", 'years' => array_combine($years, $years));
     $this->setWidgets(array('query' => new sfWidgetFormInputText(), 'from' => new sfWidgetFormI18nJQueryDate($sfWidgetFormI18nJQueryDateOptions), 'to' => new sfWidgetFormI18nJQueryDate($sfWidgetFormI18nJQueryDateOptions), 'quick_dates' => new sfWidgetFormChoice(array('choices' => InvoiceSearchForm::getQuickDates())), 'series_id' => new sfWidgetFormChoice(array('choices' => array('' => '') + SeriesTable::getChoicesForSelect(false))), 'customer_id' => new sfWidgetFormChoice(array('choices' => array())), 'tags' => new sfWidgetFormInputHidden(), 'status' => new sfWidgetFormInputHidden(), 'sent' => new sfWidgetFormChoice(array('choices' => array('' => '', 1 => 'yes', 0 => 'no')))));
     $this->widgetSchema->setLabels(array('query' => 'Search', 'from' => 'from', 'to' => 'to', 'quick_dates' => ' ', 'series_id' => 'Series', 'customer_id' => 'Customer', 'sent' => 'Sent'));
     $dateRangeValidatorOptions = array('required' => false);
     $this->setValidators(array('query' => new sfValidatorString(array('required' => false, 'trim' => true)), 'from' => new sfValidatorDate($dateRangeValidatorOptions), 'to' => new sfValidatorDate($dateRangeValidatorOptions), 'customer_id' => new sfValidatorString(array('required' => false, 'trim' => true)), 'tags' => new sfValidatorString(array('required' => false, 'trim' => true)), 'status' => new sfValidatorString(array('required' => false, 'trim' => true))));
     // autocomplete for customer
     $this->widgetSchema['customer_id']->setOption('renderer_class', 'sfWidgetFormJQueryAutocompleter');
     $this->widgetSchema['customer_id']->setOption('renderer_options', array('url' => url_for('search/ajaxCustomerAutocomplete'), 'value_callback' => 'CustomerTable::getCustomerName'));
     $this->widgetSchema->setNameFormat('search[%s]');
     $this->widgetSchema->setFormFormatterName('list');
 }