Example #1
0
function GetTripDetail($tripId)
{
    //-----------------------------------------
    // selected trip
    $trip = new trip();
    $trip->retrieve($tripId);
    // get all waypoints for this trip
    $waypoint = new waypoint();
    $waypoints = $waypoint->getAllObjectsArray('tripid = ' . DB::qstr($tripId), null, 'objid');
    /*
    $wpdistance = '';
    $totaldistance = 0;
    $wptypical = '';
    $totaltypical = 0;
    $wpconsumption = '';
    $totalconsumption = 0;
    $wpaverage = '';
    $wpdrivetime = '';
    $totaldrivetime = 0;
    $wpchargetime = '';
    $totalchargetime = 0;
    $startdrivetime = $trip->att('theoreticalstarttime');
    $wpchargeneeded = 0;
    $wpchargestarted = 0;
    $wparrivaltime = '';
    $wpdeparturetime = '';
    $wpchargestart = 0;
    */
    // declare and initialize all variables
    $wpnbr = -1;
    $statusid = WaypointStatus::STATUS_LEFT;
    // build the waypoints array
    $dwp = null;
    //foreach ($waypoints as &$wp) {
    for ($i = 0; $i < count($waypoints); $i++) {
        // get the needed waypoints
        $wp = $waypoints[array_keys($waypoints)[$i]];
        if ($i > 0) {
            $prevwp = $waypoints[array_keys($waypoints)[$i - 1]];
        }
        if ($i < count($waypoints) - 1) {
            $nextwp = $waypoints[array_keys($waypoints)[$i + 1]];
        }
        // get the active waypoint (etappe) and status
        if ($statusid == WaypointStatus::STATUS_LEFT) {
            $wpnbr++;
            $statusid = $wp['statusid'];
        }
        // calculate all values
        // first position : O overview (effective), T theoretical, F formatting
        // second position : A distance, T Typical, V consumption G Average
        // third position : 1 waypoint-value, 2 sum
        CalculateDistance($i, $wp, $prevwp, $oa1, $ta1, $oa2, $ta2, $ot1, $tt1, $ot2, $tt2, $ov1, $tv1, $ov2, $tv2, $og1, $tg1, $og2, $tg2, $fa1, $fa2, $ft1, $ft2, $fv1, $fv2, $fg1, $fg2);
        $oa1 = format($oa1, 1);
        $foa2 = format($oa2, 1);
        $ta1 = format($ta1, 1);
        $fta2 = format($ta2, 1);
        $ot1 = format($ot1, 0);
        $fot2 = format($ot2, 0);
        $tt1 = format($tt1, 0);
        $ftt2 = format($tt2, 0);
        $ov1 = format($ov1, 1);
        $fov2 = format($ov2, 1);
        $tv1 = format($tv1, 1);
        $ftv2 = format($tv2, 1);
        $og1 = format($og1, 0);
        $fog2 = format($og2, 0);
        $tg1 = format($tg1, 0);
        $ftg2 = format($tg2, 0);
        CalculateTimes($trip, $i, $wp, $prevwp, $nextwp, $or1, $tr1, $or2, $tr2, $ol1, $tl1, $ol2, $tl2, $ocn, $tcn, $oat, $tat, $ovt, $tvt, $fr1, $fr2, $fl1, $fl2, $fcn, $fat, $fvt);
        // build the waypoint output result
        $dwp[] = array('id' => $wp['objid'], 'location' => '', 'name' => $wp['destination'], 'statusid' => $wp['statusid'], 'overview' => array('distance' => $oa1, 'totaldistance' => $foa2, 'typical' => $ot1, 'totaltypical' => $fot2, 'consumption' => $ov1, 'totalconsumption' => $fov2, 'average' => $og1, 'totalaverage' => $fog2, 'drivetime' => $or1, 'totaldrivetime' => $or2, 'chargetime' => $ol1, 'totalchargetime' => $ol2, 'chargeneeded' => $ocn, 'arrivaltime' => $oat, 'departuretime' => $ovt), 'theoretical' => array('distance' => $ta1, 'totaldistance' => $fta2, 'typical' => $tt1, 'totaltypical' => $ftt2, 'consumption' => $tv1, 'totalconsumption' => $ftv2, 'average' => $tg1, 'totalaverage' => $ftg2, 'drivetime' => $tr1, 'totaldrivetime' => $tr2, 'chargetime' => $tl1, 'totalchargetime' => $tl2, 'chargeneeded' => $tcn, 'arrivaltime' => $tat, 'departuretime' => $tvt), 'formating' => array('distance' => $fa1, 'totaldistance' => $fa2, 'typical' => $ft1, 'totaltypical' => $ft2, 'consumption' => $fv1, 'totalconsumption' => $fv2, 'average' => $fg1, 'totalaverage' => $fg2, 'drivetime' => $tr1, 'totaldrivetime' => $tr2, 'chargetime' => $tl1, 'totalchargetime' => $tl2, 'chargeneeded' => $tcn, 'arrivaltime' => $tat, 'departuretime' => $tvt));
        //$wpchargestarted = $wpchargeneeded;
    }
    // final result
    $d = array('id' => $tripId, 'desc' => $trip->att('name'), 'statusid' => $statusid, 'etape' => $wpnbr, 'waypoints' => $dwp);
    return array("key" => "trip", "data" => $d);
    //return $d;
}
Example #2
0
/**
 * Registers the buttons for title area of the trip profile page
 *
 * @param trip $trip
 */
