Пример #1
0
 function getLensPowerListsFromArray($arr)
 {
     $params = JRequest::getVar('params', null);
     //print_r($params);
     // $toric = $params['toric'];
     $refraction = $params['refraction'][0];
     $clRx = $params['clRx'][0];
     $vertex = 1;
     if (isset($params['clRx'][0])) {
         $vertex = 0;
         $refraction = $clRx;
     }
     if (!isset($refraction)) {
         return null;
     }
     //print_r($refraction);
     $user =& JFactory::getUser();
     $query = "\n(SELECT pnl.pn_tid, pnl.pn_name as name, pnl.pn_image as image, pnlc.pn_comp_name as company, pnl.pn_cosmetic,  pnl.pn_toric as toric, pnl.pn_dk, pop.score, pnl.pn_discontinued as discontinued,  1 AS favorite\nFROM pn_lenses pnl \nLEFT JOIN pn_lenses_companies pnlc ON (pnl.pn_comp_id = pnlc.pn_comp_tid) \nLEFT JOIN pn_lenses_polymers pnlp ON (pnl.pn_poly_id = pnlp.pn_poly_tid) \nLEFT JOIN pn_lenses_user_favorites c ON c.item_id = pnl.pn_tid \nLEFT JOIN pn_lenses_popularity pop ON (pop.itemID = pnl.pn_tid) \nWHERE c.user_id = {$user->id} AND c. favorite = 1\nAND pnl.pn_tid IN (" . implode(',', $arr) . ") \nAND pnl.pn_name NOT LIKE '%synergeye%' AND pnl.pn_name NOT LIKE '%softperm%' \nAND pn_bifocal = 0)\nUNION DISTINCT\n(SELECT pnl.pn_tid, pnl.pn_name as name, pnl.pn_image as image, pnlc.pn_comp_name as company, pnl.pn_cosmetic, pnl.pn_toric as toric,  pnl.pn_dk, pop.score, pnl.pn_discontinued as discontinued, 0 as favorite\nFROM pn_lenses pnl \nLEFT JOIN pn_lenses_companies pnlc ON (pnl.pn_comp_id = pnlc.pn_comp_tid) \nLEFT JOIN pn_lenses_polymers pnlp ON (pnl.pn_poly_id = pnlp.pn_poly_tid) \nLEFT JOIN pn_lenses_popularity pop ON (pop.itemID = pnl.pn_tid) \nWHERE NOT EXISTS (SELECT *\n                   FROM   pn_lenses_user_favorites f\n                   WHERE  f.item_id = pnl.pn_tid\nAND f.user_id = {$user->id} AND f.favorite=1\n)\nAND pnl.pn_tid IN (" . implode(',', $arr) . ") \nAND pnl.pn_name NOT LIKE '%synergeye%' AND pnl.pn_name NOT LIKE '%softperm%' \nAND pn_bifocal = 0)\n\n order by favorite DESC, score DESC, name ASC";
     $db = databaseObj();
     $db->setQuery($query);
     $lenses = $db->loadAssocList();
     //echo $query;
     //print_r($lenses);
     $returnLenses = array();
     if (!empty($lenses)) {
         foreach ($lenses as $k => $v) {
             //comvert image string to an array
             if (strstr($v['image'], ',')) {
                 $images = explode(',', $v['image']);
                 $v['image'] = trim($images[count($images) - 1]);
             }
             //get an array for this lens's powers
             $powerQuery = "SELECT lpl.sphere, lpl.cylinder, lpl.axis, lp.diameter, lp.baseCurve FROM pn_lenses_power_lists lpl LEFT JOIN pn_lenses_powers lp ON lpl.id=lp.id WHERE lpl.lensID = " . $v['pn_tid'];
             $db->setQuery($powerQuery);
             $lensPowerArr = $db->loadAssocList();
             //print_r($lensPowerArr[0]);
             //$lensPowers = $this->getPowerArrayForLens ($v['pn_tid']);
             $resultArray = getBestCLPowerForParams($refraction, $lensPowerArr, $v['toric'], $vertex);
             foreach ($resultArray as $oneVariation) {
                 // 					echo "<br/>vari:<br/>";
                 // 					print_r ($oneVariation);
                 // 					echo "<br/>lens:<br/>";
                 // 					print_r ($v);
                 $row = array_merge($v, $oneVariation);
                 array_push($returnLenses, $row);
             }
             //print_r($resultArray);
             //
             //print_r($returnLenses);
         }
     }
     usort($returnLenses, "vaSorter");
     //print_r($returnLenses);
     /*array_multisort($returnLenses['va'], SORT_ASC, SORT_NUMERIC,
       $returnLenses['favorite'], SORT_NUMERIC, SORT_DESC);*/
     //filter out the worst lenses
     $returnLenses = removeVAOutliers($returnLenses);
     return $returnLenses;
 }
