Skip to content

Commit fb1d477

Browse files
authored
Merge pull request #24 from MyMedia/new-features
Extended by new methods insertUpdateRelationalTable and deleteRelationalTableData
2 parents a854ecd + d0c2fba commit fb1d477

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

src/Silverpop/EngagePod.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,84 @@ public function purgeTable($tableName, $isPrivate = true) {
598598
}
599599

600600
}
601+
602+
/**
603+
* This interface inserts or updates relational data
604+
*
605+
* For each Row that is passed in:
606+
* - If a row is found having the same key as the passed in row, update the record.
607+
* - If no matching row is found, insert a new row setting the column values to those passed in the request.
608+
*
609+
* Only one hundred rows may be passed in a single insertUpdateRelationalTable call!
610+
*/
611+
public function insertUpdateRelationalTable($tableId, $rows) {
612+
$processedRows = array();
613+
$attribs = array();
614+
foreach($rows as $row) {
615+
$columns = array();
616+
foreach($row as $name => $value)
617+
{
618+
$columns['COLUMN'][] = $value;
619+
$attribs[5]['COLUMN'][] = array('name' => $name);
620+
}
621+
622+
$processedRows['ROW'][] = $columns;
623+
}
624+
625+
$data["Envelope"] = array(
626+
"Body" => array(
627+
"InsertUpdateRelationalTable" => array(
628+
"TABLE_ID" => $tableId,
629+
"ROWS" => $processedRows,
630+
),
631+
),
632+
);
633+
634+
$response = $this->_request($data, array(), $attribs);
635+
$result = $response["Envelope"]["Body"]["RESULT"];
636+
637+
if ($this->_isSuccess($result)) {
638+
return true;
639+
} else {
640+
throw new \Exception("insertUpdateRelationalTable Error: ".$this->_getErrorFromResponse($response));
641+
}
642+
}
643+
644+
/**
645+
* This interface deletes records from a relational table.
646+
*/
647+
public function deleteRelationalTableData($tableId, $rows) {
648+
$processedRows = array();
649+
$attribs = array();
650+
foreach($rows as $row) {
651+
$columns = array();
652+
foreach($row as $name => $value)
653+
{
654+
$columns['KEY_COLUMN'][] = $value;
655+
$attribs[5]['KEY_COLUMN'][] = array('name' => $name);
656+
}
657+
658+
$processedRows['ROW'][] = $columns;
659+
}
660+
661+
$data["Envelope"] = array(
662+
"Body" => array(
663+
"DeleteRelationalTableData" => array(
664+
"TABLE_ID" => $tableId,
665+
"ROWS" => $processedRows,
666+
),
667+
),
668+
);
669+
670+
$response = $this->_request($data, array(), $attribs);
671+
$result = $response["Envelope"]["Body"]["RESULT"];
672+
673+
if ($this->_isSuccess($result)) {
674+
return true;
675+
} else {
676+
throw new \Exception("deleteRelationalTableData Error: ".$this->_getErrorFromResponse($response));
677+
}
678+
}
601679

602680
/**
603681
* Import a list/database

src/Silverpop/Util/ArrayToXml.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ function _processArray( &$array, $level = 0, $parent = '' ) {
5151

5252
if ( isset( $this->_attribs[$tlevel][$name][$this->_rep[$name] - 1] ) && is_array( $this->_attribs[$tlevel][$name][$this->_rep[$name] - 1] ) ) {
5353
foreach ( (array) $this->_attribs[$tlevel][$name][$this->_rep[$name] - 1] as $aname => $avalue ) {
54-
unset( $value[$aname] );
5554
$attrs .= " $aname=\"$avalue\"";
5655
}
5756
}

0 commit comments

Comments
 (0)