[TYPO3-dam] DAM 1.1 beta01 for download - (dam_downloads)

Karl-Ernst Kiel kekiel at kekiel.de
Mon Nov 27 21:39:03 CET 2006


René Fritz wrote:
> I'm also interested in the changes made on dam_downloads. Please send me your 
> code. I may (not promise) make a "best of" compilation with adoption to DAM 
> 1.1. 

Hi!

This is the "interesting part" of my dam_downloads modifications.
(I also added a custom "language table" for the content languages 
because of the "special needs" of my customer and am currently 
implementing grouping of results by categories. I´ll post the whole 
thing when it´s ready...)

Would be nice to have a feedback. May be there are things that could be 
done better or easier?! Or should never be done this way ?!:-) - I´m 
just on the way discovering the API´s and learning by doing and copying 
ideas and concepts from other extensions...

Greetings,
Karl-E.

(I will also send a mail with file attached...)


           //[...]
           // taken from dev. Version of dam_dlbycat
           // Karl-E. Kiel
           // kekiel at kekiel.de
           // 26.11.2006
           // illustration of concept of FE category selection tree

function main($content, $conf) {

           //[...]

     // get the id of the media folder(s)
	$this->conf['pidList'] = tx_dam_db::getPidList();

           // browse cat tree this depth
           $this->maxSearchTreeBrowseLevels = 
t3lib_div::intInRange($this->conf['maxSearchTreeBrowseLevels'],0,100,25);

           // use an array of all category names
           // whole tree is fetched an localisation is applied
	// only default-language (l18n_parent = 0)
	$from = 'tx_dam_cat';
	$where = 'pid IN ('.$this->conf['pidList'].') AND l18n_parent = 0';
	$where .= $this->cObj->enableFields('tx_dam_cat');
	$res = 
$GLOBALS['TYPO3_DB']->exec_SELECTquery('title,pid,uid,parent_id,sys_language_uid,l18n_parent', 
$from, $where, '', 'sorting');
	$this->allCatArray = array();
	// apply internationalisation to the categories
	if ($res) {
		while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$this->allCatArray[] = 
$GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_dam_cat', $row, 
$GLOBALS['TSFE']->sys_language_uid, '');
		}
	}
           //[...]
        }


       function listView($content, $conf) {

       //[...]

       // collect category uid´s of each "selection tree"
if ($this->displaySearch) {
   		// collect category uid´s of the "selection tree" in searchform
        	if ($this->piVars['cat1']) {
        		foreach($this->piVars['cat1'] as $tempcat) {
        			$tempcat = t3lib_div::intInRange($tempcat, 0, 100000, 0);
        			if ($tempcat) $searchCatList1[] = $tempcat;
        		}
        	}
	$catUidList1 = implode(',', $searchCatList1);
} else {
	// no search - browse the cat´s as selected in CE Flexform
	// (and optionally traverse the tree)
	$catUidList1 = implode(',', $this->startCatList1);
	// category tree object (from dam_catedit extension)
	$treedb = t3lib_div::makeInstance('tx_damcatedit_db');
	$treedb->init('tx_dam_cat', 'parent_id');
	// get subtree´s list of uid´s
	if ($this->includeSubtree1) {
		$catUidList1 = $treedb->getSubRecordsIdList($catUidList1, 
$this->maxSearchTreeBrowseLevels);
	}
}

// compose the DAM uid-List regarding the selected categories
$tmp_where = 'AND tx_dam_cat.uid IN ('.$catUidList1.')';
$tmp_where .= $this->cObj->enableFields('tx_dam');
$damIdList1 = array();
if ($res = $GLOBALS['TYPO3_DB']->exec_SELECT_mm_query('tx_dam.uid', 
'tx_dam', 'tx_dam_mm_cat', 'tx_dam_cat', $tmp_where)) {
	while ($tmprow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
		$damIdList1[] = $tmprow['uid'];
	}
}

       //(using two trees in my extension - skipped the second here...
       $damIdMerged = $damIdList1;

// get final dam $res recordset with merged result id´s
if (count($damIdMerged)) {
	$addWhere = 'AND uid IN ('.implode(',', $damIdMerged).')';
} else {
	// if list is empty, result should also be
	$addWhere = 'AND 1=0';
}

       // Get number of records:
       $this->internal['res_count'] = 0;
       if ($res = $this->pi_exec_query('tx_dam', 1, $addWhere)) {
       	list($this->internal['res_count']) = 
$GLOBALS['TYPO3_DB']->sql_fetch_row($res);
       }

       // Make listing query, pass query to SQL database:
       $res = $this->pi_exec_query('tx_dam', 0, $addWhere);

       //[...]

       }


/**
*  Build a html select tree starting with category $startCat
*
* @param   uid of start cat
* @param   name of html form input element
* @param   current treeDepth
* @return [string]    html content: single tree
*/
function buildCatSelectTree($startCat, $inputname, $treeDepth = 0) {

	// max recursion depth
	if ($treeDepth > $this->maxSearchTreeBrowseLevels) {
		return '';
	}
	$siblings = array();
	// walk through $this->allCatArray searching for entrys with pid=$startCat
	foreach($this->allCatArray as $v) {
		// get starting cat name
		if ($startCat == $v['uid']) {
                   // indent line according to tree level
			for($i = 0; $i < $treeDepth; $i++) {
				$content .= '&nbsp;&nbsp;&nbsp;';   // TODO: configure via TS
			}
			$content .= '<input type="checkbox" 
name="tx_damdlbycat_pi1['.$inputname.']['.$v['uid'].']" 
value="'.$v['uid'].'"'.($this->piVars[$inputname][$v['uid']] > 0 ? ' 
checked="checked"' : '').' />'.$v['title'].'<br />';
		}
		// siblings?
		if ($startCat == $v['parent_id']) {
			$siblings[] = $v['uid'];
		}
	}
	// add Subtrees for siblings
	foreach($siblings as $sibling) {
		$content .= $this->buildCatSelectTree($sibling, $inputname, $treeDepth 
+ 1);
	}
	return $content;
}



More information about the TYPO3-project-dam mailing list