<commit_before><?php
/**
 * Cross Applicant Management
 * 
 * @filesource
 * @copyright (c) 2013 Cross Solution (http://cross-solution.de)
 * @license   GPLv3
 */

/** Applications controller */
namespace Applications\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Applications\Model\Hydrator\ApplicationHydrator;
use Applications\Model\JsonApplication;
use Zend\Stdlib\Hydrator\Strategy\ClosureStrategy;
use Core\Mapper\Criteria\Criteria;
use Core\Filter\ListQuery;
use Core\Mapper\Query\Query;



/**
 * Action Controller for managing applications.
 *
 */
class ManageController extends AbstractActionController
{
    
    /**
     * List applications
     *
     */
    public function indexAction()
    { 
        
        $v = new ViewModel(array(
            'by' => $this->params()->fromQuery('by', 'me'),
            'hasJobs' => (bool) $this->getServiceLocator()
                                     ->get('repositories')
                                     ->get('job')
                                     ->countByUser($this->auth('id'))
        ));
        $v->setTemplate('applications/sidebar/manage');
        $this->layout()->addChild($v, 'sidebar_applicationsFilter');
        $repository = $this->getServiceLocator()->get('repositories')->get('application');
        $params = $this->params()->fromQuery();
        
            
        
        $paginator = new \Zend\Paginator\Paginator(
            $repository->getPaginatorAdapter($params)
        );
        $paginator->setCurrentPageNumber($this->params()->fromQuery('page'))
                  ->setItemCountPerPage(10);
        
        
        $jsonFormat = 'json' == $this->params()->fromQuery('format');
        
        if ($jsonFormat) {
            $viewModel = new JsonModel();
            //$items = iterator_to_array($paginator);
            
            $viewModel->setVariables(array(
                'items' => $this->getServiceLocator()->get('builders')->get('JsonApplication')
                                ->unbuildCollection($paginator->getCurrentItems()),
                'count' => $paginator->getTotalItemCount()
            ));
            return $viewModel;
            
        } 
        
        return array(
            'applications' => $paginator,
            'byJobs' => isset($params['by']) && 'jobs' == $params['by'],
            'sort' => isset($params['sort']) ? $params['sort'] : 'none',
            
        );
        
        
    }
    
    public function detailAction(){

    	$application = $this->getServiceLocator()
    						->get('repositories')
    						->get('application')->find($this->params('id'), 'EAGER');
    	
    	$jsonFormat = 'json' == $this->params()->fromQuery('format');
    	if ($jsonFormat) {
    		$viewModel = new JsonModel();
    		$viewModel->setVariables(array('educations' => $application->cv->educations));
    		return $viewModel;
    	}

    	return array('application'=> $application);
    }
    
}<commit_msg>[Applications] Fix: json response of detail view is empty<commit_after><?php
/**
 * Cross Applicant Management
 * 
 * @filesource
 * @copyright (c) 2013 Cross Solution (http://cross-solution.de)
 * @license   GPLv3
 */

/** Applications controller */
namespace Applications\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Applications\Model\Hydrator\ApplicationHydrator;
use Applications\Model\JsonApplication;
use Zend\Stdlib\Hydrator\Strategy\ClosureStrategy;
use Core\Mapper\Criteria\Criteria;
use Core\Filter\ListQuery;
use Core\Mapper\Query\Query;



/**
 * Action Controller for managing applications.
 *
 */
class ManageController extends AbstractActionController
{
    
    /**
     * List applications
     *
     */
    public function indexAction()
    { 
        
        $v = new ViewModel(array(
            'by' => $this->params()->fromQuery('by', 'me'),
            'hasJobs' => (bool) $this->getServiceLocator()
                                     ->get('repositories')
                                     ->get('job')
                                     ->countByUser($this->auth('id'))
        ));
        $v->setTemplate('applications/sidebar/manage');
        $this->layout()->addChild($v, 'sidebar_applicationsFilter');
        $repository = $this->getServiceLocator()->get('repositories')->get('application');
        $params = $this->params()->fromQuery();
        
            
        
        $paginator = new \Zend\Paginator\Paginator(
            $repository->getPaginatorAdapter($params)
        );
        $paginator->setCurrentPageNumber($this->params()->fromQuery('page'))
                  ->setItemCountPerPage(10);
        
        
        $jsonFormat = 'json' == $this->params()->fromQuery('format');
        
        if ($jsonFormat) {
            $viewModel = new JsonModel();
            //$items = iterator_to_array($paginator);
            
            $viewModel->setVariables(array(
                'items' => $this->getServiceLocator()->get('builders')->get('JsonApplication')
                                ->unbuildCollection($paginator->getCurrentItems()),
                'count' => $paginator->getTotalItemCount()
            ));
            return $viewModel;
            
        } 
        
        return array(
            'applications' => $paginator,
            'byJobs' => isset($params['by']) && 'jobs' == $params['by'],
            'sort' => isset($params['sort']) ? $params['sort'] : 'none',
            
        );
        
        
    }
    
    public function detailAction(){

    	$application = $this->getServiceLocator()
    						->get('repositories')
    						->get('application')->find($this->params('id'), 'EAGER');
    	
    	$jsonFormat = 'json' == $this->params()->fromQuery('format');
    	if ($jsonFormat) {
    		$viewModel = new JsonModel();
    		$viewModel->setVariables(/*array(
    		    'application' => */$this->getServiceLocator()
    		                          ->get('builders')
    		                          ->get('JsonApplication')
    		                          ->unbuild($application)
    		);
    		return $viewModel;
    	}

    	return array('application'=> $application);
    }
    
}
{'fraction_non_alphanumeric': 0.15339559917682444, 'fraction_numerical': 0.002216241886971664, 'mean_word_length': 2.0229665071770335, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '258865', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1701, 'n_words': 266}