/** * Test different data sources */ public function testSources() { // Array $items = array('a' => 'Apple', 'b' => 'Banana', 'c' => 'Cranberry'); $field = new CheckboxSetField('Field', null, $items); $this->assertEquals($items, $field->getSource()); // SS_List $list = new ArrayList(array(new ArrayData(array('ID' => 'a', 'Title' => 'Apple')), new ArrayData(array('ID' => 'b', 'Title' => 'Banana')), new ArrayData(array('ID' => 'c', 'Title' => 'Cranberry')))); $field2 = new CheckboxSetField('Field', null, $list); $this->assertEquals($items, $field2->getSource()); $field3 = new CheckboxSetField('Field', null, $list->map()); $this->assertEquals($items, $field3->getSource()); }
/** * Returns the print URL for the given DataObject * (silvercart-print/$DataObjectName/$DataObjectID) * * @param ArrayList $dataObjectList ArrayList to get print URL for * * @return string */ public static function getPrintURLForMany($dataObjectList) { $printURL = ''; if ($dataObjectList instanceof SS_List) { $dataObject = $dataObjectList->first(); if ($dataObject instanceof DataObject) { $map = $dataObjectList->map('ID', 'ID'); if ($map instanceof SS_Map) { $map = $map->toArray(); } $printURL = sprintf('silvercart-print-many/%s/%s', $dataObject->ClassName, implode('-', $map)); } } return $printURL; }
public function getTeamsDLL($id = 'add_member_team') { $current_member = Member::currentUser(); if (!$current_member) { return false; } $company = $current_member->getManagedCCLACompany(); if (!$company) { return false; } $res = $this->team_repository->getByCompany($company->getIdentifier()); $res = new ArrayList($res); $ddl = new DropdownField($id, null, $res->map("ID", "Name")); $ddl->setEmptyString('-- Select a Team --'); return $ddl; }
/** * Get a member SQLMap of members in specific groups * * If no $groups is passed, all members will be returned * * @param mixed $groups - takes a SS_List, an array or a single Group.ID * @return SQLMap Returns an SQLMap that returns all Member data. * @see map() */ public static function map_in_groups($groups = null) { $groupIDList = array(); if ($groups instanceof SS_List) { foreach ($groups as $group) { $groupIDList[] = $group->ID; } } elseif (is_array($groups)) { $groupIDList = $groups; } elseif ($groups) { $groupIDList[] = $groups; } // No groups, return all Members if (!$groupIDList) { return Member::get()->sort(array('Surname' => 'ASC', 'FirstName' => 'ASC'))->map(); } $membersList = new ArrayList(); // This is a bit ineffective, but follow the ORM style foreach (Group::get()->byIDs($groupIDList) as $group) { $membersList->merge($group->Members()); } $membersList->removeDuplicates('ID'); return $membersList->map(); }
public function testMap() { $list = new ArrayList(array(array('ID' => 1, 'Name' => 'Steve'), (object) array('ID' => 3, 'Name' => 'Bob'), array('ID' => 5, 'Name' => 'John'))); $this->assertEquals($list->map('ID', 'Name'), array(1 => 'Steve', 3 => 'Bob', 5 => 'John')); }
/** * @return FieldList */ public function getCMSFields() { // Determine optional field values $form = $this->getFormParent(); // predefined choices are also candidates $multiOptionFields = EditableMultipleOptionField::get()->filter('ParentID', $form->ID); // if they have email fields then we could send from it $validEmailFromFields = EditableEmailField::get()->filter('ParentID', $form->ID); // For the subject, only one-line entry boxes make sense $validSubjectFields = EditableTextField::get()->filter('ParentID', $form->ID)->filterByCallback(function ($item, $list) { return (int) $item->getSetting('Rows') === 1; }); $validSubjectFields->merge($multiOptionFields); // To address can only be email fields or multi option fields $validEmailToFields = new ArrayList($validEmailFromFields->toArray()); $validEmailToFields->merge($multiOptionFields); // Build fieldlist $fields = FieldList::create(Tabset::create('Root')->addExtraClass('EmailRecipientForm')); // Configuration fields $fields->addFieldsToTab('Root.EmailDetails', array(FieldGroup::create(TextField::create('EmailSubject', _t('UserDefinedForm.TYPESUBJECT', 'Type subject'))->setAttribute('style', 'min-width: 400px;'), DropdownField::create('SendEmailSubjectFieldID', _t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '.. or select a field to use as the subject'), $validSubjectFields->map('ID', 'Title'))->setEmptyString(''))->setTitle(_t('UserDefinedForm.EMAILSUBJECT', 'Email subject')), FieldGroup::create(TextField::create('EmailAddress', _t('UserDefinedForm.TYPETO', 'Type to address'))->setAttribute('style', 'min-width: 400px;'), DropdownField::create('SendEmailToFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'), $validEmailToFields->map('ID', 'Title'))->setEmptyString(' '))->setTitle(_t('UserDefinedForm.SENDEMAILTO', 'Send email to'))->setDescription(_t('UserDefinedForm.SENDEMAILTO_DESCRIPTION', 'You may enter multiple email addresses as a comma separated list.')), TextField::create('EmailFrom', _t('UserDefinedForm.FROMADDRESS', 'Send email from'))->setDescription(_t('UserDefinedForm.EmailFromContent', "The from address allows you to set who the email comes from. On most servers this " . "will need to be set to an email address on the same domain name as your site. " . "For example on yoursite.com the from address may need to be something@yoursite.com. " . "You can however, set any email address you wish as the reply to address.")), FieldGroup::create(TextField::create('EmailReplyTo', _t('UserDefinedForm.TYPEREPLY', 'Type reply address'))->setAttribute('style', 'min-width: 400px;'), DropdownField::create('SendEmailFromFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'), $validEmailFromFields->map('ID', 'Title'))->setEmptyString(' '))->setTitle(_t('UserDefinedForm.REPLYADDRESS', 'Email for reply to'))->setDescription(_t('UserDefinedForm.REPLYADDRESS_DESCRIPTION', 'The email address which the recipient is able to \'reply\' to.')))); // Only show the preview link if the recipient has been saved. if (!empty($this->EmailTemplate)) { $preview = sprintf('<p><a href="%s" target="_blank" class="ss-ui-button">%s</a></p><em>%s</em>', "admin/pages/edit/EditForm/field/EmailRecipients/item/{$this->ID}/preview", _t('UserDefinedForm.PREVIEW_EMAIL', 'Preview email'), _t('UserDefinedForm.PREVIEW_EMAIL_DESCRIPTION', 'Note: Unsaved changes will not appear in the preview.')); } else { $preview = sprintf('<em>%s</em>', _t('UserDefinedForm.PREVIEW_EMAIL_UNAVAILABLE', 'You can preview this email once you have saved the Recipient.')); } // Email templates $fields->addFieldsToTab('Root.EmailContent', array(new CheckboxField('HideFormData', _t('UserDefinedForm.HIDEFORMDATA', 'Hide form data from email?')), new CheckboxField('SendPlain', _t('UserDefinedForm.SENDPLAIN', 'Send email as plain text? (HTML will be stripped)')), new DropdownField('EmailTemplate', _t('UserDefinedForm.EMAILTEMPLATE', 'Email template'), $this->getEmailTemplateDropdownValues()), new HTMLEditorField('EmailBodyHtml', _t('UserDefinedForm.EMAILBODYHTML', 'Body')), new TextareaField('EmailBody', _t('UserDefinedForm.EMAILBODY', 'Body')), new LiteralField('EmailPreview', '<div id="EmailPreview">' . $preview . '</div>'))); // Custom rules for sending this field $grid = new GridField("CustomRules", _t('EditableFormField.CUSTOMRULES', 'Custom Rules'), $this->CustomRules(), $this->getRulesConfig()); $grid->setDescription(_t('UserDefinedForm.RulesDescription', 'Emails will only be sent to the recipient if the custom rules are met. If no rules are defined, this receipient will receive notifications for every submission.')); $fields->addFieldsToTab('Root.CustomRules', array(new DropdownField('CustomRulesCondition', _t('UserDefinedForm.SENDIF', 'Send condition'), array('Or' => 'Any conditions are true', 'And' => 'All conditions are true')), $grid)); $this->extend('updateCMSFields', $fields); return $fields; }
/** * Find an identical item in the order/cart, item is identical if the * productID, version and the options for the item are the same. Used to increase * quantity of items that already exist in the cart/Order. * * @see Order::addItem() * @param DatObject $product * @param ArrayList $options * @return DataObject */ public function findIdenticalItem($product, $variation, ArrayList $options) { $items = $this->Items(); $filtered = $items->filter(array('ProductID' => $product->ID, 'ProductVersion' => $product->Version)); if ($variation && $variation->exists()) { $filtered = $filtered->filter(array('VariationID' => $variation->ID, 'VariationVersion' => $variation->Version)); } //Could have many products of same variation at this point, need to check product options carefully $optionsMap = $options->map('Description', 'Price'); $existingItems = clone $filtered; foreach ($existingItems as $existingItem) { $existingOptionsMap = $existingItem->ItemOptions()->map('Description', 'Price')->toArray(); if ($optionsMap != $existingOptionsMap) { $filtered = $filtered->exclude('ID', $existingItem->ID); } } return $filtered->first(); }
/** * @return FieldList */ public function getCMSFields() { $fields = new FieldList(new TextField('EmailSubject', _t('UserDefinedForm.EMAILSUBJECT', 'Email subject')), new LiteralField('EmailFromContent', '<p>' . _t('UserDefinedForm.EmailFromContent', "The from address allows you to set who the email comes from. On most servers this " . "will need to be set to an email address on the same domain name as your site. " . "For example on yoursite.com the from address may need to be something@yoursite.com. " . "You can however, set any email address you wish as the reply to address.") . "</p>"), new TextField('EmailFrom', _t('UserDefinedForm.FROMADDRESS', 'Send email from')), new TextField('EmailReplyTo', _t('UserDefinedForm.REPLYADDRESS', 'Email for reply to')), new TextField('EmailAddress', _t('UserDefinedForm.SENDEMAILTO', 'Send email to')), new CheckboxField('HideFormData', _t('UserDefinedForm.HIDEFORMDATA', 'Hide form data from email?')), new CheckboxField('SendPlain', _t('UserDefinedForm.SENDPLAIN', 'Send email as plain text? (HTML will be stripped)')), new TextareaField('EmailBody', _t('UserDefinedForm.EMAILBODY', 'Body'))); $formID = $this->FormID != 0 ? $this->FormID : Session::get('CMSMain.currentPage'); $dropdowns = array(); // if they have email fields then we could send from it $validEmailFields = EditableEmailField::get()->filter('ParentID', (int) $formID); // for the subject, only one-line entry boxes make sense $validSubjectFields = EditableTextField::get()->filter('ParentID', (int) $formID)->filterByCallback(function ($item, $list) { return (int) $item->getSetting('Rows') === 1; }); // predefined choices are also candidates $multiOptionFields = EditableMultipleOptionField::get()->filter('ParentID', (int) $formID); $fields->insertAfter($dropdowns[] = new DropdownField('SendEmailFromFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASFROM', '.. or select a field to use as reply to address'), $validEmailFields->map('ID', 'Title')), 'EmailReplyTo'); $validEmailFields = new ArrayList($validEmailFields->toArray()); $validEmailFields->merge($multiOptionFields); $validSubjectFields->merge($multiOptionFields); $fields->insertAfter($dropdowns[] = new DropdownField('SendEmailToFieldID', _t('UserDefinedForm.ORSELECTAFIELDTOUSEASTO', '.. or select a field to use as the to address'), $validEmailFields->map('ID', 'Title')), 'EmailAddress'); $fields->insertAfter($dropdowns[] = new DropdownField('SendEmailSubjectFieldID', _t('UserDefinedForm.SELECTAFIELDTOSETSUBJECT', '.. or select a field to use as the subject'), $validSubjectFields->map('ID', 'Title')), 'EmailSubject'); foreach ($dropdowns as $dropdown) { $dropdown->setHasEmptyDefault(true); $dropdown->setEmptyString(" "); } $this->extend('updateCMSFields', $fields); return $fields; }
public function testMap() { $list = new ArrayList(array(array('ID' => 1, 'Name' => 'Steve'), (object) array('ID' => 3, 'Name' => 'Bob'), array('ID' => 5, 'Name' => 'John'))); $map = $list->map('ID', 'Name'); // Items added after calling map should not be included retroactively $list->add(array('ID' => 7, 'Name' => 'Andrew')); $this->assertInstanceOf('SS_Map', $map); $this->assertEquals(array(1 => 'Steve', 3 => 'Bob', 5 => 'John'), $map->toArray()); }