public function render($tpl = null) { //authenticate the current user to make sure they are an admin UsersHelper::authenticateAdmin(); //app $app = \Cobalt\Container::fetch('app'); if ($app->input->get('layout') == 'sample') { $this->_displaySample($tpl); return; } /** Menu Links **/ $menu = MenuHelper::getMenuModules(); $this->menu = $menu; //javascripts $doc = $app->getDocument(); $doc->addScript(JURI::base() . "/src/Cobalt/media/js/cobalt-admin.js"); $doc->addScript(JURI::base() . "/src/Cobalt/media/js/document_manager.js"); //import data $import_post = FALSE; if (count($_FILES) > 0) { $import_post = TRUE; $import_data = array(); $import_type = $app->input->get('import_type'); $model = new ImportModel(); foreach ($_FILES as $file) { $data = $model->readCSVFile($file['tmp_name']); $import_data = array_merge($import_data, $data); } if (count($import_data) > 500) { switch ($app->input->get('import_type')) { case "company": $import_model = "company"; break; case "people": $import_model = "people"; break; case "deals": $import_model = "deal"; break; } if ($model->importCSVData($import_data, $import_model)) { $success = "SUCCESSFULLY"; } else { $success = "UNSUCCESSFULLY"; } $view = "import"; $msg = TextHelper::_('COBALT_' . $success . '_IMPORTED_ITEMS'); $app->redirect('index.php?view=' . $view, $msg); } $this->headers = $import_data['headers']; unset($import_data['headers']); $this->import_data = $import_data; $this->import_type = $import_type; $doc->addScriptDeclaration('import_length=' . count($import_data) . ';'); $doc->addScriptDeclaration("show_tab='import_review';"); } $this->import_post = $import_post; //display return parent::render(); }
public function execute() { $sampleIds = array(); $importModel = new ImportModel(); $sampleCsvFiles = array('sample-company' => "companies", 'sample-person' => "people", 'sample-deal' => "deals"); foreach ($sampleCsvFiles as $file => $table) { $importData = $importModel->readCSVFile(JPATH_COBALT . '/Sample/' . $file . '.csv', $table, false); switch ($table) { case "companies": $model = "company"; break; case "people": $model = "people"; break; case "deals": $model = "deal"; break; } unset($importData['headers']); $ids = $importModel->importCSVData($importData, $model, true); $sampleIds[$table] = $ids; } $data = array('import_sample' => serialize($sampleIds)); $configModel = new ConfigModel(); $configModel->store($data); $msg = TextHelper::_('COBALT_SAMPLE_DATA_INSTALLED'); $this->getApplication()->redirect('index.php?view=import', $msg); }
public function render($tpl = null) { $app = \Cobalt\Container::fetch('app'); $doc = $app->getDocument(); $doc->addScript(JURI::base() . 'src/Cobalt/media/js/import_manager.js'); if (count($_FILES) > 0) { $model = new ImportModel(); foreach ($_FILES as $file) { $import_data = $model->readCSVFile($file['tmp_name']); } $this->headers = $import_data['headers']; unset($import_data['headers']); $this->import_data = $import_data; if (count($import_data) > 500) { switch ($app->input->get('import_type')) { case "company": $view = "companies"; $import_model = "company"; break; case "people": $view = "people"; $import_model = "people"; break; case "deals": $view = "deals"; $import_model = "deal"; break; } if ($model->importCSVData($import_data, $import_model)) { $success = "SUCCESSFULLY"; } else { $success = "UNSUCCESSFULLY"; $view = "import&import_type=" . $app->input->get('import_type'); } $msg = TextHelper::_('COBALT_' . $success . '_IMPORTED_ITEMS'); $app->redirect(RouteHelper::_('index.php?view=' . $view), $msg); } $doc->addScriptDeclaration('import_length=' . count($import_data) . ';'); } $import_type = $app->input->get('import_type'); $import_header = ucwords(TextHelper::_('COBALT_IMPORT_' . $import_type)); $this->import_type = $import_type; $this->import_header = $import_header; if ($this->getLayout() == 'default') { $this->setLayout('import'); } //display return parent::render(); }