Jump to content
TNG Community
RickW

Statistics - just one branch?

Recommended Posts

RickW

Is there a way to get the statistics page to look at just one branch, rather than the entire database? On my site, I have three branches, and if someone from one side of my family was looking at the site, I'm sure they would be interested in statistics only for that branch, not the entire database.

Thanks,

Rick

Share this post


Link to post
Share on other sites
RickW

Does Anyone have thoughts on this?

Share this post


Link to post
Share on other sites
bhemph

Rick,
     It is possible.  I have something set up that is working to do this, although I have some extra things in my changes.  The statistics piece of the mod is:
 

******* statistics.php *******
%target:statistics.php%

%location:%

$query = "SELECT count(id) as pcount FROM $people_table $wherestr";
%end:%
%replace:%
$nonullbranch = false;
if( $branchrestrict ) {
	if( $branchlimitrestrict ) {
		$nonullbranch=true;
		if( !$_SESSION['strict_branch'] && !($assignedbranch == "") ) {
			$nonullbranch=false;
		}
	}
	else {
		if( $_SESSION['strict_branch'] && !($assignedbranch == "") ) {
			$nonullbranch=true;
		}
	}
}
else {
	if( $_SESSION['strict_branch'] && !($assignedbranch == "") ) {
		$nonullbranch=true;
	}
}
if($tree) {
	//rights are limited to a tree or tree+branch
	if( $branchrestrict ) {
		if( strpos( $assignedbranch, '!' ) === false ) {
			if( $nonullbranch ) {
				$wherestr3 = " AND {$table}branch LIKE \"%$assignedbranch%\"";
			} else {
				$wherestr3 = " AND {$table}branch LIKE \"%$assignedbranch%\" OR {$table}branch = \"\"";
			}
		}
		else {
			$likelist = "";
			$loop=0;
			$branchpieces = explode('!', $assignedbranch);
			foreach($branchpieces as $minibranch) {
				if( $loop == 0 ) {
					$likelist = $minibranch;
					$loop++;
				} else {
					$loop++;
					$likelist .= "%\" OR {$table}branch LIKE \"%$minibranch";
				}
			}
			if( !$nonullbranch )
				$likelist .= "%\" OR {$table}branch = \"";
			else
				$likelist .= "%";
			$wherestr3 = " AND {$table}branch LIKE \"%$likelist\"";
		}
	}
}

$query = "SELECT count(id) as pcount FROM $people_table $wherestr $wherestr3";
%end:%

%location:%
$query = "SELECT count(id) as fcount FROM $families_table $wherestr";
%end:%
%replace:%
$query = "SELECT count(id) as fcount FROM $families_table $wherestr $wherestr3";
%end:%

%location:%
$query = "SELECT count(id) as pcount FROM $people_table WHERE sex = 'M' $wherestr2";
%end:%
%replace:%
$query = "SELECT count(id) as pcount FROM $people_table WHERE sex = 'M' $wherestr2 $wherestr3";
%end:%

%location:%
$query = "SELECT count(id) as pcount FROM $people_table WHERE sex = 'F' $wherestr2";
%end:%
%replace:%
$query = "SELECT count(id) as pcount FROM $people_table WHERE sex = 'F' $wherestr2 $wherestr3";
%end:%

%location:%
$query = "SELECT count(id) as pcount FROM $people_table WHERE living != 0 $wherestr2";
%end:%
%replace:%
$query = "SELECT count(id) as pcount FROM $people_table WHERE living != 0 $wherestr2 $wherestr3";
%end:%

%location:%
    WHERE birthdatetr != '0000-00-00' $wherestr2
%end:%
%replace:%
    WHERE birthdatetr != '0000-00-00' $wherestr2 $wherestr3
%end:%

%location:%
		$wherestr2
%end:%
%replace:%
		$wherestr2 $wherestr3
%end:%

%location:%
    WHERE birthdatetr != '0000-00-00' AND deathdatetr != '0000-00-00' $wherestr2
%end:%
%replace:%
    WHERE birthdatetr != '0000-00-00' AND deathdatetr != '0000-00-00' $wherestr2 $wherestr3
%end:%

******************************************


There are some extra pieces in there that go with some of my other changes, but that should give you an idea of the mod necessary to make the change you are looking for.

If you don't know coding to make a mod yourself, I think you just need to put the following lines between the first replace and the setting of $nonnullbranch:

$branchrestrict=true;
$branchlimitrestrict=true;
$_SESSION['strict_branch']=true;

 

Brent

Share this post


Link to post
Share on other sites
tngrlkrz

Brent,

I know it's untested, but I copied the script into a mod in TNG 11.1.2 and TNG 12.0.1.  In both cases, got these install errors:

ine 7: %target:statistics.php% verified
line 9: %location:% #1 not installed
line 68: %location:% #2 not installed
line 75: %location:% #3 not installed
line 82: %location:% #4 not installed
line 89: %location:% #5 not installed
line 96: %location:% #6 Bad target
line 103: %location:% #7 not unique
line 110: %location:% #8 not installed

Ron

 

Share this post


Link to post
Share on other sites
bhemph

Ron,
     Yes, it looks like I made more changes to the file than I got documented and put in the mod file.  The mod is at more of a not ready for alpha release yet, since I haven't gotten to reviewing it for mistakes in making the changes.  I hit a couple of snags and a rethink on how a couple of things were implemented that stalled my development of the total mod.  So it is more of my first comment of giving an idea of what is needed to make it work.

%location:%
    WHERE birthdatetr != '0000-00-00' $wherestr2
%end:%
%replace:%
    WHERE birthdatetr != '0000-00-00' $wherestr2 $wherestr3
%end:%

%location:%
		$wherestr2
    ORDER BY totaldays DESC";
%end:%
%replace:%
		$wherestr2 $wherestr3
    ORDER BY totaldays DESC";
%end:%

If you replace the error code section with this, does it work for you?

 

Brent

Share this post


Link to post
Share on other sites
tngrlkrz

Brent,

The mod location #6  doesn't exist in statistics.php in TNG12 or TNG11, so I omitted it.

%location:%
    WHERE birthdatetr != '0000-00-00' $wherestr2

The mod then installed, and I logged on with a user restricted to a branch, and the statistics actually seem to be correct for that users branch. So that location change seems to be a redundant or unnecessary change perhaps. 

Unique Last Names maybe could be made branch specific.

But overall, certainly on the right track!

Nice work!

Ron

Edited by tngrlkrz
update remarks

Share this post


Link to post
Share on other sites
RickW

Brent, thanks so much.  Sorry, I hadn't posted earlier to thank you.  This really helped.

Cheer,s

Rick

Share this post


Link to post
Share on other sites
GuyMarsh

HI.

From the Statistic.php, I created a new php page and removed and added code to suit what I was looking for.  Then I code link to my new php.  This is my results...  www.marshclarkefamilytree.com

<p><?php include ("showstat.php") ?></p>

I have attached the php page and i called it "showstat.php"

Regards,

Guy

showstat.php

Share this post


Link to post
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

×