Example #1
0
 static function find($recipe_id, $dbh)
 {
     $stmt = $dbh->prepare("select * from " . Steps::$tableName . " WHERE recipe_id = :id ORDER BY stepno  ASC ");
     $stmt->bindParam(":id", $recipe_id);
     $stmt->execute();
     $result = array();
     while ($row = $stmt->fetch()) {
         $p = new Steps();
         $p->copyFromRow($row);
         $result[] = $p;
     }
     return $result;
 }
Example #2
0
 function copyStepsFromRow($row)
 {
     if (isset($row['step'])) {
         $arr = array();
         $i = 1;
         foreach ($row['step'] as $key => $value) {
             if ($value != "") {
                 $x = array("recipe_id" => $this->id, "stepno" => $i, "text" => $value);
                 $n = new Steps();
                 $n->copyFromRow($x);
                 array_push($arr, $n);
                 $i++;
             }
         }
         $this->steps = $arr;
     }
 }
Example #3
0
 public function advanceTo($requestStep, $params)
 {
     try {
         if ($requestStep == $this->token) {
             throw new \Exception("Can't advance to same step");
         }
         $canAdvanceTo = $this->steps->getStep($this->token);
         if (in_array($requestStep, $canAdvanceTo)) {
             $this->token = $requestStep;
             return $requestStep;
         } elseif (array_key_exists($requestStep, $canAdvanceTo)) {
             $conditionProcessor = new ConditionProcessor($canAdvanceTo[$requestStep]);
             if ($conditionProcessor->prepare()->process($params)) {
                 $this->token = $requestStep;
                 return $requestStep;
             }
             throw new \Exception("Can't go to this step");
         } else {
             throw new \Exception("Can't go to this step");
         }
     } catch (\Exception $ex) {
         throw new \Exception($ex->getMessage());
     }
 }
function indivmostlikeme($feedid)
{
    global $feedids;
    global $peergroup;
    global $meuqni;
    global $melifeavglist;
    global $perfeed;
    // NEED TO SETUP UPFRONT LOGIC IS BATCH OR REFRESH FOR PARTICUALR INDIVIDUAL?
    // what is feed id of this individual
    //$feedindv  = 2;  // need to GET_(feed_id) or something
    $date = time();
    // need list of all feeds
    feedarray();
    //$feedids = Array ( '1' => '1', '2' => '2', '3' => '3', '4' => '4', '5' => '5', '6' => '6', '7' => '7', '8' => '8', '9' => '9', '10' => '10', '11' => '11', '12' => '12', '13' => '13', '14' => '14', '15' => '15', '16' => '16', '17' => '17', '18' => '18', '19' => '19', '20' => '20');//, '21' => '21', '22' => '23', '23' => '24', '24' => '25', '25' => '26', '26' => '27', '27' => '28', '29' => '29', '30' => '31', '31' => '31', '32' => '32', '33' => '33', '34' => '34', '35' => '35', '36' => '36', '37' => '37', '38' => '38', '39' => '39', '40' => '40');
    //print_r($feedids);
    //prepmelife ($feedids);
    $lifelisttop = toplifefivearray($feedid);
    //print_r($lifelisttop);
    // call melifedata array with list of feed ids mepath needs data on
    //how many individual, count feedarray
    $indpeers = count($feedids);
    //echo $indpeers.'nofeeds<br />';
    //80-20 rule
    $peertwenty = $indpeers * 0.1;
    //echo $peertwenty.'20% feeds<br />';
    // batch per lifestlyeid  save memory getting over maxed
    foreach ($lifelisttop as $unid) {
        $perdiffarr = '';
        $newadf = 1;
        $perdiffarr = melifearray($unid, $newadf, $feedid);
        //print_r($melifeavglist);
        //print_r($perdiffarr);
        //echo 'break<br /><br />';
        // now look up the individuals melife stat and then order all indivials stas and then use 80-20 rules, ie take20% of indivudals clostest to that individual.  Then display results, have any post been published from this peergroup of in the last 24hrs?
        // new list of feeds that have lifestyle in top5 $perfeed;
        //foreach ($feedids as $fma)  {
        //foreach ($perfeed[$unid] as $pfma)  {
        $steps = '';
        // form an array for all the lifestyleids, count no. feeds find out 20% of that number, find out individuals average then identify feeds 10% plus this indivudals avarage and -10% from their average
        //print_r($melifeavglist[$mell]);
        $mecou = count($perdiffarr[$unid]);
        //echo $mecou;
        if ($mecou > 0) {
            //gives us array containing the individuals average
            // next need to find -10 and +10% either side of that position
            //  now need to count back and forward along the array to pick out peer list.
            $steps = new Steps();
            $poslist = array();
            foreach ($perdiffarr[$unid] as $key => $reindex) {
                $steps->add($key);
            }
            //echo 'listorder';
            //print_r($steps->all);
            $feedindv = $feedid;
            //echo 'indiv feedid'.$feedindv.'<br /><br />';
            // set this individuals avg. position
            $steps->setCurrent($feedindv);
            //print_r($steps);
            for ($i = 1; $i <= $peertwenty; $i++) {
                //echo $i;
                //echo $steps->getNext().'<br>';
                $newset = $steps->getNext();
                //echo $newset.'newno<br /><br >';
                $indivset = $steps->setCurrent($newset);
                //echo $indivset.'indvid set';
                if (strlen($newset) > 0) {
                    $poslist[] = $newset;
                }
            }
            //print_r($poslist);
            $steps->setCurrent($feedindv);
            for ($i = 1; $i <= $peertwenty; $i++) {
                //echo $i;
                //echo $steps->getPrev().'<br>';
                $newset = $steps->getPrev();
                $indivset = $steps->setCurrent($newset);
                if (strlen($newset) > 0) {
                    $poslist[] = $newset;
                }
            }
            //echo 'postlist';
            //print_r($poslist);
            //echo 'postlist';
            $arraycou = count($poslist);
            //echo $arraycou.'numcou';
            // save to perpeers table to have on demand quickly and update on a per individual basis
            if ($arraycou > 0) {
                //print_r($poslist);
                //echo 'heelo';
                $peerinslist = '';
                $rank = '';
                foreach ($poslist as $peerid) {
                    $rank++;
                    $peerinslist .= "('{$feedid}', '{$rank}', '{$date}', '{$unid}', '{$peerid}' ), ";
                }
                $peerinslist = substr($peerinslist, 0, strLen($peerinslist) - 2);
                //this will eat the last comma
                //echo $peerinslist.'insertcode';
                if (strLen($peerinslist) > 0) {
                    $db->query = " INSERT INTO " . RSSDATA . ".perpeers (feedid, rank, date, idlifestart, peerid) VALUES ";
                    $db->query .= $peerinslist;
                    //echo $db->query;
                    $resultinsqual = mysql_query($db->query) or die(mysql_error());
                }
                //closes if
            }
            // closes if anything to insert
        }
        // closes if no melifedata
        //}  // closes foreach loop ie eachfeed.
    }
    // closes for each unqiue lifestyle definition
}