<commit_before><?php

class VoManage_Controller_Index extends Default_Controller_LoggedIn
{
    protected $m_vo_id = '';
    protected $m_action = '';
    protected $m_allowedActions = array('Index', 'SelectVo', 'Add', 'Edit', 'Delete');
    
    /**
     * VO selection
     */
    public function selectVoAction() 
    {
        // selected VO is posted to itself, redirect to index
        $vo_id = trim(html_entity_decode($this->_getRequest()->getPostParameter("vo_id")));
        if (strlen($vo_id) > 0) {
            // go to attribute list
            $this->m_vo_id = $vo_id;
            $this->handleAction("Index");
            return;
        }
        // show VO list
        $service = new VoManage_Service_VirtualOrganisation();
        $this->resultSet = $service->fetchAll();
    }
    
    /**
     * List view of user attributes
     */
    public function indexAction($dispatch=TRUE)
    {
        //var_dump($this->_getRequest()->getPostParameters());
        
        // VO selected?
        $this->getSelectedVO();

        // dispatch
        if ($dispatch) $this->dispatchAction($this->_getRequest()->getPostParameters());
        
        // index action 
        $params = Surfnet_Search_Parameters::create();
        $params->addSearchParam('vo_id', $this->m_vo_id);
        $service = new VoManage_Service_VirtualOrganisationAttribute();
        $results = $service->listSearch($params);

        $resultSet = $results->getResults();
        $this->vo_id = $this->m_vo_id;
        
        $spList = $this->getServiceProviders();
        foreach($resultSet as $key => &$record) {
            $record['sp_entity_id_display'] = (isset($spList[$record['sp_entity_id']]) ? $spList[$record['sp_entity_id']]['id_display'] : '- unknown -');
        }
        // sort
        $resultSet = $this->sortByColumn($resultSet, 'sp_entity_id_display');
        // assign to view
        $this->resultSet = $resultSet;
    }

    public function sortByColumn($recordset, $column) {
        // put the column values into tmp
        $tmp = array();
        foreach ($recordset as $key => $record) {
            $tmp[$key] = (is_string($record[$column]) ? strtolower($record[$column]) : $record[$column]);
        }
        // multisort
        array_multisort($tmp, SORT_ASC, $recordset);
        // done!
        return $recordset;
    }
    
    public function addAction() 
    {
        $formAction = html_entity_decode($this->_getRequest()->getPostParameter("formaction"));
        $this->vo_id = $this->m_vo_id;
        if ($formAction == 'save') {
            $data = $this->_getRequest()->getPostParameters();
            $recordData = array_intersect_key($data, array_fill_keys(array('vo_id','sp_entity_id','user_id_pattern','attribute_name_saml','attribute_name_opensocial','attribute_value'), 0));
            $service = new VoManage_Service_VirtualOrganisationAttribute();
            $result = $service->save($recordData);
            $this->errors = $result->errors;
            $this->data = $data;
        } elseif ($formAction == 'cancel') {
            // return to index, ignore dispatching
            $this->handleAction('Index', array(FALSE));
        } else {
            // initial values
            $this->data = array('user_id_pattern' => 'urn:collab:person:*');
        }
        // form data
        $this->spList = $this->getServiceProviders();
    }

    public function editAction() {
        $formAction = html_entity_decode($this->_getRequest()->getPostParameter("formaction"));
        $this->vo_id = $this->m_vo_id;
        $service = new VoManage_Service_VirtualOrganisationAttribute();
        
        if ($formAction == '') {
            $this->data = $service->fetch($this->m_vo_id, intval($this->_getRequest()->getPostParameter('id')));
        } elseif ($formAction == 'save') {
            $data = $this->_getRequest()->getPostParameters();
            $recordData = array_intersect_key($data, array_fill_keys(array('id','vo_id','sp_entity_id','user_id_pattern','attribute_name_saml','attribute_name_opensocial','attribute_value'), 0));
            $result = $service->save($recordData);
            $this->errors = $result->errors;
            $this->data = $data;
        } elseif ($formAction == 'cancel') {
            // return to index, ignore dispatching
            $this->handleAction('Index', array(FALSE));
        }
        // form data
        $this->spList = $this->getServiceProviders();        
    }
    
