Welcome, Guest
Username: Password: Remember me

TOPIC: Help with tables.

Help with tables. 20 Mar 2012 10:40 #1681

Hello, I'm trying to build two tables on my project with same values, in which users can put values on the 1st table, then they can transfer it to the other table. Can anyone tell me how can I achieve this? Thanks! :)
The administrator has disabled public write access.

Re: Help with tables. 20 Mar 2012 11:23 #1684

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
I don't ask you why don't you simply use a marker that define when the element has been transfered.

If you want to move the element, you should do it manually.

TODO :
$element = $modelItemFirst->getData();
$element->id = 0;
if($modelItemSecond->save($element))		//COPY
	$modelItemFirst->delete();			//DELETE PREVIOUS

It is only the concept, you have to first get the instance of $modelItemFirst and $modelItemSecond

Should work
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Help with tables. 20 Mar 2012 14:53 #1693

Hi, thank you for the reply sir. And I apologize for posting the topic in the wrong section. Thank you for moving it.
Back to the topic, where should I insert those lines? and in my case, what is an "instance"? If you could sir, Can you set and give an example code? Would really appreciate if you can as this is really crucial in my project.

Thank you!
Daryll
The administrator has disabled public write access.

Re: Help with tables. 20 Mar 2012 20:06 #1696

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
To get a model wherever in Joomla :
$model = JModel::getInstance('Mymodel', 'MycomponentModel');

NB : If you call it outside of your component, you must include the file of the concerned model
require_once(JPATH_ADMIN_XXXXX .DS.'models'.DS.'mymodel.php');

In your case, you must only deal with ITEM models


Place this code in your controller behind a new task function called copy() for your exemple.
Construct this function, reproducing the others tasks.
$model1 = JModel::getInstance('Mymodel1', 'MycomponentModel');
$model2 = JModel::getInstance('Mymodel2', 'MycomponentModel');

//Here, you can place a loop to execute on multiple items
$cid = $cid[0];

$model1->setId($cid);
$element = $model1->getData();

$element->id = 0; 				//Reset the ID
if($model2->save($element))		//COPY
	if ($model1->delete())		//DELETE PREVIOUS
	{
	}

Not tested
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Help with tables. 21 Mar 2012 06:14 #1697

Thank you again for the fast response, I've tried it but I don't know how it can work, I've pasted this on my 1st controller :
	
function movetoregistered(){
    $model1 = JModel::getInstance('Unregisteredpins', 'PinsModel');
    $model2 = JModel::getInstance('Registeredpins', 'PinsModel');

   //Here, you can place a loop to execute on multiple items
    $cid = $cid[0];

     $model1->setId($cid);
     $element = $model1->getData();

     $element->id = 0; 				//Reset the ID
        if($model2->save($element))		//COPY
	 if ($model1->delete()){		//DELETE PREVIOUS
	}
}

Is this right? And how can I put a button on the grid so they can check the item to be moved and by pressing it moves it? What files should be added? I have little php knowledge so please give me a hand if you would be so kind. I really appreciate everything.

Thank you again.
Daryll
Last Edit: 21 Mar 2012 06:16 by darylldelfin.
The administrator has disabled public write access.

Re: Help with tables. 21 Mar 2012 13:14 #1701

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
If you find by yourself, then you understand the mechanism and it is much better for everybody.
I give you another clue :

$cid is not initializated in your function !!

function movetoregistered()
{

//HERE YOU PROTECT FROM DIRECT CALL (need a unique session token)
	// Check for request forgeries
	JRequest::checkToken() or jexit( 'Invalid Token' );

//HERE YOU INITIALIZE $cid
	$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
	
//CHECK ACL (based on core.edit, but you can change it)
	if (!$this->can('core.edit', JText::_("JTOOLBAR_YOUR_NEW_TASK_FUNCTON_NAME") ))
		return;



//PROCESS THE COPY
    $model1 = JModel::getInstance('Unregisteredpins', 'PinsModel');
    $model2 = JModel::getInstance('Registeredpins', 'PinsModel');

   //Here, you can place a loop to execute on multiple items
    $cid = $cid[0];

     $model1->setId($cid);
     $element = $model1->getData();

	$element->id = 0; 				//Reset the ID

	$result = false;
        if($model2->save($element))		//COPY
	 if ($model1->delete()){		//DELETE PREVIOUS

		$result = true;
	}



	if ($result)
	{
		//Redirect if success
		
		$vars = array();
		JRequest::setVar( 'view'  , '...');
		JRequest::setVar( 'layout', '...' );
		//JRequest::setVar( 'cid', null );

		$this->setRedirect(XxxxHelper::urlRequest($vars));
	}
	else
	{
		//Redirect if fails ...
		//Reproduce a custom redirection if you want ...

		// OR keep the post and stay on page
	
		parent::display();
	}
		

}

