Recent Topics

1 Mar 14, 2008 10:21    

Hi
Is there a way I can insert tags in database by calling a standard function which will break the string, assign ids and put tags in db. I just can't figure out how do I put tags directly in db.

I have a tag strings and post ids
Thanks

2 Mar 14, 2008 16:48

Completely untested :

<?php
$ItemCache = get_cache( 'ItemCache' );
$Item = & $ItemCache->get_by_ID( 1 );// replace 1 with the post ID
$Item->set_tags_from_string( 'my, groovy, tags, string' );// you may wish to choose different tags ;)
$Item->dbupdate();
?>

¥

3 Mar 14, 2008 17:24

Thanks, I'll try it today

4 Mar 14, 2008 20:29

Doesn't work. The functions I use

function AdminTabAction()
	{	
		global $Plugins, $DB;
		
		$this->param_tag = param( $this->get_class_id('tag'));
		
		if( $this->param_id = param( $this->get_class_id('id') ) )
		{
			$ItemCache = get_cache( 'ItemCache' );
			
			$post_ID = $this->param_id;
			$tag = $this->param_tag;
			
			$Item = & $ItemCache->get_by_ID( $post_ID );
			$Item->set_tags_from_string( $tag );
			$Item->dbupdate(); 
			
			$this->text_from_AdminTabAction .= '<p>Tags <b>"'.$tag.'"</b> were added for item <b>'.$post_ID.'</b></p>';
		}
	}


	function AdminTabPayload()
	{
		echo 'Insert tags.<br /><br />';
		echo $this->text_from_AdminTabAction;

		$Form = & new Form();
		$Form->begin_form();
		$Form->hidden_ctrl();
		$Form->hiddens_by_key( get_memorized() );
		
		$Form->text_input( $this->get_class_id().'_id', $this->param_text, '20', 'Post ID' );
		$Form->text_input( $this->get_class_id().'_tag', $this->param_text, '160', 'Tag string' );

		$Form->button_input();
		$Form->end_form();
	}


Debug info

Query #14: DataObjectCache::get_by_ID()
SELECT *
FROM evo_items__item
WHERE post_ID = 1234

5 Mar 15, 2008 08:47

sam2kb wrote:

$this->param_tag = param( $this->get_class_id('tag'));

if( $this->param_id = param( $this->get_class_id('id') ) )

sam2kb wrote:

$Form->text_input( $this->get_class_id().'_id', $this->param_text, '20', 'Post ID' );
$Form->text_input( $this->get_class_id().'_tag', $this->param_text, '160', 'Tag string' );

;)

¥

6 Mar 15, 2008 08:58

Hey, this is my first try. :( At this stage I'm copy-pasting, but this ugly code works. It does select an item but it doesn't update it.

7 Mar 15, 2008 09:24

		function AdminTabAction()
    {

        $this->param_tag = param( $this->get_class_id().'_tag');

        if( $this->param_id = param( $this->get_class_id().'_id' ) )
        {
            $ItemCache = get_cache( 'ItemCache' );

            $Item = & $ItemCache->get_by_ID( $this->param_id );
            $Item->set_tags_from_string( $this->param_tag );
            $Item->insert_update_tags( 'update');

            $this->msg( '<p>Tags <b>"'.$this->param_tag.'"</b> were added for item <b>'.$this->param_id.'</b></p>', 'success' );
        }
    }


    function AdminTabPayload()
    {
        echo 'Insert tags.';

        $Form = & new Form();
        $Form->begin_form();
        $Form->hidden_ctrl();
        $Form->hiddens_by_key( get_memorized() );

        $Form->text_input( $this->get_class_id().'_id', $this->param_id, '20', 'Post ID' );
        $Form->text_input( $this->get_class_id().'_tag', $this->param_tag, '160', 'Tag string' );

        $Form->button_input();
        $Form->end_form();
    }

It would appear that unless the item itself has changes then the tags don't up0date, so you need to convince them that they should update ;)

¥

8 Mar 15, 2008 09:36

Perfect! Thanks

:cookie:


Form is loading...