We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24723
    • 19 Posts
    I’m trying to modify TvTagCloud so that I can send it multiple TVs and it will fetch the tags associated with them. I’m having a bit of trouble though.

    In my TvTagCloud my tvTags looks like this:
    tvTags=`region,countries`


    I’d like to be able to return tags from both of those TVs.

    I’m using list() and explode() to divide up tvTags into separate variables to construct my query. However, what I have isn’t working and I’m not sure what I’ve done wrong. Any help is greatly appreciated!

    if (!function_exists('getTags')) {
    	function getTags($cIDs, $tvTags, $days) {
    		
    		global $modx, $parent;
    		
    		$docTags = array ();
    
    		$baspath= $modx->config["base_path"] . "manager/includes";
    	    include_once $baspath . "/tmplvars.format.inc.php";
    	    include_once $baspath . "/tmplvars.commands.inc.php";
    		
    		if ($days > 0) {
    			$pub_date = mktime() - $days*24*60*60;
    		} else {
    			$pub_date = 0;
    		}
     
    		list($region, $countries) = explode(",", $tvTags);
    
    		$tb1 = $modx->getFullTableName("site_tmplvar_contentvalues");
    		$tb2 = $modx->getFullTableName("site_tmplvars");
    		$tb_content = $modx->getFullTableName("site_content");
    		$query = "SELECT stv.name,stc.tmplvarid,stc.contentid,stv.type,stv.display,stv.display_params,stc.value";
    		$query .= " FROM ".$tb1." stc LEFT JOIN ".$tb2." stv ON stv.id=stc.tmplvarid ";
    		$query .= " LEFT JOIN $tb_content tb_content ON stc.contentid=tb_content.id ";
                	$query .= " WHERE stv.name='".$countries."' AND stc.contentid IN (".implode($cIDs,",").") ";
                    $query .= " OR stv.name='".$region."' AND stc.contentid IN (".implode($cIDs,",").") ";
                	$query .= " AND tb_content.pub_date >= '$pub_date' ";
    		$query .= " AND tb_content.published = 1 ";
    		$query .= " ORDER BY stc.contentid ASC;";
    		
    		$rs = $modx->db->query($query);
    		$tot = $modx->db->getRecordCount($rs);
    		$resourceArray = array();
    		for($i=0;$i<$tot;$i++)  {
    			$row = @$modx->fetchRow($rs);
    			$docTags[$row['contentid']]['tags'] = getTVDisplayFormat($row['name'], $row['value'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);   
    		}
              	if ($tot != count($cIDs)) {
    			$query = "SELECT name,type,display,display_params,default_text";
    			$query .= " FROM $tb2";
    			$query .= " WHERE name='".$countries."' OR name= '".$region."' ";
    			$rs = $modx->db->query($query);
    			$row = @$modx->fetchRow($rs);
    			$defaultOutput = getTVDisplayFormat($row['name'], $row['default_text'], $row['display'], $row['display_params'], $row['type'],$row['contentid']);
    			foreach ($cIDs as $id) {
    				if (!isset($docTags[$id]['tags'])) {
    					$docTags[$id]['tags'] = $defaultOutput;
    				}
    			}
    		}
    	
    			return $docTags;
    	}
    }