Skip to content

Instantly share code, notes, and snippets.

@keslo
Last active September 7, 2017 12:28
Show Gist options
  • Save keslo/2c62d3c79cb9168e12ff28cf0d1060c5 to your computer and use it in GitHub Desktop.
Save keslo/2c62d3c79cb9168e12ff28cf0d1060c5 to your computer and use it in GitHub Desktop.
modx_update_insert.php
<?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