Skip to content

Commit

Permalink
Added fields for SS module score and updated custom fields hook/funct…
Browse files Browse the repository at this point in the history
…ion.
  • Loading branch information
mediabeastnz committed Jan 26, 2017
1 parent d1d8752 commit f7c3f39
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/docs export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/composer.json export-ignore
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Version 1.2.0
Added new feature to add custom fields and change field type via cms.
# Version 1.1.0
Up'd Userforms module requirements
# Version 1.0.0
Initial release of module.
Empty file added CONTRIBUTING.md
Empty file.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2017 Myles Derham

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Via composer
```
composer require mediabeast/campaign-monitor-userform
```
#####Configuration
##### Configuration
To connect to your campaign monitor field you will need to set two fields in your config.yml.
```
EditableCampaignMonitorField:
Expand All @@ -16,22 +16,28 @@ EditableCampaignMonitorField:
```
^ These setting can be found in client settings area in Campaign Monitor.

#####Customisation
##### Customisation
You can also change what type of field is actually used on the UserForm.
By Default it's a checkbox field. You can change this via your config.yml.
If you choose to use a dropwdown field you can add options under the Custom Options tab.
By Default it's a checkbox field. You can change this via your config.yml OR via the CMS per form.
If you choose to use a DropdownField you can add options under the Custom Options tab.
```
EditableCampaignMonitorField:
defaultFieldType: 'DropdownField'
```
There are currently 3 extension hooks which can be useful to handle data before and after saving.
```

##### Adding Custom Fields
You can integrate your campaigns custom fields with the fields on your form.
To do so you must name the field(s) with the prefix 'customfields_', so for example if your custom field was
called `interests` then the field name on your form must be named `customfield_interests`.
The module will automatically push all fields to Campaign Monitor if there's a match.
Note: there are a few caveats here e.g. you have to ensure if a field is required then it needs to be required at both ends.

##### Extensions
There are a few extension hooks which can be useful to handle data before and after saving throughout the process.
+ `$this->extend('beforeValueFromData', $data)`
+ `$this->extend('afterValueFromData', $data)`
+ `$this->extend('updateLists', $data)`

#### TODO
+ ~~add extension points e.g. Custom fields, change field type~~
+ ~~Added supoport for submission data e.g. Submission shows user was subscribed.~~
+ Better error message is something goes wrong

+ `$this->extend('updateLists', $data)`
+ `$this->extend('updateCustomFields', $custom_fields)`


![field configuration example](http://i.imgur.com/3mBgSRq.png)
26 changes: 25 additions & 1 deletion code/extensions/EditableCampaignMonitorField.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ public function getValueFromData($data)
$auth = array(null, 'api_key' => $this->config()->get('api_key'));
$wrap = new CS_REST_Subscribers($this->owner->getField('ListID'), $auth);

$custom_fields = $this->extend('addCustomFields', $data);
$custom_fields = $this->addCustomFields($data);
if (empty($custom_fields)) { $custom_fields = array(); }

$dataToSend = array(
'EmailAddress' => $data[$this->owner->getField('EmailField')],
Expand Down Expand Up @@ -233,4 +234,27 @@ public function getLists()

return new ArrayList($cLists);
}

/**
* @return Array
*/
public function addCustomFields(Array $data)
{
$custom_fields = array();
// loop through the submitted data and check for custom fields
foreach($data as $key=>$value){
if(count(explode('customfield_',$key)) > 1){
$custom_fields[] = array("Key" => substr($key, 12), "Value" => $value);
}
}

$this->extend('updateCustomFields', $custom_fields);

// check if any custom fields were found
if(count($custom_fields) > 0) {
return $custom_fields;
}

return array();
}
}
2 changes: 2 additions & 0 deletions docs/en/userguide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Documentation
See the README file - theres more there.

0 comments on commit f7c3f39

Please sign in to comment.