caneditrow list plugin

porlhews

Member
I have a form that several people are able to use. Each person can edit any of the rows on the list.

To prevent multiple people trying to edit the row at the same time, I've used the lockrow plugin and element (which is brilliant by the way).

When Person 1 edits the row, it successfully locks it.

As expected, Person 2 can click on the edit button and it will allow them to access the form; but they cannot submit the form.

I'd like to hide the edit form button from Person 2 when the row is locked by Person 1. To do this, I've used the caneditrow list plugin with the following code in the Advanced php tab:

PHP:
$lal = {table___lockrow_raw};
$lockid = explode(';',$lal);

$user = JFactory::getUser();
$myid = {$my->id};

$elapsed = time ( ) - $lockid[0];
//THE NEXT LINE SHOWS THE EDIT BOX IF THE ROW IS NOT LOCKED
if ($lal == 0){
return true;
}

else{
//THE NEXT LINE SHOWS THE EDIT BOX IF THE ROW WAS LOCKED BUT THE TIME DURATION OF THE LOCK HAS ELAPSED (30 minute duration)
if($elapsed > 30*60){
return true;
}

else{
//The NEXT LINE SHOWS THE EDIT BOX IF THE USER IS THE PERSON WHO LOCKED THE ROW
if($lockid[1] == $myid){
return true;
}

else{
return false;
}
}
}


From my testing, I think everything works as intended apart from the final if statement:

PHP:
if($lockid[1] == $myid)

Can anyone see why this doesn't work?

Thanks in advance for your help
 
You seem to have problems with your if-else statements.

The first condition is met here:
Code:
if ($lal == 0){
return true;
}
So it returns always true if the lock element exists and the further code will not be executed.

Something like this should do (not tested):
Code:
if ($lal == 0 || $elapsed > 30*60 || $lockid[1] == $myid) {
return true;
}
 
Hi Juuser,

Thanks for your help. I followed your advice, but it's not solved the problem.

I reduced the code to just a single if statement:

PHP:
if ($lockid[1] == $myid)

This doesn't appear to work; it doesn't identify the case where they are equal and always returns the same output as a result.

The rest of the conditions seem to work as expected.

is there a complexity I've missed about comparing an array element with a string?
 
Hmm, haven't faced similar issue.

What do you get with:

var_dump($lal);
exit;

or

var_dump($lockid[1]);
exit;
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top