Last active
December 30, 2015 06:59
Revisions
-
ablik revised this gist
Jan 11, 2014 . 1 changed file with 34 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -33,36 +33,51 @@ function tv2id ($tvid, $tvval) { $field2 = $modx->getTemplateVar($tv_valuta,'',$id); $fid2 = $field2['id']; $fval2 = str_replace(" ","",$field2['value']); $take_curr = $modx->getTemplateVar($tv_curr,'',$id); $field3 = $modx->getTemplateVar($take_curr['value'],'',$id_curr); $fval3 = $field3['value']; $fval1 = round($fval2 * $fval3,0); if ($mode == 'new') { $sql="INSERT INTO $tvc (tmplvarid, contentid, value) values ($fid1, $id, '$fval1')"; } else { $check_select = "SELECT * FROM ".$modx->getFullTableName('site_tmplvar_contentvalues')." WHERE tmplvarid = ".$fid1." AND contentid=".$id.""; $check_col = $modx->db->query($check_select); $check = $modx->db->getColumn(id, $check_col); if ($check !=NULL) { $sql="UPDATE $tvc SET `value`='$fval1' WHERE `tmplvarid`='$fid1' AND `contentid`='$id'"; } else { $sql="INSERT INTO $tvc (tmplvarid, contentid, value) values ($fid1, $id, '$fval1')"; } } //print_r($id); //exit(); $modx->db->query($sql); } if ($id == $id_curr) { //todo:добавить автоматическое определение id параметра с валютой $usd = '42'; $eur = '45'; $grn = '57'; //Определяем значения курсов валют $curr_usd = $modx->getTemplateVar($usd,'',$id); $curr_eur = $modx->getTemplateVar($eur,'',$id); $curr_grn = $modx->getTemplateVar($grn,'',$id); $usd_ids = tv2id($usd, $tv_curr); $eur_ids = tv2id($eur, $tv_curr); $grn_ids = tv2id($grn, $tv_curr); //todo: переписать в один универсальный sql запрос $sql_usd = "UPDATE ".$tvc." AS a " @@ -84,5 +99,15 @@ function tv2id ($tvid, $tvval) { . "AND b.contentid IN (".$eur_ids.")"; $modx->db->query($sql_eur); $sql_grn = "UPDATE ".$tvc." AS a " . "LEFT JOIN ".$tvc." AS b " . "ON a.contentid=b.contentid " . "SET b.value = a.value*".$curr_grn['value']." " . "WHERE a.tmplvarid = ".$tv_valuta." " . "AND b.tmplvarid = ".$tv_price." " . "AND b.contentid IN (".$grn_ids.")"; $modx->db->query($sql_grn); } } -
ablik revised this gist
Dec 4, 2013 . 1 changed file with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,6 +56,7 @@ function tv2id ($tvid, $tvval) { $usd = '42'; $eur = '45'; //Определяем значения курсов валют $curr_usd = $modx->getTemplateVar($usd,'',$id); $curr_eur = $modx->getTemplateVar($eur,'',$id); @@ -69,7 +70,8 @@ function tv2id ($tvid, $tvval) { . "ON a.contentid=b.contentid " . "SET b.value = a.value*".$curr_usd['value']." " . "WHERE a.tmplvarid = ".$tv_valuta." " . "AND b.tmplvarid = ".$tv_price." " . "AND b.contentid IN (".$usd_ids.")"; $modx->db->query($sql_usd); @@ -78,7 +80,8 @@ function tv2id ($tvid, $tvval) { . "ON a.contentid=b.contentid " . "SET b.value = a.value*".$curr_eur['value']." " . "WHERE a.tmplvarid = ".$tv_valuta." " . "AND b.tmplvarid = ".$tv_price." " . "AND b.contentid IN (".$eur_ids.")"; $modx->db->query($sql_eur); } -
ablik created this gist
Dec 4, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,85 @@ //<?php //*********************************** // TVCurrencyConverter plugin v1.1 for MODx 1.0.x //*********************************** // Eugeny `zk` Krylov - http://nopreset.ru // Support topic: http://modx-shopkeeper.ru/forum/viewtopic.php?id=239 //*********************************** // Description: TV Currency Converter // Configuration: &tv_price=TV цены;string;цена &tv_valuta=TV цены в валюте;string;доллары &id_curr=id ресурса с курсом;string;1 &tv_curr=TV курса;string;курс // System Events: OnDocFormSave //*********************************** //update by ablik $e = &$modx->Event; $tvc = $modx->getFullTableName('site_tmplvar_contentvalues'); function tv2id ($tvid, $tvval) { global $modx; $sql = "SELECT contentid FROM ".$modx->getFullTableName('site_tmplvar_contentvalues')." WHERE tmplvarid = ".$tvval." AND value=".$tvid.""; $select = $modx->db->query($sql); $ids = $modx->db->getColumn(contentid, $select); $ids = implode(",", $ids); return $ids; } if ($e->name == 'OnDocFormSave'){ $field1 = $modx->getTemplateVar($tv_price,'',$id); if ( is_array($field1) ) { $fid1 = $field1['id']; $field2 = $modx->getTemplateVar($tv_valuta,'',$id); $fid2 = $field2['id']; $fval2 = $field2['value']; $take_curr = $modx->getTemplateVar($tv_curr,'',$id); $field3 = $modx->getTemplateVar($take_curr['value'],'',$id_curr); $fval3 = $field3['value']; $fval1 = round($fval2 * $fval3,0); if ($mode == 'new') { $sql="INSERT INTO $tvc (tmplvarid, contentid, value) values ($fid1, $id, '$fval1')"; } else { $sql="UPDATE $tvc SET value='$fval1' WHERE tmplvarid=$fid1 AND contentid=$id"; } $modx->db->query($sql); } if ($id == $id_curr) { //todo:добавить автоматическое определение id параметра с валютой $usd = '42'; $eur = '45'; $curr_usd = $modx->getTemplateVar($usd,'',$id); $curr_eur = $modx->getTemplateVar($eur,'',$id); $usd_ids = tv2id($usd, $tv_curr); $eur_ids = tv2id($eur, $tv_curr); //todo: переписать в один универсальный sql запрос $sql_usd = "UPDATE ".$tvc." AS a " . "LEFT JOIN ".$tvc." AS b " . "ON a.contentid=b.contentid " . "SET b.value = a.value*".$curr_usd['value']." " . "WHERE a.tmplvarid = ".$tv_valuta." " . "AND b.tmplvarid = ".$tv_price." AND b.contentid IN (".$usd_ids.")"; $modx->db->query($sql_usd); $sql_eur = "UPDATE ".$tvc." AS a " . "LEFT JOIN ".$tvc." AS b " . "ON a.contentid=b.contentid " . "SET b.value = a.value*".$curr_eur['value']." " . "WHERE a.tmplvarid = ".$tv_valuta." " . "AND b.tmplvarid = ".$tv_price." AND b.contentid IN (".$eur_ids.")"; $modx->db->query($sql_eur); } }