<commit_before><?php
/*
 * Manage Navigation Content
 */
class Navigation_Controller extends Admin_Controller {
	/**
	 * List all the navigation content nodes for editing
	 */
	public function manage()
	{		
		if (isset($_POST['new_navigation_form']))
		{
			$post = $this->input->post();
			$node = ORM::factory('navigation_content');
			$parent = ORM::factory('navigation_content', $post['parent_id']);
			if (!$parent->loaded) die($parent->name);
			if ($node->validate($post))
			{
				$node->insert_as_first_child($parent);
				notice::add('Navigation Item Created!', 'success');
				url::redirect('admin/navigation/edit/'.$node->id);
			}
			else
			{
				foreach($post->errors() as $error)
				{
					notice::add($error, 'error');
				}
			}
		}
		$root = ORM::factory('navigation_content')->root->find();
		$nodes = ORM::factory('navigation_content')->orderby('lft', 'ASC')->find_all();
		$this->template->content = View::factory('content/static/admin/navigation/manage');
		$this->template->content->root = $root;
		$this->template->content->nodes = $nodes;
	}
	public function edit($id)
	{
		$content = ORM::factory('navigation_content', $id);
		if (!(bool)$content->id)Event::run('system.404');//incorrect $id

		if(isset($_POST['edit_navigation']))
		{
			$post = $this->input->post();
			//update the page
			if($content->update($post))
			{
				notice::add('Item Saved!', 'success');
				url::redirect('admin/navigation/manage');
			}
			else
			{
				$errors = $post->errors('form_errors');
				foreach($errors as $error)
				{
					notice::add($error, 'error');
				}
			}
		}

		$this->template->content = View::factory('content/static/admin/navigation/edit');
		$this->template->content->item = $content;
		$this->template->content->pages = ORM::factory('content_page')
												->select_list('id', 'alias');
	}
	public function delete($id)
	{
		$node = ORM::factory('navigation_content', $id);
		if (!(bool)$node->id) Event::run('system.404');

		if($node->delete())
		{
			notice::add('Item Deleted Successfully!', 'success');
		}
		else
		{
			//@TODO: look into why this is always FALSE
			notice::add('Item Deleted Successfully!', 'success');
		}
		url::redirect('admin/navigation/manage');
	}
} // End Admin Navigation Controller<commit_msg>insert_as_last_child() just makes more sense here...sorting options coming soon!<commit_after><?php
/*
 * Manage Navigation Content
 */
class Navigation_Controller extends Admin_Controller {
	/**
	 * List all the navigation content nodes for editing
	 */
	public function manage()
	{		
		if (isset($_POST['new_navigation_form']))
		{
			$post = $this->input->post();
			$node = ORM::factory('navigation_content');
			$parent = ORM::factory('navigation_content', $post['parent_id']);
			if (!$parent->loaded) die($parent->name);
			if ($node->validate($post))
			{
				$node->insert_as_last_child($parent);
				notice::add('Navigation Item Created!', 'success');
				url::redirect('admin/navigation/edit/'.$node->id);
			}
			else
			{
				foreach($post->errors() as $error)
				{
					notice::add($error, 'error');
				}
			}
		}
		$root = ORM::factory('navigation_content')->root->find();
		$nodes = ORM::factory('navigation_content')->orderby('lft', 'ASC')->find_all();
		$this->template->content = View::factory('content/static/admin/navigation/manage');
		$this->template->content->root = $root;
		$this->template->content->nodes = $nodes;
	}
	public function edit($id)
	{
		$content = ORM::factory('navigation_content', $id);
		if (!(bool)$content->id)Event::run('system.404');//incorrect $id

		if(isset($_POST['edit_navigation']))
		{
			$post = $this->input->post();
			//update the page
			if($content->update($post))
			{
				notice::add('Item Saved!', 'success');
				url::redirect('admin/navigation/manage');
			}
			else
			{
				$errors = $post->errors('form_errors');
				foreach($errors as $error)
				{
					notice::add($error, 'error');
				}
			}
		}

		$this->template->content = View::factory('content/static/admin/navigation/edit');
		$this->template->content->item = $content;
		$this->template->content->pages = ORM::factory('content_page')
												->select_list('id', 'alias');
	}
	public function delete($id)
	{
		$node = ORM::factory('navigation_content', $id);
		if (!(bool)$node->id) Event::run('system.404');

		if($node->delete())
		{
			notice::add('Item Deleted Successfully!', 'success');
		}
		else
		{
			//@TODO: look into why this is always FALSE
			notice::add('Item Deleted Successfully!', 'success');
		}
		url::redirect('admin/navigation/manage');
	}
} // End Admin Navigation Controller
{'fraction_non_alphanumeric': 0.20217391304347826, 'fraction_numerical': 0.0026086956521739132, 'mean_word_length': 4.1236080178173715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 75, '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': '3738399', 'n_tokens_mistral': 1740, 'n_tokens_neox': 1471, 'n_words': 255}