Last active
September 7, 2017 12:28
-
-
Save keslo/2c62d3c79cb9168e12ff28cf0d1060c5 to your computer and use it in GitHub Desktop.
modx_update_insert.php
This file contains 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 characters
<?php | |
if (!function_exists('saveTV')) { | |
function saveTV($contentid,$tv,$tvval){ | |
global $modx; | |
if(is_numeric($tv)){ | |
$tvid = $tv; | |
}else{ | |
$table = $modx->getFullTableName('site_tmplvars'); | |
$tvid = $modx->db->getValue( $modx->db->select( 'id', $table, 'name="'.$tv.'"' ) ); | |
} | |
$table = $modx->getFullTableName('site_tmplvar_contentvalues'); | |
$isset = $modx->db->getValue( $modx->db->select( 'count(*)', $table, "contentid=".$contentid." AND tmplvarid=".$tvid." " ) ); | |
if($isset){ | |
$modx->db->update(array('value'=>$tvval),$table,"contentid=".$contentid." AND tmplvarid=".$tvid); | |
} | |
else{ | |
$modx->db->insert(array('contentid'=>$contentid,'tmplvarid'=>$tvid,'value'=>$tvval),$table); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment