Jump to content

MarkupAdminTable Links breaking the table


fredbob
 Share

Recommended Posts

Apologies I originally put this in the wrong sub forum.

I am having some trouble with my admin table, I am using the MarkupAdminTable module that is included with ProcessWire.

It is not outputting one of the columns properly when I use the links.

I will attach two images and their corresponding code to show what is happening.

 

The code bellow is how I want it to look but with links.


<?php   
$table = $modules->get("MarkupAdminDataTable");

function publishedCol($value) {
	if ($value == 1)
		return "Yes";
	else 
		return "No";
}

function pedigreeParentsName($value) {
	if (count($value->title) > 0)
		return $value->title;
	else
		return 'No Parent Defined';
}

function pedigreeParentsLink($value)
{
	if (count($value->title) > 0)
		return $value->url;
	else
		return $value->url;
}

/* breed id */
$breed = $input->get['id'];

$published = $input->get['pub'];
if (empty($breed)) {
	$table->headerRow( ["Dog", "Gender", "Sire", "Dam", "Breed", "Website display"] );
	
	foreach($pages->find("template=dog, sort=title") as $page){
	  $data = array(
		// Values with a sting key are converter to a link: title => link
		$page->title => $config->urls->admin."page/edit/?id=".$page->id,
		$page->dog_gender->title,
		pedigreeParentsName($page->father),
		pedigreeParentsName($page->mother),
		$page->parent->title,
		publishedCol($page->dog_create_page)
	  );
    	$table->row($data);
	}
}
else {	
	echo "<h2>$title</h2>";
	$table->headerRow( ["Dog", "Gender", "Sire", "Dam", "Website display"] );
	
	foreach($pages->find("template=dog, sort=title") as $page){
	  $data = array(
		// Values with a sting key are converter to a link: title => link
		$page->title => $config->urls->admin."page/edit/?id=".$page->id,
		$page->dog_gender->title,
		pedigreeParentsName($page->father),
		pedigreeParentsName($page->mother),
		publishedCol($page->dog_create_page)
	  );
    	$table->row($data);
	}
}


// $table->footerRow( $someArray );

echo $table->render();

?>

The code below shows the issue I am having when I add the links.


<?php   
$table = $modules->get("MarkupAdminDataTable");

function publishedCol($value) {
	if ($value == 1)
		return "Yes";
	else 
		return "No";
}

function pedigreeParentsName($value) {
	if (count($value->title) > 0)
		return $value->title;
	else
		return 'No Parent Defined';
}

function pedigreeParentsLink($value)
{
	if (count($value->title) > 0)
		return $value->url;
	else
		return $value->url;
}

/* breed id */
$breed = $input->get['id'];

$published = $input->get['pub'];
if (empty($breed)) {
	$table->headerRow( ["Dog", "Gender", "Sire", "Dam", "Breed", "Website display"] );
	
	foreach($pages->find("template=dog, sort=title") as $page){
	  $data = array(
		// Values with a sting key are converter to a link: title => link
		$page->title => $config->urls->admin."page/edit/?id=".$page->id,
		$page->dog_gender->title,
		pedigreeParentsName($page->father) => pedigreeParentsLink($page->father),
		pedigreeParentsName($page->mother) => pedigreeParentsLink($page->mother),
		$page->parent->title,
		publishedCol($page->dog_create_page)
	  );
    	$table->row($data);
	}
}
else {	
	echo "<h2>$title</h2>";
	$table->headerRow( ["Dog", "Gender", "Sire", "Dam", "Website display"] );
	
	foreach($pages->find("template=dog, sort=title") as $page){
	  $data = array(
		// Values with a sting key are converter to a link: title => link
		$page->title => $config->urls->admin."page/edit/?id=".$page->id,
		$page->dog_gender->title,
		pedigreeParentsName($page->father) => pedigreeParentsLink($page->father),
		pedigreeParentsName($page->mother) => pedigreeParentsLink($page->mother),
		publishedCol($page->dog_create_page)
	  );
    	$table->row($data);
	}
}


// $table->footerRow( $someArray );

echo $table->render();

?>

 

How it is supposed to look.PNG

Broken table with links .PNG

Broken table with links .PNG

How it is supposed to look.PNG

Link to comment
Share on other sites

It's hard to tell what problem you are having with the table. Is it that in some cases "No Parent Defined" is being replaced with "Our Corgis"?

I don't really understand this code:

function pedigreeParentsLink($value)
{
	if (count($value->title) > 0)
		return $value->url;
	else
		return $value->url;
}

 

Isn't this where you need to deal with no parent defined? Your conditional is returning the same result whether there is a title or not.

  • Like 1
Link to comment
Share on other sites

Actually, it's quite obvious once you know where to look. When you have entries where both mother and father are empty, you try to set two entries with identical titles of "No Parent Defined" in $data, and since this is a plain array, PHP will only use the last assignment for that array key.

So you'll have to make sure in some way that your titles differ for the "SIRE" and "DAM" fields (e.g. "No Sire Defined" vs. "No Dam defined").

  • Like 1
Link to comment
Share on other sites

8 minutes ago, BitPoet said:

and since this is a plain array, PHP will only use the last assignment for that array key

Ah yes - I hadn't got that far yet - just noticed the weird conditional.

The easiest option might be to just return the entire link/title as a string, rather than relying on the array key/value to create the link?

Try this:

function pedigreeParents($value)
{
    if ($value->id)
        return '<a href="'.$value->url.'">'.$value->title.'</a>';
    else
        return 'No Parent Defined';
}

Note that I have changed the conditional. I would assume that your father and mother page fields are set for "single page", or at least they should be, so the approach for checking if there is an ID works well.

You could even do something like this if you want separate "No Mother Defined" and "No Father Defined" entries where appropriate.

function pedigreeParents($value, $parent)
{
    if ($value->id)
        return '<a href="'.$value->$parent->url.'">'.$value->$parent->title.'</a>';
    else
        return 'No '.$parent.' Defined';
}

and call it like this:

pedigreeParents($page->father, 'Father');

and:

pedigreeParents($page->mother, 'Mother');

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...