    public function deleteAction() {
        $formAction = html_entity_decode($this->_getRequest()->getPostParameter("formaction"));
        $this->vo_id = $this->m_vo_id;
        $service = new VoManage_Service_VirtualOrganisationAttribute();
        $this->id = intval($this->_getRequest()->getPostParameter('id'));
        
        if ($formAction == '') {
            $record = $service->fetch($this->m_vo_id, $this->id);
            $spList = $this->getServiceProviders();
            $record['sp_entity_id_display'] = (isset($spList[$record['sp_entity_id']]) ? $spList[$record['sp_entity_id']]['id_display'] : '- unknown -');
            $this->data = $record;
        } elseif ($formAction == 'delete') {
            $data = $this->_getRequest()->getPostParameters();
            $result = $service->delete($this->m_vo_id, $this->id);
            $this->errors = $result->errors;
            $this->data = $data;
        } elseif ($formAction == 'cancel') {
            // return to index, ignore dispatching
            $this->handleAction('Index', array(FALSE));
        }
    }
    
    protected function dispatchAction($postVars) {
        $this->m_action = trim(html_entity_decode($this->_getRequest()->getPostParameter("action")));
        if (in_array($this->m_action, $this->m_allowedActions) && $this->m_action != 'Index') {
            $this->handleAction($this->m_action);
        }
        return;
    }
    
    /**
     * Get the selected VO from the POST variable, except when it is already known.
     * 
     * @return string
     */
    protected function getSelectedVO() {
        if (strlen($this->m_vo_id) == 0) {
            $vo_id = trim(html_entity_decode($this->_getRequest()->getPostParameter("vo_id")));
            if (strlen($vo_id) == 0 ) {
                $this->handleAction("selectVo");
                return;
            }
            $this->m_vo_id = $vo_id;
        }
        // return the vo_id in case you want to assign it directly to something else
        return $this->m_vo_id;
    }<commit_msg>CamelCase fix<commit_after><?php

class VoManage_Controller_Index extends Default_Controller_LoggedIn
{
    protected $m_vo_id = '';
    protected $m_action = '';
    protected $m_allowedActions = array('Index', 'SelectVo', 'Add', 'Edit', 'Delete');
    
    /**
     * VO selection
     */
    public function selectVoAction() 
    {
        // selected VO is posted to itself, redirect to index
        $vo_id = trim(html_entity_decode($this->_getRequest()->getPostParameter("vo_id")));
        if (strlen($vo_id) > 0) {
            // go to attribute list
            $this->m_vo_id = $vo_id;
            $this->handleAction("Index");
            return;
        }
        // show VO list
        $service = new VoManage_Service_VirtualOrganisation();
        $this->resultSet = $service->fetchAll();
    }
    
    /**
     * List view of user attributes
     */
    public function indexAction($dispatch=TRUE)
    {
        //var_dump($this->_getRequest()->getPostParameters());
        
        // VO selected?
        $this->getSelectedVO();

        // dispatch
        if ($dispatch) $this->dispatchAction($this->_getRequest()->getPostParameters());
        
        // index action 
        $params = Surfnet_Search_Parameters::create();
        $params->addSearchParam('vo_id', $this->m_vo_id);
        $service = new VoManage_Service_VirtualOrganisationAttribute();
        $results = $service->listSearch($params);

        $resultSet = $results->getResults();
        $this->vo_id = $this->m_vo_id;
        
        $spList = $this->getServiceProviders();
        foreach($resultSet as $key => &$record) {
            $record['sp_entity_id_display'] = (isset($spList[$record['sp_entity_id']]) ? $spList[$record['sp_entity_id']]['id_display'] : '- unknown -');
        }
        // sort
        $resultSet = $this->sortByColumn($resultSet, 'sp_entity_id_display');
        // assign to view
        $this->resultSet = $resultSet;
    }

    public function sortByColumn($recordset, $column) {
        // put the column values into tmp
        $tmp = array();
        foreach ($recordset as $key => $record) {
            $tmp[$key] = (is_string($record[$column]) ? strtolower($record[$column]) : $record[$column]);
        }
        // multisort
        array_multisort($tmp, SORT_ASC, $recordset);
        // done!
        return $recordset;
    }
    