Пример #2
0
function getBestCLPowerForParams($refraction, $lensPowerArray, $toric)
{
    //print_r ($lensPowerArray);
    //echo "<br/>$refraction<br/>";
    //get some info about the desired power
    $mr = rxStringBreaker($refraction);
    // break it down into an Rx object
    $bestCLrx = $mr->diffVertex(0);
    //vertex to the corneal plane
    $bestSph = $bestCLrx->sphM();
    $bestCyl = $bestCLrx->cylM();
    $bestAxis = $bestCLrx->axisM();
    $targetSph = $bestSph;
    if ($toric == "") {
        if ($bestCyl <= -0.75) {
            $toric = 1;
        }
        if ($bestCyl > -0.75) {
            $toric = 0;
        }
    }
    //an array of lenses rxs that are the closest
    $bestRxArray = array();
    //we'll only want to return the lens that provides the best vision.  For each lens we'll
    //$bestVA = 10000;
    if ($toric == 0) {
        //if it's not a toric lens we'll need the spherical equivalent
        $targetSph = $bestCLrx->sphericalEquivalent();
        foreach ($lensPowerArray as $paramList) {
            $rxArray = array();
            //if the parameters are not listed as an array (but are still in a comma-separated list), explode it into an array
            if (!is_array($paramList['sphere'])) {
                $paramList['sphere'] = explode(",", $paramList['sphere']);
            }
            $rxArray['sphere'] = closestValue($paramList['sphere'], $targetSph);
            //echo $rxArray['sphere'] ;
            $rxArray['cylinder'] = null;
            $rxArray['axis'] = null;
            $rxArray['baseCurve'] = $paramList['baseCurve'];
            $rxArray['diameter'] = $paramList['diameter'];
            //create an RxObject
            $clRx = new RxObject($rxArray['sphere']);
            $rxArray['fullRx'] = $clRx->prettyStringMinus();
            $rxArray['bestRx'] = $bestCLrx->prettyStringMinus();
            //the diff between this Rx and the ideal Rx
            $rxdiff = $bestCLrx->subtractRx($clRx);
            $rxArray['rxDiff'] = $rxdiff->prettyStringMinus();
            //echo $rxdiff  ->prettyStringMinus();
            $rxArray['va'] = (int) VAFromCorrection($rxdiff);
            $rxArray['chartVA'] = eyeChartVA($rxArray['va']);
            $rxArray['variation'] = $paramList['variation'];
            array_push($bestRxArray, $rxArray);
        }
    } else {
        if ($toric == 1) {
            //if it IS a toric lens...
            foreach ($lensPowerArray as $paramList) {
                $rxArray = array();
                //if the parameters are not listed as an array (but are still in a comma-separated list), explode it into an array
                if (!is_array($paramList['sphere'])) {
                    $paramList['sphere'] = explode(",", $paramList['sphere']);
                }
                if (!is_array($paramList['axis'])) {
                    $paramList['axis'] = explode(",", $paramList['axis']);
                }
                if (!is_array($paramList['cylinder'])) {
                    $paramList['cylinder'] = explode(",", $paramList['cylinder']);
                }
                //first, find the closest cyl power.
                $cyl = closestValue($paramList['cylinder'], $bestCyl);
                //echo "<br/>".$cyl;
                // If the closest $cyl is less than the $bestCyl the $targetSph will need to be adjusted
                //echo "<br/>targetSphere1: $targetSph";
                $adjSph = $targetSph + ($bestCyl - $cyl) / 2;
                //echo "<br/>adjSph: $adjSph";
                $rxArray['sphere'] = closestValue($paramList['sphere'], $adjSph);
                $rxArray['cylinder'] = $cyl;
                $rxArray['axis'] = closestValue($paramList['axis'], $bestAxis);
                $rxArray['baseCurve'] = $paramList['baseCurve'];
                $rxArray['diameter'] = $paramList['diameter'];
                //create an RxObject
                $clRx = new RxObject($rxArray['sphere'], $rxArray['cylinder'], $rxArray['axis']);
                $rxArray['fullRx'] = $clRx->prettyStringMinus();
                $rxArray['bestRx'] = $bestCLrx->prettyStringMinus();
                //the diff between this and the ideal Rx
                $rxdiff = $bestCLrx->subtractRx($clRx);
                $rxArray['rxDiff'] = $rxdiff->prettyStringMinus();
                $rxArray['va'] = (int) VAFromCorrection($rxdiff);
                $rxArray['chartVA'] = eyeChartVA($rxArray['va']);
                $rxArray['variation'] = $paramList['variation'];
                array_push($bestRxArray, $rxArray);
            }
        }
    }
    //filter out the outliers
    $bestRxArray = removeVAOutliers($bestRxArray);
    //print_r ( $bestRxArray);
    //echo "<p> </p>";
    return $bestRxArray;
}