[TYPO3-dam] Automatic categorization while importing

Völker Stefan t3 at nyxos.de
Fri Sep 26 23:29:43 CEST 2008


Good evening,

now i am really confused...

I use following code due to dam_demo of the index_rule:	

function processMeta($meta)	{
		$fileId = $meta['fields']['uid'];
		$keywords = explode(',',$meta['fields']['keywords']);
		
		for($i = 0; $i < count($keywords); $i++) {
			$query = $GLOBALS['TYPO3_DB']->exec_SELECTquery('COUNT(*) as  
anzahl', 'tx_dam_cat', ' title = "'.$keywords[$i].'"','','');
			$res = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query);
			if($res['anzahl'] == 0) {
				# create cat
				$insertFields = array('title' => $keywords[$nxs],'pid' => 31,  
'parent_id' => 0, 'tstamp' => time(), 'crdate' => time(), 'cruser_id'  
=> $BE_USER->user['uid'] );
				$query = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_cat ', 
$insertFields);
				$catId = $GLOBALS['TYPO3_DB']->sql_insert_id();
			} else {
				# get uid from cat with this keyword-title
				$qu = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
					'uid',
					'tx_dam_cat',
					'title = "'.$keywords[$i].'"',
					'',
					'');
				$catIdRes = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qu);
				$catId = $catIdRes['uid'];
			}

			# create mm-relation
			$insertCatRelation = array('uid_local' => $fileId, 'uid_foreign' =>  
$catId);
			$catQuery = $GLOBALS['TYPO3_DB']->exec_INSERTquery('tx_dam_mm_cat',  
$insertCatRelation);
		}
		return $meta;
	}


It won't insert the mm-relation.


BUT if i use this phrase for the $insertCatRelation:
$insertCatRelation = array('uid_local' => $fileId+1, 'uid_foreign' =>  
$catId);
it works (although the id is wrong of course...)

I double-checke, if $fileId is an integer, it is.

What can this be ??


Thanks in advance,


Stefan.

Am 26.09.2008 um 11:53 schrieb Thorsten Boock:

> Völker Stefan schrieb:
>> Hi Thorsten,
>>
>> sounds interesting!
>> I will definetly have a look at this function -first thing in the  
>> morning
>>
>> Best regards,
>> Stefan.
>>
>>
>> Am 25.09.2008 um 17:39 schrieb Thorsten Boock:
>>
>>> Völker Stefan schrieb:
>>>> Hello DAM-lovers,
>>>>
>>>> is it possible, to use one of the metadata-fields for automatic
>>>> categorization?
>>>>
>>>> I have this in my mind:
>>>> An image is saved via Adobe Bridge with following keywords  
>>>> "animal",
>>>> "nature", "CMS".
>>>> It will be uploaded into the DAM and while the automatic indexing
>>>> process, the comma-separated keywordlist will be used to  
>>>> categorize this
>>>> image in following categories: "animal", "nature" and "CMS".
>>>>
>>>> I don't believe, that there is already a solution for this, but i  
>>>> want
>>>> to know, on which place (e.g. hook) i can implement this little  
>>>> feature
>>>> as described above.
>>>> Where do i have to "register" my "keyword-to-category"-function?
>>>>
>>>> Thank you very much in advance,
>>>>
>>>> Stefan.
>>>
>>> Hi,
>>> I'm trying to do exactly the same right now. As I had my first  
>>> look on
>>> DAM about 7 hours ago I'm not exactly sure if I really got it but  
>>> have
>>> you had a look on the file class.tx_damdemo_sv1.php of the
>>> demo-extension, yet? I think the function processMeta is the right  
>>> place
>>> to call your code. The meta-array given to this function as a  
>>> parameter
>>> contains the iptc-data and thereby the keywords you are looking for.
>>>
>>>
>>> Regards,
>>> Thorsten Boock
>>> _______________________________________________
>>> TYPO3-project-dam mailing list
>>> TYPO3-project-dam at lists.netfielders.de
>>> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-project-dam
>>
>
> Hi Stefan,
>
> after taking a closer look at class.tx_dam_indexrulebase.php again, I
> have to revoke my previous comment.
>
> If you overwrite $meta['fields']['category'] in the function
> proccessMeta, it will be overwritten again at some later point.  
> Changing
>  the title field in processMeta for example works perfect. As I don't
> have much time to finish the project I'm currently working on, I'm
> unable to research the problem more precisely.
>
> Maybe the following (very dirty but extremly useful) testing-code  
> helps
> you a little bit:
>
> function postProcessMeta($meta, $abs) {
> 	exec('echo "'.print_r($meta, true).'" >> /home/thorsten/ 
> exiftest3.txt');
> 	exec('echo "'.print_r($abs, true).'" >> /home/thorsten/ 
> exiftest3.txt');
> 	}
>
> At the point where the function is called the datasets corresponding  
> to
> the indexed files are allready inserted into the database and you can
> read their uids from $meta['fields']['uid']. This makes it very easy  
> to
> execute an updatequery. The variable abs contains the full path to the
> indexed file. The function gets called for every single file.
>
> Of course this additional query will cost you script-runtime and  
> thereby
> it isn't a beautiful solution - but I think it will be my way to do it
> because of the lack of time.
>
> Regards,
> Thorsten Boock
> _______________________________________________
> TYPO3-project-dam mailing list
> TYPO3-project-dam at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-project-dam



More information about the TYPO3-project-dam mailing list