function mytrips_register_profile_buttons($trip)
{
    $actions = array();
    // trip owners
    if ($trip->canEdit()) {
        // edit and invite
        $url = elgg_get_site_url() . "mytrips/edit/{$trip->getGUID()}";
        $actions[$url] = 'mytrips:edit';
        $url = elgg_get_site_url() . "mytrips/invite/{$trip->getGUID()}";
        $actions[$url] = 'mytrips:invite';
        $contar = 0;
        for ($i = 2; $i < count($trip->summaryPreOrderConfirmed); $i++) {
            if ($trip->summaryPreOrderConfirmed[$i] == 0) {
                $contar++;
            }
        }
        if (count($trip->preorder) > 2 || $contar > 0) {
            $url = elgg_get_site_url() . "mytrips/manageOrders/{$trip->getGUID()}";
            $actions[$url] = 'mytrips:manageOrders';
        }
    }
    //system_message("CREANDO BOTONES mytrips/libs/mytrips","NOTICE");
    // trip members
    if ($trip->isMember(elgg_get_logged_in_user_entity())) {
        if ($trip->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
            $user = elgg_get_logged_in_user_entity();
            $asientosOcupados = 0;
            $summaryPreOrderUserGuid = $trip->summaryPreOrderUserGuid;
            $summaryPreOrderConfirmed = $trip->summaryPreOrderConfirmed;
            $summaryPreOrderBultos = $trip->summaryPreOrderBultos;
            $summaryPreOrderTrayecto = $trip->summaryPreOrderTrayecto;
            $clave = array_search($user->guid, $summaryPreOrderUserGuid);
            /*for($i=2;$i<count($summaryPreOrderConfirmed);$i++)
            		{
            			if($summaryPreOrderConfirmed[$i]=="1") {
            				$asientosOcupados++;
            			}
            		}*/
            if ($summaryPreOrderConfirmed[$clave] == "1") {
                // Desconfirmed
                $url = elgg_get_site_url() . "action/mytrips/unconfirmtrip?trip_guid={$trip->getGUID()}";
                $url = elgg_add_action_tokens_to_url($url);
                $actions[$url] = 'mytrips:unconfirmTrip';
            } else {
                if (in_array($user->guid, $trip->preorder)) {
                    // despreorder
                    $url = elgg_get_site_url() . "action/mytrips/unpreorder?trip_guid={$trip->getGUID()}";
                    $url = elgg_add_action_tokens_to_url($url);
                    $actions[$url] = 'mytrips:unPreorder';
                    // confirmed
                    /*$url = elgg_get_site_url() . "action/mytrips/confirmtrip?trip_guid={$trip->getGUID()}";
                    		$url = elgg_add_action_tokens_to_url($url);
                    		$actions[$url] = 'mytrips:confirmTrip';*/
                } else {
                    if (in_array($user->guid, $trip->follower)) {
                        // leave trip
                        $url = elgg_get_site_url() . "action/mytrips/leave?trip_guid={$trip->getGUID()}";
                        $url = elgg_add_action_tokens_to_url($url);
                        $actions[$url] = 'mytrips:leave';
                        //calculo asientos para éste viaje
                        $owner = $trip->getOwnerEntity();
                        $asientosOcupados = 0;
                        if ($trip->preorder != "") {
                            $asientosOcupados += count($trip->preorder) - 2;
                        }
                        if ($trip->confirmed != "") {
                            $asientosOcupados += count($trip->confirmed) - 2;
                        }
                        $asientosLibres = 0;
                        //Si hay asientos disponibles para éste viaje podrá seguir haciendo el proceso
                        if ($owner->nAsientos != "") {
                            $asientosLibres = $owner->nAsientos - 1;
                        } else {
                            if ($trip->nplazas != "") {
                                $asientosLibres = $trip->nplazas - 1;
                            }
                        }
                        if ($asientosLibres >= $asientosOcupados) {
                            // preorder
                            $url = elgg_get_site_url() . "mytrips/summaryPreOrder/{$trip->getGUID()}";
                            $actions[$url] = 'mytrips:manageOrders';
                            /*
                            $url = elgg_get_site_url() . "action/mytrips/preorder?trip_guid={$trip->getGUID()}";
                            $url = elgg_add_action_tokens_to_url($url);
                            */
                            $actions[$url] = 'mytrips:preorder';
                        } else {
                            register_error(elgg_echo("mytrips:cantPreorderSeatMax"));
                        }
                    } else {
                        // leave trip
                        $url = elgg_get_site_url() . "action/mytrips/leave?trip_guid={$trip->getGUID()}";
                        $url = elgg_add_action_tokens_to_url($url);
                        $actions[$url] = 'mytrips:leave';
                        // preOrder
                        $url = elgg_get_site_url() . "action/mytrips/preorder?trip_guid={$trip->getGUID()}";
                        $url = elgg_add_action_tokens_to_url($url);
                        $actions[$url] = 'mytrips:preReservar';
                    }
                }
            }
        }
    } elseif (elgg_is_logged_in()) {
        // join - admins can always join.
        $url = elgg_get_site_url() . "action/mytrips/join?trip_guid={$trip->getGUID()}";
        $url = elgg_add_action_tokens_to_url($url);
        if ($trip->isPublicMembership() || $trip->canEdit()) {
            $actions[$url] = 'mytrips:join';
        } else {
            // request membership
            $actions[$url] = 'mytrips:joinrequest';
        }
    }
    if ($actions) {
        foreach ($actions as $url => $text) {
            elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
        }
    }
}
Example #3
0
function GetTripDetail($tripId)
{
    //-----------------------------------------
    // selected trip
    $trip = new trip();
    $trip->retrieve($tripId);
    $waypoint = new waypoint();
    $waypoints = $waypoint->getAllObjectsArray('tripid = ' . DB::qstr($tripId), null, 'objid');
    // make the result array
    $wpnbr = -1;
    $statusid = 4;
    $wpdistance = '';
    $totaldistance = 0;
    $wptypical = '';
    $totaltypical = 0;
    $wpconsumption = '';
    $totalconsumption = 0;
    $wpaverage = '';
    $wpdrivetime = '';
    $totaldrivetime = 0;
    $wpchargetime = '';
    $totalchargetime = 0;
    $startdrivetime = $trip->att('theoreticalstarttime');
    $wpchargeneeded = 0;
    $wpchargestarted = 0;
    $wparrivaltime = '';
    $wpdeparturetime = '';
    $wpchargestart = 0;
    // build the waypoints array
    $dwp = null;
    //foreach ($waypoints as &$wp) {
    for ($i = 0; $i < count($waypoints); $i++) {
        $wp = $waypoints[array_keys($waypoints)[$i]];
        //var_dump($wp); exit();
        if ($statusid == 4) {
            $wpnbr++;
            $statusid = $wp['statusid'];
        }
        if ($i == 0) {
            // first waypoint initialize counters
            if ($wp['statusid'] < 4) {
                $startdrivetime = $trip->att('date');
                $wpchargeneeded = $wp['theoreticalchargeneeded'];
            } else {
                $startdrivetime = $wp['departuretime'];
                $wpchargeneeded = $wp['departuretypical'];
            }
            $wpdeparturetime = date('H:i', $startdrivetime);
            $wpchargestarted = $wpchargeneeded;
        } else {
            // make running totals
            if ($wp['statusid'] == 0) {
                $wpdistance = $wp['theoreticaldistance'];
                $wptypical = $wp['theoreticaltypical'];
                $wpconsumption = $wp['theoreticalconsumption'];
                $wparrivaltime = $startdrivetime + $wp['theoreticaldrivetime'] * 60;
                $wpchargestart = $wpchargestarted - $wp['theoreticaltypical'];
            } else {
                $wpdistance = $wp['arrivaldistance'];
                $wptypical = $wpchargestarted - $wp['arrivaltypical'];
                $wpconsumption = $wp['arrivalconsumption'];
                $wparrivaltime = $wp['arrivaltime'];
                $wpchargestart = intval($wp['arrivaltypical']);
            }
            $totaldistance += $wpdistance;
            $totaltypical += $wptypical;
            $totalconsumption += $wpconsumption;
            $startdrivetime = $wparrivaltime;
            if ($wpdistance != 0) {
                $wpaverage = round($wpconsumption * 1000 / $wpdistance, 0);
            } else {
                $wpaverage = '';
            }
            if ($wp['statusid'] < 3) {
                //$startdrivetime = $wparrivaltime + ($wp['theoreticalchargetime'] * 60);
                $startdrivetime = $wparrivaltime + CalculateChargeTime(0, $wp['theoreticalchargeneeded']) * 60;
                $wpchargeneeded = $wp['theoreticalchargeneeded'];
            }
            if ($wp['statusid'] == 3) {
                $startdrivetime = $wp['chargeendtime'];
                $wpchargeneeded = $wp['chargeendtypical'];
            }
            if ($wp['statusid'] == 4) {
                $wpchargeneeded = $wp['departuretypical'];
                $startdrivetime = $wp['departuretime'];
            }
            // to calculate
            $wpdrivetime = $wp['theoreticaldrivetime'];
            $totaldrivetime += $wpdrivetime;
            //$wpchargetime = $wp['theoreticalchargetime'];
            $wpchargetime = CalculateChargeTime(0, $wp['theoreticalchargeneeded']);
            $totalchargetime += $wpchargetime;
            //format the output
            $wpdistance = number_format($wpdistance, 1, ',', '.');
            $wptypical = number_format($wptypical, 0);
            $wpconsumption = number_format($wpconsumption, 1, ',', '.');
            $wpdrivetime = date('H:i', mktime(0, $wpdrivetime, 0, 1, 1, 2000));
            if ($wpchargetime > 0) {
                $wpchargetime = date('H:i', mktime(0, $wpchargetime, 0, 1, 1, 2000));
            } else {
                $wpchargetime = '';
            }
            $wparrivaltime = date('H:i', $wparrivaltime);
            $wpdeparturetime = date('H:i', $startdrivetime);
        }
        // build the waypoint
        $dwp[] = array('id' => $wp['objid'], 'location' => '', 'name' => $wp['destination'], 'statusid' => $wp['statusid'], 'overview' => array('distance' => $wpdistance, 'totaldistance' => number_format($totaldistance, 1, ',', '.'), 'typical' => $wptypical, 'totaltypical' => $totaltypical, 'consumption' => $wpconsumption, 'totalconsumption' => number_format($totalconsumption, 1, ',', '.'), 'averageconsumption' => $wpaverage, 'drivetime' => $wpdrivetime, 'totaldrivetime' => date('H:i', mktime(0, $totaldrivetime, 0, 1, 1, 2000)), 'chargetime' => $wpchargetime, 'totalchargetime' => date('H:i', mktime(0, $totalchargetime, 0, 1, 1, 2000)), 'chargeneeded' => $wpchargeneeded, 'arrivaltime' => $wparrivaltime, 'departuretime' => $wpdeparturetime), 'theoretical' => array('arrival' => array('distance' => $wpdistance + 0.0, 'typical' => $wpchargestarted - $wp['theoreticaltypical'], 'consumption' => $wp['theoreticalconsumption'] + 0.0, 'time' => $wp['theoreticaldrivetime']), 'chargestart' => array('typical' => $wpchargestart, 'time' => ''), 'chargeend' => array('typical' => $wp['theoreticalchargeneeded'] + 0, 'time' => ''), 'departure' => array('distance' => 0.0, 'typical' => $wpchargeneeded + 0, 'consumption' => 0.0, 'time' => '')), 'effective' => array('arrival' => array('distance' => $wp['arrivaldistance'], 'typical' => $wp['arrivaltypical'], 'consumption' => $wp['arrivalconsumption'], 'time' => $wp['arrivaltime']), 'chargestart' => array('typical' => $wp['chargestarttypical'], 'time' => $wp['chargestarttime']), 'chargeend' => array('typical' => $wp['chargeendtypical'], 'time' => $wp['chargeendtime']), 'departure' => array('distance' => $wp['departuredistance'], 'typical' => $wp['departuretypical'], 'consumption' => $wp['departureconsumption'], 'time' => $wp['departuretime'])));
        $wpchargestarted = $wpchargeneeded;
    }
    // final result
    $d = array('id' => $tripId, 'desc' => $trip->att('name'), 'statusid' => $statusid, 'etape' => $wpnbr, 'waypoints' => $dwp);
    return array("key" => "trip", "data" => $d);
    //return $d;
}
Example #4
0
/**
 * Join a user to a trip, add river event, clean-up invitations
 *
 * @param trip $trip
 * @param ElggUser  $user
 * @return bool
 */
function mytrips_join_trip($trip, $user)
{
    // access ignore so user can be added to access collection of invisible trip
    $ia = elgg_set_ignore_access(TRUE);
    $result = $trip->join($user);
    elgg_set_ignore_access($ia);
    if ($result) {
        // flush user's access info so the collection is added
        get_access_list($user->guid, 0, true);
        // Remove any invite or join request flags
        remove_entity_relationship($trip->guid, 'invited', $user->guid);
        remove_entity_relationship($user->guid, 'membership_request', $trip->guid);
        elgg_create_river_item(array('view' => 'river/relationship/member/create', 'action_type' => 'join', 'subject_guid' => $user->guid, 'object_guid' => $trip->guid));
        return true;
    }
    return false;
}