i wanna to convert the php function in javascript
below is my code
function getpercentage($standard,$proid,$statename,$repid,$type)
{
$standardids=$standard;
$productid=$proid;
$allstandardsguid=array();
$bencharray=array();
$stddocs = array();
$finalbench=array();
$std = array();
for($g=0;$g<sizeof($standardids);$g++)
{
$string = file_get_contents("../correlation/standards/".$standardids[$g].".xml");
$doc = new DOMDocument();
$doc->loadXML($string);
$xpath = new DOMXpath($doc);
$coursecnt=$xpath->evaluate('count(//itm[@type="course"])');
$gradecnt=$xpath->evaluate('count(//itm[@type="grade"])');
if($coursecnt!=0)
{
$typ='course';
}
else if($gradecnt!=0)
{
$typ='grade';
}
$grades = $xpath->query("//itm[@type='".$typ."']");
$guids = $xpath->query("//itm[@type='".$typ."']//itm[@type='standard']/*");
$stdcnt = 0;
$h=0;
foreach($guids as $guid)
{
$gud = $guid->getAttribute('guid')."</br>";
$h++;
}
foreach($grades as $grade)
{
$nodes = $xpath->query("itm[@type='standard']",$grade);
$nodecnt = $nodecnt + $nodes->length;
if($nodes->length > 0) {
foreach ($nodes as $node) {
$guid = $node->getAttribute('guid');
$nodesinner = $xpath->query(".//itm[@type='standard']",$node);
$nodecnt = $nodecnt + $nodesinner->length;
if($nodesinner->length > 0) {
$j=0;
foreach ($nodesinner as $nodeinner) {
//echo $nodeinner->getAttribute('guid')."</br>";
if($nodeinner->getAttribute('guid') != '') {
$std[$j] = $nodeinner->getAttribute('guid');
$j++;
$stdcnt++;
}
}
$stdproduct[$guid] = $std;
unset($std);
}
$stdcnt++;
}
}
}
$allstandardsguid[$standardids[$g]]=$stdproduct;
unset($stdproduct);
foreach($grades as $grade)
{
$nodes = $xpath->query("//itm[@type='standard'][not(descendant::itm[@type='standard'])] ",$grade);
if($nodes->length > 0) {
foreach ($nodes as $node) {
$guid = $node->getAttribute('guid');
$bencharray[] = $guid;
}
}
}
$finalbench[]=$bencharray;
$benchindivdualcount[]=sizeof($bencharray);
unset($bencharray);
}
$nodes = $xpath->query("//itm[@type='standard']");
$nodecnt = $nodecnt + $nodes->length;
if($nodes->length > 0) {
$j = 0;
foreach ($nodes as $node) {
$tempstd[$j] = $node->getAttribute('guid');
$j++;
}
}
$productassets=array();
for($h=0;$h<sizeof($productid);$h++)
{
$string = file_get_contents("../correlation/products/".$productid[$h].".xml");
$stddocs = array();
$doc = new DOMDocument();
$doc->loadXML($string);
$xpath = new DOMXpath($doc);
$items = $xpath->query("//itm");
$psalign = array();
if($items->length > 0) {
$i = 0;
foreach($items as $item)
{
$guid = $item->getAttribute('guid');
$psalign[$i] = $guid;
$i++;
}
}
$productassets[$productid[$h]]=$psalign;
unset($psalign);
}
$tempbstdarray = array();
for($k=0;$k<sizeof($standardids);$k++)
{
$totalalign = 0;
$tempstdarray = array();
$mainstdarray = array();
for($p=0;$p<sizeof($productid);$p++)
{
$stdproduct=$allstandardsguid[$standardids[$k]];
$psalign=$productassets[$productid[$p]];
foreach($stdproduct as $key => $val) {
$result = array_intersect($stdproduct[$key],$psalign);
$tempstdarray = array_merge($tempstdarray, $result);
if(sizeof($result) > 0) {
$totalalign++;
$resultarray[]=array_values($result);
if(sizeof($stdproduct[$key]) > 0 ) {
$mainstdarray[] = $key;
}
}
unset($result);
}
unset($stdproduct);
unset($psalign);
}
$finalresultarray[]=$resultarray;
for($t=0;$t<sizeof($resultarray);$t++)
{
for($i=0;$i<sizeof($resultarray[$t]);$i++)
{
$newarray[]=$resultarray[$t][$i];
}
}
if(sizeof($newarray)!=0)
{
$percent= sizeof(array_unique($tempstdarray)) + sizeof(array_unique($mainstdarray));
$uni=array_values(array_unique($newarray));
$unipoint=sizeof(array_values(array_unique($newarray)));
}
else
{
$percent=0;
$uni=array(0);
$unipoint=0;
}
$percentage[]=$percent;
$uniquearray[]=$uni;
$uniquepoints[]=$unipoint;
unset($newarray);
unset($resultarray);
unset($percent);
unset($uni);
unset($unipoints);
}
$tempbmarr = array();
for($benchst=0;$benchst<sizeof($standardids);$benchst++)
{
$c=0;
for($pr=0;$pr<sizeof($productid);$pr++)
{
$bpsalign=$productassets[$productid[$pr]];
for($fin=0;$fin<sizeof($finalbench[$benchst]);$fin++)
{
$result = array_search($finalbench[$benchst][$fin],$bpsalign);
if(($result != '') and (!in_array($finalbench[$benchst][$fin],$tempbmarr)))
{
$tempbmarr[] = $finalbench[$benchst][$fin];
$c++;
}
}
}
$benpercenatge[]=$c;
unset($benresultarray);
unset($bpsalign);
unset($tempbmarr);
}
if($type==1){
return $percentage;
}
else if($type==2){
return $benpercenatge;
}
else if($type==3){
return $benchindivdualcount;
}
else if($type==4){
return $uniquearray;
}
else if($type==5){
return $uniquepoints;
}
}
No comments:
Post a Comment