Skip to content

Instantly share code, notes, and snippets.

@core01
Last active September 12, 2015 15:37
Show Gist options
  • Save core01/b71350e1e7540d5208ab to your computer and use it in GitHub Desktop.
Save core01/b71350e1e7540d5208ab to your computer and use it in GitHub Desktop.
modxplugin
<?php
if ($modx->event->name == 'OnDocFormSave') {
if(isset($_POST['adress']) AND isset($_POST['phone']) ){
$sellUSD = floatval($_POST['sellUSD']);
$buyUSD = floatval($_POST['buyUSD']);
$buyEUR = floatval($_POST['buyEUR']);
$buyUAN = floatval($_POST['buyUAN']);
$buyRUB = floatval($_POST['buyRUB']);
$sellEUR = floatval($_POST['sellEUR']);
$sellUAN = floatval($_POST['sellUAN']);
$sellRUB = floatval($_POST['sellRUB']);
$adress = $modx->stripTags($_POST['adress']);
$phone = $modx->stripTags($_POST['phone']);
$properties[ 'exchange' ] =array(
'sellUSD' => $sellUSD,
'buyUSD' => $buyUSD,
'sellEUR' => $sellEUR,
'buyEUR' => $buyEUR,
'buyRUB' => $buyRUB,
'sellRUB' => $sellRUB,
'buyUAN' => $buyUAN,
'sellUAN' => $sellUAN,
'adress' => $adress,
'phone' => $phone
);
// $prop["exchange"] = $exchange;
$resource->set( 'properties', $modx->toJSON( $properties ) );
$resource->setTVValue('sellUSD', $sellUSD);
$resource->setTVValue('buyUSD', $buyUSD);
$resource->setTVValue('sellEUR', $sellEUR);
$resource->setTVValue('buyEUR', $buyEUR);
$resource->setTVValue('sellUAN', $sellUAN);
$resource->setTVValue('buyUAN', $buyUAN);
$resource->setTVValue('sellRUB', $sellRUB);
$resource->setTVValue('buyRUB', $buyRUB);
$resource->setTVValue('exch.adress', $adress);
$resource->setTVValue('phone', $phone);
$resource->set('published', 0);
$resource->save();
//$resource->setProperties($exchange, 'exchange');
# ВОТ ЭТОТ КОД -> РАБОТАЕТ, значения записываются в TV
/* if(!$resource->setTVValue('$sellUSD', $sellUSD) and !$resource->setTVValue('buyUSD', $buyUSD)) {
$message = "Fail!";
}
else{
$message = "Success";
}
*/
}else{
//Номера ТВ
$sellUSD = $resource->getTVValue(3);
$buyUSD = $resource->getTVValue(4);
$phone = $resource->getTVValue(5);
$sellRUB = $resource->getTVValue(6);
$buyRUB = $resource->getTVValue(7);
$buyEUR = $resource->getTVValue(8);
$sellEUR = $resource->getTVValue(9);
$buyUAN = $resource->getTVValue(10);
$sellUAN = $resource->getTVValue(11);
$adress = $resource->getTVValue(12);
$properties[ 'exchange' ] =array(
'sellUSD' => $sellUSD,
'buyUSD' => $buyUSD,
'sellEUR' => $sellEUR,
'buyEUR' => $buyEUR,
'buyRUB' => $buyRUB,
'sellRUB' => $sellRUB,
'buyUAN' => $buyUAN,
'sellUAN' => $sellUAN,
'adress' => $adress,
'phone' => $phone
);
$resource->set( 'properties', $modx->toJSON( $properties ) );
$resource->save();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment