From e84cc5d1e3c72e0ef37994ea0dd357fb934d858e Mon Sep 17 00:00:00 2001 From: Scott Tesoriere Date: Thu, 12 May 2011 11:35:54 -0400 Subject: [PATCH] section id abstraction --- content/content.index.php | 18 ++++++---- events/event.mass_upload_utility_entry.php | 41 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 6 deletions(-) create mode 100644 events/event.mass_upload_utility_entry.php diff --git a/content/content.index.php b/content/content.index.php index f723522..c7de71f 100644 --- a/content/content.index.php +++ b/content/content.index.php @@ -13,7 +13,16 @@ class contentExtensionMassUploadUtilityIndex extends AdministrationPage { protected $_valid = false; protected $_message = ''; - + public function getSectionID() { + $sectionManager = new SectionManager($this->_Parent); + + $section_id = $sectionManager->fetchIDFromHandle(General::sanitize($_REQUEST['MUUsource'])); + + if(!$section = $sectionManager->fetch($section_id)) + return NULL; + else + return $section_id; + } /** * --------------------------------------------------------- * This functionality is essentially duplicated (and slightly changed) @@ -30,13 +39,10 @@ public function view() { if (!isset($_REQUEST['MUUsource']) or $_REQUEST['MUUsource'] == '') { $this->_message = __("You didn't choose a source, perhaps you don't have any sections with an upload field in them?"); $this->__response(); } + if (($section_id = $this->getSectionID()) === NULL) + { $this->_message = __('The Section you are looking, %s for could not be found.', $this->_context['section_handle']); $this->__response(); } $sectionManager = new SectionManager($this->_Parent); - $section_id = $sectionManager->fetchIDFromHandle(General::sanitize($_REQUEST['MUUsource'])); - - if(!$section = $sectionManager->fetch($section_id)) - Administration::instance()->customError(__('Unknown Section'), __('The Section you are looking, %s for could not be found.', $this->_context['section_handle'])); - $entryManager = new EntryManager($this->_Parent); $entry =& $entryManager->create(); diff --git a/events/event.mass_upload_utility_entry.php b/events/event.mass_upload_utility_entry.php new file mode 100644 index 0000000..295d4b0 --- /dev/null +++ b/events/event.mass_upload_utility_entry.php @@ -0,0 +1,41 @@ + 'Mass Upload Utility: Create an Entry', + 'author' => array( + 'name' => 'Scott Tesoriere', + 'website' => 'http://tesoriere.com', + 'email' => 'scott@tesoriere.com'), + 'version' => '1.0', + 'release-date' => '2009-11-13T11:35:07+00:00', + 'trigger-condition' => 'action[api]'); + } + + public static function getSource(){ + return contentExtensionMassUploadUtilityIndex::getSectionId(); + } + + public static function documentation(){ + return ''; + } + + public function load(){ + return $this->__trigger(); + } + + protected function __trigger(){ + + include(TOOLKIT . '/events/event.section.php'); + return $result; + } + + } \ No newline at end of file