<commit_before><?php
App::uses('AppController', 'Controller');


/**
 * Organizations Controller
 *
 * @property Organization $Organization
 * @property PaginatorComponent $Paginator
 */
class OrganizationsController extends AppController
{

	public function beforeFilter()
	{
		parent::beforeFilter();
		// Allow guest users to open event index and event view
		$this->Auth->allow('go_view', 'go_add', 'go_index');
	}

	/**
	 * Components
	 *
	 * @var array
	 */
	public $components = array('Paginator');
	public $helpers = array('Address', 'PhpExcel');

	public function api_get_organization($organization_id)
	{
		$organization = $this->Organization->find('first', array(
			'conditions' => array(
				'organization_id' => $organization_id
			),
			'contain' => array()
		));

		if (!$organization) {
			throw new \JsonSchema\Exception\ResourceNotFoundException("Organization not found.");
		}

		$this->set('organization', $organization['Organization']);
		$this->set('_serialize', array('organization'));
	}

	public function api_get_organization_events($organization_id) {
		$organization = $this->Organization->find('first', [
			'conditions' => [
				'organization_id' => $organization_id
			],
			'contain' => []
		]);

		if( !$organization ) {
			throw new NotFoundException('Unable to find organization by id ' . $organization_id);
		}

		$fields = $this->_CurrentUserCanWrite($organization_id)
			? [
				'*'
			]
			: [
				'Event.event_id',
				'Event.title',
				'Event.description',
				'Event.start_time',
				'Event.stop_time'
			];

		$events = $this->Organization->Event->find('all', [
			'conditions' => [
				'Event.organization_id' => $organization_id
			],
			'contain' => [

			],
			'fields' => $fields
		]);

		$this->set([
			'events' => $events,
			'_serialize' => ['organization', 'events']
		]);
	}

	public function api_get_organization_role($organization_id)
	{
		$organization = $this->Organization->find('first', array(
			'conditions' => array(
				'organization_id' => $organization_id
			),
			'contain' => array()
		));

		if (!$organization) {
			throw new \JsonSchema\Exception\ResourceNotFoundException("Organization not found.");
		}

		$permission = $this->Organization->Permission->find('first', array(
			'conditions' => array(
				'organization_id' => $organization['Organization']['organization_id'],
				'user_id' => $this->Auth->user('user_id')
			),
			'contain' => array()
		));

		$this->set('permission', $permission['Permission']);
		$this->set('_serialize', array('permission'));
	}


	/**
	 * go_leave method
	 *
	 * @return void
	 */
	public function go_leave($id = null)
	{
		return $this->redirect(
			array(
				'coordinator' => true,
				'controller' => 'organizations',
				'action' => 'leave',
				$id)
		);
	}


	/**
	 * go_join method
	 *
	 * @return void
	 */
	public function go_join($id = null)
	{
		return $this->redirect(
			array(
				'volunteer' => true,
				'controller' => 'organizations',
				'action' => 'join',
				$id)
		);
	}


	/**
	 * go_add method
	 *
	 * @return void
	 */
	public function go_add()
	{
		return $this->redirect(
			array(
				'volunteer' => true,
				'controller' => 'organizations',
				'action' => 'add'
			)
		);
	}

	/**
	 * go_index method
	 *
	 * @return void
	 */
	public function go_index($id = null)
	{
		return $this->redirect(<commit_msg>Remove old PhpExcel component invocation from Org controller<commit_after><?php
App::uses('AppController', 'Controller');


/**
 * Organizations Controller
 *
 * @property Organization $Organization
 * @property PaginatorComponent $Paginator
 */
class OrganizationsController extends AppController
{

	public function beforeFilter()
	{
		parent::beforeFilter();
		// Allow guest users to open event index and event view
		$this->Auth->allow('go_view', 'go_add', 'go_index');
	}

	/**
	 * Components
	 *
	 * @var array
	 */
	public $components = array('Paginator');
	public $helpers = array('Address');

	public function api_get_organization($organization_id)
	{
		$organization = $this->Organization->find('first', array(
			'conditions' => array(
				'organization_id' => $organization_id
			),
			'contain' => array()
		));

		if (!$organization) {
			throw new \JsonSchema\Exception\ResourceNotFoundException("Organization not found.");
		}

		$this->set('organization', $organization['Organization']);
		$this->set('_serialize', array('organization'));
	}

	public function api_get_organization_events($organization_id) {
		$organization = $this->Organization->find('first', [
			'conditions' => [
				'organization_id' => $organization_id
			],
			'contain' => []
		]);

		if( !$organization ) {
			throw new NotFoundException('Unable to find organization by id ' . $organization_id);
		}

		$fields = $this->_CurrentUserCanWrite($organization_id)
			? [
				'*'
			]
			: [
				'Event.event_id',
				'Event.title',
				'Event.description',
				'Event.start_time',
				'Event.stop_time'
			];

		$events = $this->Organization->Event->find('all', [
			'conditions' => [
				'Event.organization_id' => $organization_id
			],
			'contain' => [

			],
			'fields' => $fields
		]);

		$this->set([
			'events' => $events,
			'_serialize' => ['organization', 'events']
		]);
	}

	public function api_get_organization_role($organization_id)
	{
		$organization = $this->Organization->find('first', array(
			'conditions' => array(
				'organization_id' => $organization_id
			),
			'contain' => array()
		));

		if (!$organization) {
			throw new \JsonSchema\Exception\ResourceNotFoundException("Organization not found.");
		}

		$permission = $this->Organization->Permission->find('first', array(
			'conditions' => array(
				'organization_id' => $organization['Organization']['organization_id'],
				'user_id' => $this->Auth->user('user_id')
			),
			'contain' => array()
		));

		$this->set('permission', $permission['Permission']);
		$this->set('_serialize', array('permission'));
	}


	/**
	 * go_leave method
	 *
	 * @return void
	 */
	public function go_leave($id = null)
	{
		return $this->redirect(
			array(
				'coordinator' => true,
				'controller' => 'organizations',
				'action' => 'leave',
				$id)
		);
	}


	/**
	 * go_join method
	 *
	 * @return void
	 */
	public function go_join($id = null)
	{
		return $this->redirect(
			array(
				'volunteer' => true,
				'controller' => 'organizations',
				'action' => 'join',
				$id)
		);
	}

	/**
	 * go_add method
	 *
	 * @return void
	 */
	public function go_add()
	{
		return $this->redirect(
			array(
				'volunteer' => true,
				'controller' => 'organizations',
				'action' => 'add'
			)
		);
	}

	/**
	 * go_index method
	 *
	 * @return void
	 */
	public function go_index($id = null)
	{
		return $this->redirect(
{'fraction_non_alphanumeric': 0.1769162210338681, 'fraction_numerical': 0.0, 'mean_word_length': 3.611643835616438, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 111, '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': '6803920', 'n_tokens_mistral': 2598, 'n_tokens_neox': 2138, 'n_words': 409}