Esta es , le quite las consultas para que no quedara tan larga,
Código PHP:
<?php
session_start();
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
class Missions{
private $conn;
private $idufb;
function __construct($link) {
$this->conn = $link;
$this->idufb = $_SESSION['id'];
}
public function verifyInvitedFriend(){
try{
$mission_complete = array();
$id_misions = array();
$stmt = $this->getObjectMission( 9 );
if($stmt)
{
$result_update_current = $this->conn->prepare($this->update_action);
$j=0;
while( $row = $stmt->fetchObject() )
{
$id_misions[$j] = $row->idmissions;
$tmp_actions = json_decode($row->current);
for( $i = 0;$i < count( $tmp_actions ); $i++ )
{
$tmp_action = json_decode($tmp_actions[$i]);
if( $tmp_action->idaction == 9 && $tmp_action->current < $tmp_action->amount )
{
$id_misions[$j] = $row->idmissions;
++$tmp_action->current;
$tmp_actions[$i] = json_encode($tmp_action);
$result_update_current->bindParam(1, json_encode($tmp_actions));
$result_update_current->bindParam(2, $this->idufb);
$result_update_current->bindParam(3, $row->idactivemissions);
//if(false)
if(!$result_update_current->execute())
{
throw new Exception("Problema en la consulta");
}
}else{
}
}
++$j;
}
$ids_misions = implode(',',$id_misions);
$mission_complete = $this->getMission($ids_misions) ;
return $mission_complete;
}else{
return $mission_complete;
}
} catch (Exception $e){
}
}
private function getObjectMission($idaction){
try{
$mission_complete->actions = array();
$result = $this->conn->prepare($query1);
$result->bindParam(1,$idaction);
$result->bindParam(2,$this->idufb);
$result->execute();
$row = $result->fetchObject();
if($row->num!=0)
{
$result2 = $this->conn->prepare($query2);
$result2->bindParam(1,$idaction);
$result2->bindParam(2,$this->idufb);
$result2->execute();
return $result2;
}else{
return false;
}
}catch(Exception $e){
}
}
private function getMission( $idmissions ){
try{
$stmt_activemission = $this->conn->prepare( $query_activemission );
$stmt_activemission->bindParam( 1 , $this->idufb );
$result_activemission = $stmt_activemission->execute();
if( $result_activemission )
{
while( $row_activemission = $stmt_activemission->fetchObject() )
{
$complete = false;
$stmt_select->bindParam( 1 , $row_activemission->idmissions);
$result_AM = $stmt_select->execute();
$actions_current = json_decode( $row_activemission->current );
$i=0;
$rewardType = explode( '_' , $row_activemission->recompense );
while( $row = $stmt_select->fetchObject() )
{
if( $row_activemission->completed == 0 )
{
$actions = array();
$complete = true;
$NewMissions = array();
break;
}else{
$NewMissions = array();
$current = json_decode($actions_current[$i]);
$actions[] = array('idaction' => $row->idaction,
'description' => $row->description,
'amount' => $current->amount,
'current' => $current->current);
}
++$i;
}
$missions[]=array(
'idmission' => $row_activemission->idmissions,
'name' => $row_activemission->name,
'reward' => $rewardType[0],
'rewardType' => $rewardType[1],
'actions' => $actions,
'complete' => $complete,
'missions' => $NewMissions
);
$actions = array();
}
}
}catch(Exception $e){
}
return $missions;
}
public function getMissionsOnTime(){
try{
$mission = array();
$stmt = $this->conn->prepare($query);
$stmt->bindParam(1, $this->idufb);
$result = $stmt->execute();
if($result)
{
$row = $stmt->fetchObject();
if( $row->num < 4 )
{
return NUM_MISSIONS - $row->num ;
}else{
return false;
}
}
}catch(Exception $e){
}
}
}
?>
saludos