Example #1
0
function displayPtCommentsSelector($htmlid, \lib\Objects\PowerTrail\PowerTrail $powerTrail, $selectedId = 0, $usr = null)
{
    $appContainer = lib\Objects\ApplicationContainer::Instance();
    if ($appContainer->getLoggedUser() === false) {
        return '';
    }
    $cachesFoundByUser = $powerTrail->getFoundCachsByUser($appContainer->getLoggedUser()->getUserId());
    $percetDemand = $powerTrail->getPerccentRequired();
    $ptId = $powerTrail->getId();
    if ($powerTrail->getCacheCount() != 0) {
        $percentUserFound = round(count($cachesFoundByUser) * 100 / $powerTrail->getCacheCount(), 2);
    } else {
        $percentUserFound = 0;
    }
    $commentsArr = lib\Controllers\PowerTrailController::getEntryTypes();
    $ptOwners = powerTrailBase::getPtOwners($ptId);
    $selector = '<select id="' . $htmlid . '" name="' . $htmlid . '">';
    foreach ($commentsArr as $id => $type) {
        if ($id == 2) {
            if ($percentUserFound < $percetDemand || powerTrailBase::checkUserConquestedPt($appContainer->getLoggedUser()->getUserId(), $ptId) > 0) {
                continue;
            }
            $selected = 'selected="selected"';
        }
        if (!isset($ptOwners[$appContainer->getLoggedUser()->getUserId()]) && ($id == 3 || $id == 4 || $id == 5)) {
            continue;
        }
        if ($id == 3 && $powerTrail->canBeOpened() === false && $powerTrail->getStatus() != \lib\Objects\PowerTrail\PowerTrail::STATUS_OPEN) {
            /* this PT cannot be opened */
            continue;
        }
        if ($id === \lib\Objects\PowerTrail\Log::TYPE_ADD_WARNING && $appContainer->getLoggedUser()->getIsAdmin() === false) {
            continue;
        }
        if (!isset($selected)) {
            $selected = '';
        }
        if ($selectedId == $id) {
            $selected = 'selected';
        }
        $selector .= '<option value="' . $id . '" ' . $selected . '>' . tr($type['translate']) . '</option>';
        unset($selected);
    }
    $selector .= '</select>';
    return $selector;
}