Now, the next step is to place a custom toolbar button to launch this task.
For the moment I am not sure you can do it easily with JDom (must check it)

Try to get it out ;-)

You can try by url if you COMMENT the token check.
(If you don't, it will you output 'Invalid Token')
index.php?option=...&task=movetoregistered&cid[]=##

I also cannot help you more because I don't have really the time to test it.
Helping you is really a gift because I am passionated, but I should concentrate myself on the support only.
Coding is now a piece of cake
Last Edit: 21 Mar 2012 13:16 by admin.
The administrator has disabled public write access.

Re: Help with tables. 22 Mar 2012 09:06 #1708

Hi, thank you so much again for replying in my request! I have followed all you wrote for hours but I can't seem to make it work. :(

I have added this on my grid :

the link with this code :
<td class="Movetoregistered" style="text-align:center">
<a style='cursor:pointer;' onclick="javascript:listItemTask('cb0', 'movetoregistered')" title='Move to Registered'>Move to Registered</a></td>

*cb0 changes to cb1, cb2, cb3 and so on, like the edit and delete button on the grid.

and in my controllers/unregistered.php is this :
	function movetoregistered()
	{

//HERE YOU PROTECT FROM DIRECT CALL (need a unique session token)
	// Check for request forgeries
	//JRequest::checkToken() or jexit( 'Invalid Token' );

//HERE YOU INITIALIZE $cid
	$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
	
//CHECK ACL (based on core.edit, but you can change it)
	if (!$this->can('core.edit', JText::_("JTOOLBAR_YOUR_NEW_TASK_FUNCTON_NAME") ))
		return;



//PROCESS THE COPY
    $model1 = JModel::getInstance('Unregisteredpins', 'ListofpinsModel');
    $model2 = JModel::getInstance('Registeredpins', 'ListofpinsModel');

   //Here, you can place a loop to execute on multiple items
    $cid = $cid[0];

     $model1->setId($cid);
     $element = $model1->getData();

	$element->id = 0; 				//Reset the ID

	$result = false;
        if($model2->save($element))		//COPY
	 if ($model1->delete()){		//DELETE PREVIOUS

		$result = true;
	}



	if ($result)
	{
		//Redirect if success
		
		$vars = array();
		JRequest::setVar( 'view'  , 'unregisteredpins');
		JRequest::setVar( 'layout', 'default' );
		//JRequest::setVar( 'cid', null );

		$this->setRedirect(ListofpinsHelper::urlRequest($vars));
	}
	else
	{
		//Redirect if fails ...
		//Reproduce a custom redirection if you want ...

		// OR keep the post and stay on page
	
		parent::display();
	}
		

}

But when I click/execute it, it gives me a blank white page. I keep on trying to figure out what's wrong but sadly, I can't find anything. :( I am really grateful for the gift of helping someone like me and like you too, this is also my passion. but if you can help me this one last time, you would be my hero. :(


Really hoping for your reply,
Daryll
Last Edit: 22 Mar 2012 09:30 by darylldelfin.
The administrator has disabled public write access.

Re: Help with tables. 23 Mar 2012 07:35 #1714

Update : i have finally found my problem, it was in the getInstance.


Anyway, the save working but the delete function isn't. Any clues how I can make it work? thanks in advance.
The administrator has disabled public write access.

Re: Help with tables. 23 Mar 2012 08:40 #1715

Update : I have made it working by duplicating the delete() function.

Thank you so much for the help! :D
The administrator has disabled public write access.
Time to create page: 0.109 seconds

Get Started