Exemplo n.º 1
0
 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);
 }
Exemplo n.º 2
0
 public function removeSampleData()
 {
     $sampleIds = unserialize(ConfigHelper::getConfigValue('import_sample'));
     $db = $this->container->resolve('db');
     $query = $db->getQuery(true);
     foreach ($sampleIds as $table => $ids) {
         $query->clear()->delete("#__" . $table)->where("id IN(" . implode(',', $ids) . ")");
         $db->setQuery($query);
         $db->query();
     }
     $data = array('import_sample' => "0");
     $configModel = new ConfigModel();
     $configModel->store($data);
     $msg = TextHelper::_('COBALT_SAMPLE_DATA_REMOVED');
     $this->getApplication()->redirect('index.php?view=import', $msg);
 }