    public function addAction() 
    {
        $formAction = html_entity_decode($this->_getRequest()->getPostParameter("formaction"));
        $this->vo_id = $this->m_vo_id;
        if ($formAction == 'save') {
            $data = $this->_getRequest()->getPostParameters();
            $recordData = array_intersect_key($data, array_fill_keys(array('vo_id','sp_entity_id','user_id_pattern','attribute_name_saml','attribute_name_opensocial','attribute_value'), 0));
            $service = new VoManage_Service_VirtualOrganisationAttribute();
            $result = $service->save($recordData);
            $this->errors = $result->errors;
            $this->data = $data;
        } elseif ($formAction == 'cancel') {
            // return to index, ignore dispatching
            $this->handleAction('Index', array(FALSE));
        } else {
            // initial values
            $this->data = array('user_id_pattern' => 'urn:collab:person:*');
        }
        // form data
        $this->spList = $this->getServiceProviders();
    }

    public function editAction() {
        $formAction = html_entity_decode($this->_getRequest()->getPostParameter("formaction"));
        $this->vo_id = $this->m_vo_id;
        $service = new VoManage_Service_VirtualOrganisationAttribute();
        
        if ($formAction == '') {
            $this->data = $service->fetch($this->m_vo_id, intval($this->_getRequest()->getPostParameter('id')));
        } elseif ($formAction == 'save') {
            $data = $this->_getRequest()->getPostParameters();
            $recordData = array_intersect_key($data, array_fill_keys(array('id','vo_id','sp_entity_id','user_id_pattern','attribute_name_saml','attribute_name_opensocial','attribute_value'), 0));
            $result = $service->save($recordData);
            $this->errors = $result->errors;
            $this->data = $data;
        } elseif ($formAction == 'cancel') {
            // return to index, ignore dispatching
            $this->handleAction('Index', array(FALSE));
        }
        // form data
        $this->spList = $this->getServiceProviders();        
    }
    
    public function deleteAction() {
        $formAction = html_entity_decode($this->_getRequest()->getPostParameter("formaction"));
        $this->vo_id = $this->m_vo_id;
        $service = new VoManage_Service_VirtualOrganisationAttribute();
        $this->id = intval($this->_getRequest()->getPostParameter('id'));
        
        if ($formAction == '') {
            $record = $service->fetch($this->m_vo_id, $this->id);
            $spList = $this->getServiceProviders();
            $record['sp_entity_id_display'] = (isset($spList[$record['sp_entity_id']]) ? $spList[$record['sp_entity_id']]['id_display'] : '- unknown -');
            $this->data = $record;
        } elseif ($formAction == 'delete') {
            $data = $this->_getRequest()->getPostParameters();
            $result = $service->delete($this->m_vo_id, $this->id);
            $this->errors = $result->errors;
            $this->data = $data;
        } elseif ($formAction == 'cancel') {
            // return to index, ignore dispatching
            $this->handleAction('Index', array(FALSE));
        }
    }
    
    protected function dispatchAction($postVars) {
        $this->m_action = trim(html_entity_decode($this->_getRequest()->getPostParameter("action")));
        if (in_array($this->m_action, $this->m_allowedActions) && $this->m_action != 'Index') {
            $this->handleAction($this->m_action);
        }
        return;
    }
    
    /**
     * Get the selected VO from the POST variable, except when it is already known.
     * 
     * @return string
     */
    protected function getSelectedVO() {
        if (strlen($this->m_vo_id) == 0) {
            $vo_id = trim(html_entity_decode($this->_getRequest()->getPostParameter("vo_id")));
            if (strlen($vo_id) == 0 ) {
                $this->handleAction("SelectVo");
                return;
            }
            $this->m_vo_id = $vo_id;
        }
        // return the vo_id in case you want to assign it directly to something else
        return $this->m_vo_id;
    }
{'fraction_non_alphanumeric': 0.15728959067913537, 'fraction_numerical': 0.0007665184730952016, 'mean_word_length': 2.453414505029116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 187, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2644672', 'n_tokens_mistral': 3762, 'n_tokens_neox': 3744, 'n_words': 649}