<commit_before><?php
/**
 * sites module actions.
 *
 * @package    c2corg
 * @subpackage sites
 * @version    $Id: actions.class.php 2541 2007-12-20 18:17:11Z alex $
 */
class sitesActions extends documentsActions
{
    /**
     * Model class name.
     */
    protected $model_class = 'Site';

    /**
     * Nb of dimensions for geom column
     */   
    protected $geom_dims = 3; 
    
    /**
     * Executes view action.
     */
    public function executeView()
    {
        parent::executeView();
        
        if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL)
        {
            $user = $this->getUser();
            $prefered_cultures = $user->getCulturesForDocuments();
            $current_doc_id = $this->getRequestParameter('id');
            $parent_ids = $sites_ids = $site_docs_ids = $child_types = array();
            
            $main_associated_sites = $this->associated_sites;
            if (count($main_associated_sites))
            {
                $associated_sites = Association::addChildWithBestName($main_associated_sites, $prefered_cultures, 'tt', $current_doc_id);
                
                if (count($main_associated_sites) > 1 || count($associated_sites) == 1)
                {
                    foreach ($main_associated_sites as $site)
                    {
                        $sites_ids[] = $site['id'];
                    }
                    
                    $site_docs = array_filter($this->associated_docs, array('c2cTools', 'is_image'));
                    foreach ($site_docs as $doc)
                    {
                        $site_docs_ids[] = $doc['id'];
                    }
                    $child_types[] = 'ti';
                    $child_types[] = 'to';
                }
            }
            else
            {
                $associated_sites = $main_associated_sites;
            }
            
            $associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
            if (count($associated_parkings))
            {
                foreach ($associated_parkings as $parking)
                {
                    $parent_ids[] = $parking['id'];
                }
                $child_types[] = 'pp';
            }
            
            $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
            
            $parent_ids = array_merge($parent_ids, $sites_ids);
            if (count($parent_ids)) // "sites" can have no linked doc
            {
                $associated_childs = Association::findWithBestName($parent_ids, $prefered_cultures, $child_types, true, true, $site_docs_ids);
                $this->associated_docs = array_merge($this->associated_docs, $associated_childs);
            
                if (count($associated_parkings))
                {
                    $associated_parkings = Association::addChild($associated_parkings, array_filter($associated_childs, array('c2cTools', 'is_parking')), 'pp');
                }
                
                if (count($sites_ids))
                {
                    $associated_site_outings = array_filter($associated_childs, array('c2cTools', 'is_outing'));
                    if (count($associated_site_outings))
                    {
                        if (count($associated_outings))
                        {
                            $outing_ids = array();
                            foreach ($associated_outings as $outing)
                            {
                                $outing_ids[] = $outing['id'];
                            }
                            foreach ($associated_site_outings as $outing)
                            {
                                if (!in_array($outing['id'], $outing_ids))
                                {
                                    $associated_outings[] = $outing;
                                }
                            }
                        }
                        else
                        {
                            $associated_outings = $associated_site_outings;
                        }
                    }
                }
            }

            $this->associated_sites = $associated_sites;
            
            array_unshift($sites_ids, $current_doc_id);
            $this->ids = implode('-', $sites_ids);
            
            $this->associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
            
            $this->associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :').' ');
            $this->associated_huts = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_hut')), 'elevation');
            $this->associated_summits = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_summit')), 'elevation');
            
            // also get author of books
            $associated_books = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_book')), 'name');
            if (count($associated_books))
            {
                $associated_books = Book::getAssociatedBooksData($associated_books);
            }
            $this->associated_books = $associated_books;

            if (!isset($associated_outings))
            {
                $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
            }
            $associated_outings = Outing::fetchAdditionalFields($associated_outings, true);
            // sort outings array by antichronological order.
            usort($associated_outings, array('c2cTools', 'cmpDate'));
            $this->nb_outings = count($associated_outings);
            // group them by blocks
            $outings_limit = sfConfig::get('app_documents_outings_limit');
            $a = array();
            $i = 0;
            while (count($associated_outings) - $i*$outings_limit > $outings_limit)
            {
                $a[] = array_slice($associated_outings, $i * $outings_limit, $outings_limit);
                $i++;
            }
            $a[] = array_slice($associated_outings, $i * $outings_limit);
            $this->associated_outings = $a;
    
            $this->associated_images = Document::fetchAdditionalFieldsFor(
                                        array_filter($this->associated_docs, array('c2cTools', 'is_image')), 
                                        'Image', 
                                        array('filename', 'image_type'));
            
            
            $site_types = $this->document->get('site_types');
            if (!is_array($site_types))
            {
                $site_types = Document::convertStringToArray($site_types);
            }
            $site_types_list = sfConfig::get('app_sites_site_types');
            foreach ($site_types as &$type)
            {
                $type = $site_types_list[$type];
            }
            $site_types = implode(', ', $site_types);
            if (!empty($site_types))
            {
                $site_types = $this->__(' :') . ' ' . $site_types;
            }
            $site_types = $this->__('site') . $site_types;
            $doc_name = $this->document->get('name');
            
            $title = $doc_name;
            if ($this->document->isArchive())
            {
                $version = $this->getRequestParameter('version');
                $title .= ' :: ' . $this->__('revision') . ' ' . $version ;
            }
            
            $title .= ' :: ' . $site_types;
            $this->setPageTitle($title);

            $description = array($site_types . ' :: ' . $doc_name,
                                 $this->getAreasList());
            $this->getResponse()->addMeta('description', implode(' - ', $description));
        }
    }

    /** refresh geoassociations of the route and 'sub' outings */
    public function executeRefreshgeoassociations()
    {
        $referer = $this->getRequest()->getReferer();
        $id = $this->getRequestParameter('id');

        // check if user is moderator: done in apps/frontend/config/security.yml

        if (!Document::checkExistence($this->model_class, $id))
        {
            $this->setErrorAndRedirect('Document does not exist', $referer);<commit_msg>properly translate site types in page title<commit_after><?php
/**
 * sites module actions.
 *
 * @package    c2corg
 * @subpackage sites
 * @version    $Id: actions.class.php 2541 2007-12-20 18:17:11Z alex $
 */
class sitesActions extends documentsActions
{
    /**
     * Model class name.
     */
    protected $model_class = 'Site';

    /**
     * Nb of dimensions for geom column
     */   
    protected $geom_dims = 3; 
    
    /**
     * Executes view action.
     */
    public function executeView()
    {
        parent::executeView();
        
        if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL)
        {
            $user = $this->getUser();
            $prefered_cultures = $user->getCulturesForDocuments();
            $current_doc_id = $this->getRequestParameter('id');
            $parent_ids = $sites_ids = $site_docs_ids = $child_types = array();
            
            $main_associated_sites = $this->associated_sites;
            if (count($main_associated_sites))
            {
                $associated_sites = Association::addChildWithBestName($main_associated_sites, $prefered_cultures, 'tt', $current_doc_id);
                
                if (count($main_associated_sites) > 1 || count($associated_sites) == 1)
                {
                    foreach ($main_associated_sites as $site)
                    {
                        $sites_ids[] = $site['id'];
                    }
                    
                    $site_docs = array_filter($this->associated_docs, array('c2cTools', 'is_image'));
                    foreach ($site_docs as $doc)
                    {
                        $site_docs_ids[] = $doc['id'];
                    }
                    $child_types[] = 'ti';
                    $child_types[] = 'to';
                }
            }
            else
            {
                $associated_sites = $main_associated_sites;
            }
            
            $associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation');
            if (count($associated_parkings))
            {
                foreach ($associated_parkings as $parking)
                {
                    $parent_ids[] = $parking['id'];
                }
                $child_types[] = 'pp';
            }
            
            $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
            
            $parent_ids = array_merge($parent_ids, $sites_ids);
            if (count($parent_ids)) // "sites" can have no linked doc
            {
                $associated_childs = Association::findWithBestName($parent_ids, $prefered_cultures, $child_types, true, true, $site_docs_ids);
                $this->associated_docs = array_merge($this->associated_docs, $associated_childs);
            
                if (count($associated_parkings))
                {
                    $associated_parkings = Association::addChild($associated_parkings, array_filter($associated_childs, array('c2cTools', 'is_parking')), 'pp');
                }
                
                if (count($sites_ids))
                {
                    $associated_site_outings = array_filter($associated_childs, array('c2cTools', 'is_outing'));
                    if (count($associated_site_outings))
                    {
                        if (count($associated_outings))
                        {
                            $outing_ids = array();
                            foreach ($associated_outings as $outing)
                            {
                                $outing_ids[] = $outing['id'];
                            }
                            foreach ($associated_site_outings as $outing)
                            {
                                if (!in_array($outing['id'], $outing_ids))
                                {
                                    $associated_outings[] = $outing;
                                }
                            }
                        }
                        else
                        {
                            $associated_outings = $associated_site_outings;
                        }
                    }
                }
            }

            $this->associated_sites = $associated_sites;
            
            array_unshift($sites_ids, $current_doc_id);
            $this->ids = implode('-', $sites_ids);
            
            $this->associated_parkings = Parking::getAssociatedParkingsData($associated_parkings);
            
            $this->associated_routes = Route::getAssociatedRoutesData($this->associated_docs, $this->__(' :').' ');
            $this->associated_huts = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_hut')), 'elevation');
            $this->associated_summits = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_summit')), 'elevation');
            
            // also get author of books
            $associated_books = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_book')), 'name');
            if (count($associated_books))
            {
                $associated_books = Book::getAssociatedBooksData($associated_books);
            }
            $this->associated_books = $associated_books;

            if (!isset($associated_outings))
            {
                $associated_outings = array_filter($this->associated_docs, array('c2cTools', 'is_outing'));
            }
            $associated_outings = Outing::fetchAdditionalFields($associated_outings, true);
            // sort outings array by antichronological order.
            usort($associated_outings, array('c2cTools', 'cmpDate'));
            $this->nb_outings = count($associated_outings);
            // group them by blocks
            $outings_limit = sfConfig::get('app_documents_outings_limit');
            $a = array();
            $i = 0;
            while (count($associated_outings) - $i*$outings_limit > $outings_limit)
            {
                $a[] = array_slice($associated_outings, $i * $outings_limit, $outings_limit);
                $i++;
            }
            $a[] = array_slice($associated_outings, $i * $outings_limit);
            $this->associated_outings = $a;
    
            $this->associated_images = Document::fetchAdditionalFieldsFor(
                                        array_filter($this->associated_docs, array('c2cTools', 'is_image')), 
                                        'Image', 
                                        array('filename', 'image_type'));
            
            
            $site_types = $this->document->get('site_types');
            if (!is_array($site_types))
            {
                $site_types = Document::convertStringToArray($site_types);
            }
            $site_types_list = sfConfig::get('app_sites_site_types');
            foreach ($site_types as &$type)
            {
                $type = $this->__($site_types_list[$type]);
            }
            $site_types = implode(', ', $site_types);
            if (!empty($site_types))
            {
                $site_types = $this->__(' :') . ' ' .  $site_types;
            }
            $site_types = $this->__('site') . $site_types;
            $doc_name = $this->document->get('name');
            
            $title = $doc_name;
            if ($this->document->isArchive())
            {
                $version = $this->getRequestParameter('version');
                $title .= ' :: ' . $this->__('revision') . ' ' . $version ;
            }
            
            $title .= ' :: ' . $site_types;
            $this->setPageTitle($title);

            $description = array($site_types . ' :: ' . $doc_name,
                                 $this->getAreasList());
            $this->getResponse()->addMeta('description', implode(' - ', $description));
        }
    }

    /** refresh geoassociations of the route and 'sub' outings */
    public function executeRefreshgeoassociations()
    {
        $referer = $this->getRequest()->getReferer();
        $id = $this->getRequestParameter('id');

        // check if user is moderator: done in apps/frontend/config/security.yml

        if (!Document::checkExistence($this->model_class, $id))
        {
            $this->setErrorAndRedirect('Document does not exist', $referer);
{'fraction_non_alphanumeric': 0.12508871540099362, 'fraction_numerical': 0.004494913650343033, 'mean_word_length': 1.5188440339639506, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 104, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3396938', 'n_tokens_mistral': 4694, 'n_tokens_neox': 4328, 'n_words': 685}