/** * 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')); } } }