<?php

use_helper('Pagination', 'GeoJson');
$id = $sf_params->get('id');
$lang = $sf_params->get('lang');
$module = $sf_context->getModuleName();
$format = $sf_data->getRaw('format');
$use_keys = in_array('keys', $format);
$text_html = in_array('html', $format);
$add_gpx_track = in_array('track', $format);
$add_all_fields = in_array('full', $format);
$add_conditions = $add_all_fields || in_array('cond', $format);
$add_text = !in_array('notext', $format);
if (!isset($items) && $nb_results > 0) {
    $items = $pager->getResults('array', ESC_RAW);
    $items = Language::parseListItems($items, c2cTools::module2model($module));
} elseif ($nb_results == 0) {
    $items = array();
    $totalItems = $startIndex = $count = $hasPreviousPage = $hasNextPage = 0;
}
if (isset($pager)) {
    $totalItems = $pager->getNbResults();
    $startIndex = $pager->getMaxPerPage() * ($pager->getPage() - 1) + 1;
    $count = min($pager->getMaxPerPage(), $pager->getNbResults() - ($pager->getPage() - 1) * $pager->getMaxPerPage());
    $hasPreviousPage = $pager->getPage() != 1;
    $hasNextPage = $pager->getPage() != $pager->getLastPage() && $nb_results;
}
// compute prev and next uris
if ($hasPreviousPage || $hasNextPage) {
    $uri = _addUrlParameters(_getBaseUri(), array('page'));
    $uri .= _getSeparator($uri) . 'page=';
 public function executeWidget()
 {
     $this->div = $this->getRequestParameter('div', 'c2cwgt');
     $module = $this->getModuleName();
     $model = $this->model_class;
     $criteria = $this->getListCriteria($model);
     if ($criteria !== 'no_result' && $module != 'documents') {
         $sort = call_user_func(array('Document', 'getListSortCriteria'), $model);
         $page = $this->getRequestParameter('page', 1);
         $infos = call_user_func(array('Document', 'browse'), $model, $sort, $criteria, array('widget'), $page);
         $nb_results = $infos['nb_results'];
         $this->pager = $infos['pager'];
         $this->query = $infos['query'];
         if ($nb_results > 0) {
             $items = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
             $items = Language::parseListItems($items, $model);
         } else {
             $items = array();
         }
     } else {
         $nb_results = 0;
         $items = array();
     }
     $this->nb_results = $nb_results;
     $this->items = $items;
     $this->setLayout(false);
     $this->setTemplate('../../documents/templates/widget');
     $this->setCacheControl();
 }
 /**
  * Executes list action, adding parkings linked to routes
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $routes = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     // if they are criterias on the summit (snam, srnam, salt, styp)
     // we might have only some of the associated summits and not the 'best one' (ticket #337)
     // so we must add a new request to get the summits, display the best one and add a note to explain that the
     // other summit is associated
     // FIXME would be nice to put all in a single request (before), but I didn't manage to do it
     // TODO not working right now
     //if ($this->hasRequestParameter('snam') || $this->hasRequestParameter('srnam') ||
     //    $this->hasRequestParameter('salt') || $this->hasRequestParameter('styp'))
     //{
     // $routes = Route::addBestSummitName($routes, '');
     //}
     $timer = new sfTimer();
     Parking::addAssociatedParkings($routes, 'pr');
     // add associated parkings infos to $routes
     c2cActions::statsdTiming('parking.addAssociatedParkings', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($routes, 'ro', true);
     // number of associated outings
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($routes);
     $this->items = Language::parseListItems($routes, 'Route');
 }
 /**
  * Executes list action, adding ratings from routes linked to outings
  */
 public function executeList()
 {
     // redirect to user outings list if connected and if myoutings criteria is set
     if ($this->getUser()->isConnected() && $this->getRequestParameter('myoutings')) {
         sfLoader::loadHelpers(array('Pagination'));
         $user_id = $this->getUser()->getId();
         $this->redirect(_addUrlParameters(_getBaseUri(), array('myoutings'), array('users' => $user_id)));
     }
     // TODO something to do if outings where filtered on route ratings?
     parent::executeList();
     $format = $this->format;
     if (in_array('cond', $format) && !in_array('json', $format)) {
         $this->setTemplate('conditions');
         if (in_array('full', $format)) {
             $this->setPageTitle($this->__('conditions and comments'));
         } else {
             $this->setPageTitle($this->__('recent conditions'));
         }
     }
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $show_images = $this->show_images;
     $timer = new sfTimer();
     $outings = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     $outings = Outing::getAssociatedCreatorData($outings);
     // retrieve outing creator names
     c2cActions::statsdTiming('outing.getAssociatedCreatorData', $timer->getElapsedTime());
     $timer = new sfTimer();
     $outings = Outing::getAssociatedRoutesData($outings);
     // retrieve associated route ratings
     c2cActions::statsdTiming('outing.getAssociatedRoutesData', $timer->getElapsedTime());
     if (!in_array('list', $format)) {
         $timer = new sfTimer();
         $outings = Language::getTheBestForAssociatedAreas($outings);
         c2cActions::statsdTiming('language.getTheBestForAssociatedAreas', $timer->getElapsedTime());
     }
     // add images infos
     if ($show_images) {
         $timer = new sfTimer();
         Image::addAssociatedImages($outings, 'oi');
         c2cActions::statsdTiming('image.addAssociatedImages', $timer->getElapsedTime());
     }
     Area::sortAssociatedAreas($outings);
     $this->items = Language::parseListItems($outings, 'Outing', !$show_images);
 }
 /**
  * Executes list action
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $summits = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($summits, 'sr', true);
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($summits);
     $this->items = Language::parseListItems($summits, 'Summit');
 }
 /**
  * Executes list action
  */
 public function executeList()
 {
     parent::executeList();
     $nb_results = $this->nb_results;
     if ($nb_results == 0) {
         return;
     }
     $timer = new sfTimer();
     $sites = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
     c2cActions::statsdTiming('pager.getResults', $timer->getElapsedTime());
     $timer = new sfTimer();
     Parking::addAssociatedParkings($sites, 'pt');
     // add associated parkings infos to $sites
     c2cActions::statsdTiming('parking.addAssociatedParkings', $timer->getElapsedTime());
     $timer = new sfTimer();
     Document::countAssociatedDocuments($sites, 'to', true);
     c2cActions::statsdTiming('document.countAssociatedDocuments', $timer->getElapsedTime());
     Area::sortAssociatedAreas($sites);
     $this->items = Language::parseListItems($sites, 'Site');
 }
echo display_title(__('User image management'), $sf_params->get('module'), false);
echo '<div id="nav_space">&nbsp;</div>';
include_partial('documents/nav4home');
echo display_content_top('list_content');
echo start_content_tag('images_content');
echo javascript_tag('lightbox_msgs = Array("' . __('View image details') . '","' . __('View original image') . '");');
echo '<p class="mandatory_fields_warning">' . __('manage images presentation');
$items = $pager->getResults('array', ESC_RAW);
if (count($items) == 0) {
    echo '<br /><br />' . __('All your images are already collaborative') . '</p>';
} else {
    echo '</p>';
    $pager_navigation = pager_navigation($pager);
    echo $pager_navigation;
    echo '<div class="clearer"></div>';
    $items = Language::parseListItems($items, 'Image');
    echo form_tag("@user_manage_images?module=users", array('onsubmit' => 'C2C.submitonce(this)', 'id' => 'editform'));
    foreach ($items as $item) {
        ?>
    <div class="thumb_data manageimages_list">
    <?php 
        $i18n_item = $item['ImageI18n'][0];
        $title = $i18n_item['name'];
        $image_type = $item['image_type'];
        $filename = $item['filename'];
        $thumb_url = image_url($filename, 'small');
        $slug = make_slug($i18n_item['name']);
        $image_id = $item['id'];
        $image_route = '@document_by_id_lang_slug?module=images&id=' . $image_id . '&lang=' . $i18n_item['culture'] . '&slug=' . $slug;
        echo link_to(image_tag($thumb_url, array('class' => 'img', 'alt' => $title)), absolute_link(image_url($filename, 'big', true), true), array('title' => $title, 'data-lightbox' => 'document_images', 'class' => 'view_big', 'id' => 'lightbox_' . $image_id . '_' . $image_type));
        ?>
 /**  
  * Executes list action.
  * Overrides documentsActions::executeList()
  */
 public function executeList()
 {
     // params in order to add images of linked summits, parkings, etc...
     $request_array = array();
     if ($this->hasRequestParameter('rsummits') && ($summit_ids = $this->getRequestParameter('rsummits'))) {
         if (!in_array($summit_ids, array('-', ' '))) {
             $request_array = array(explode('-', $summit_ids), 'sr', 'ri', 'si');
         }
     } elseif ($this->hasRequestParameter('rparkings') && ($parking_ids = $this->getRequestParameter('rparkings'))) {
         if (!in_array($parking_ids, array('-', ' '))) {
             $request_array = array(explode('-', $parking_ids), 'pr', 'ri', 'pi');
         }
     } elseif ($this->hasRequestParameter('rhuts') && ($hut_ids = $this->getRequestParameter('rhuts'))) {
         if (!in_array($hut_ids, array('-', ' '))) {
             $request_array = array(explode('-', $hut_ids), 'hr', 'ri', 'hi');
         }
     } elseif ($this->hasRequestParameter('oroutes') && ($route_ids = $this->getRequestParameter('oroutes'))) {
         if (!in_array($route_ids, array('-', ' '))) {
             $request_array = array(explode('-', $route_ids), 'ro', 'oi', 'ri');
         }
     } elseif ($this->hasRequestParameter('osites') && ($site_ids = $this->getRequestParameter('osites'))) {
         if (!in_array($site_ids, array('-', ' '))) {
             $request_array = array(explode('-', $site_ids), 'to', 'oi', 'ti');
         }
     }
     if (!empty($request_array)) {
         $ids = array_shift($request_array);
         $pager = new c2cDoctrinePager('Image', c2cTools::mobileVersion() ? sfConfig::get('app_list_mobile_maxline_number') : sfConfig::get('app_list_maxline_number'));
         $this->pager = $pager;
         $q = $pager->getQuery();
         $q->select('DISTINCT i.id, i.image_type, i.geom_wkt, i.filename, ii.name, ii.culture, ii.search_name')->from('Image i')->leftJoin('i.associations a ON i.id = a.linked_id')->leftJoin('i.ImageI18n ii')->where('(a.main_id IN (SELECT a2.linked_id FROM Association a2 WHERE a2.main_id IN (' . implode(',', $ids) . ') AND a2.type = ?) AND a.type = ?)' . ' OR (a.main_id IN (' . implode(',', $ids) . ') AND a.type = ?)', $request_array);
         $pager->setPage($this->getRequestParameter('page', 1));
         $pager->init();
         $nb_results = $pager->getNbResults();
         $this->nb_results = $nb_results;
         // deal with format
         if (isset($this->format)) {
             $format = $this->format;
         } else {
             $format = $this->getRequestParameter('format', 'list');
             $format = explode('-', $format);
             $this->format = $format;
         }
         if ($nb_results == 0 && !in_array('json', $format)) {
             $params_list = array_keys(c2cTools::getCriteriaRequestParameters());
             if (count($params_list) == 1) {
                 $param = reset($params_list);
                 if (strpos($param, 'nam') !== false) {
                     $this->query_string = $this->getRequestParameter($param);
                     $this->setTemplate('../../documents/templates/simplenoresult');
                 }
             }
         } else {
             $this->items = $pager->getResults('array');
         }
         $this->setPageTitle($this->__($this->getModuleName() . ' list'));
         $this->setTemplate('list');
     } else {
         parent::executeList();
         $nb_results = $this->nb_results;
         if ($nb_results == 0) {
             return;
         }
         $items = $this->query->execute(array(), Doctrine::FETCH_ARRAY);
         $this->items = Language::parseListItems($items, 'Image');
         $this->setTemplate('list');
     }
     if (in_array('json', $this->format)) {
         $this->setJsonResponse();
         $this->setTemplate('../../documents/templates/jsonlist');
     }
 }