Skip to content

Commit

Permalink
fields can be set to custom xml now
Browse files Browse the repository at this point in the history
  • Loading branch information
shama committed Oct 9, 2010
1 parent f39db22 commit d1fed99
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 34 deletions.
21 changes: 11 additions & 10 deletions README.md
Expand Up @@ -148,21 +148,22 @@ FreshCake is offered under an [MIT license](http://www.opensource.org/licenses/m
## Roadmap and Known Issues

* MORE TESTING! MORE TESTS!
* Fix issue with some text fields showing up as Array
* Format lines/xml on invoice, estimate and recurring afterFind (so they dont break scaffold)
* Implement estimate.sendByEmail
* Implement invoice.sendByEmail, invoice.sendBySnailMail
* Implement recurring.auto_bill
* Implement staff.current
* Implement OAuth support
* Add support for staff (needs custom afterFind)
* Test support for linking models together (hopefully already does automatically)
* i18n
* Fix issue with some text fields showing up as Array - v0.2
* Format lines/xml on invoice, estimate and recurring afterFind (so they dont break scaffold) - v0.2
* Implement estimate.sendByEmail - v0.2
* Implement invoice.sendByEmail, invoice.sendBySnailMail - v0.2
* Implement recurring.auto_bill - v0.2
* Implement staff.current - v0.2
* Add support for staff (needs custom afterFind) - v0.2
* Test support for linking models together (hopefully already does automatically) - v0.2
* Implement OAuth support - v0.3
* i18n - v0.3

## Changelog

### 0.2

* Fields can be set to custom XML now (needed for fixing tasks in project)
* Added test cases for callback.verify, callback.resendToken
* Added support for callback.verify, callback.resendToken
* Added methods to return last request and response xml
Expand Down
23 changes: 14 additions & 9 deletions models/datasources/freshbooks_source.php
Expand Up @@ -230,16 +230,21 @@ public function create(&$model, $fields=null, $values=null) {
$submethod = 'create';
}
$xml =& new Xml(array('Request' => array('method' => $method.'.'.$submethod)));
if (!isset($data['xml'])) {
foreach ($data as $key => $val) {
if (is_array($val)) {
$singular = Inflector::singularize($key);
$data[$key] = array($singular => $val);
}
$node =& new Xml(array($method => array()));
foreach ($data as $key => $val) {
if (is_array($val)) {
$singular = Inflector::singularize($key);
$val = array($key => array($singular => $val));
$node->first()->append($val, array('format' => 'tags'));
unset($data[$key]);
} elseif (substr($val, 0, 1) == '<') {
$my_node =& new Xml($val);
$node->first()->append($my_node->children);
unset($data[$key]);
} else {
$my = array($key => array(array($val)));
$node->first()->append($my);
}
$node =& new Xml(array($method => $data), array('format' => 'tags'));
} else {
$node =& new Xml($data['xml']);
}
$xml->first()->append($node->children);
$this->__requestXml = $xml->toString(array('header' => true));
Expand Down
18 changes: 3 additions & 15 deletions models/project.php
Expand Up @@ -44,10 +44,6 @@ class Project extends FreshbooksAppModel {
'type' => 'text',
'null' => true,
),
'xml' => array(
'type' => 'text',
'null' => true,
),
);
public $validate = array(
'name' => 'notEmpty',
Expand All @@ -56,8 +52,8 @@ class Project extends FreshbooksAppModel {

/**
* beforeSave
* Custom format because datasource
* can't handle 'tasks'.
* Set tasks to xml as the datasource
* cant handle it automatically
*
* @return boolean
*/
Expand All @@ -68,15 +64,7 @@ public function beforeSave() {
array('tasks' => $this->data[$this->name]['tasks']),
array('format' => 'tags')
);
unset($this->data[$this->name]['tasks']);
$data =& new Xml($this->data, array('format' => 'tags'));
$data->first()->append($tasks->children);
$xml = $data->toString();
$this->data = array(
$this->name => array(
'xml' => $xml,
),
);
$this->data[$this->name]['tasks'] = $tasks->toString();
}
return true;
}
Expand Down

0 comments on commit d1fed99

Please sign in to comment.