/** * Populate __sleep values, restore serialize values specified on __sleep() method * * @return self */ public function populateWithItself(self $formulary) { $this->_name = $formulary->getName(); $this->_isActive = $formulary->isActive(); $this->_isDefault = $formulary->isDefault(); return $this; }
public function processUploadCsvAction() { $name = preg_replace('/[^a-zA-Z]+/', '', $this->_getParam('name', '')); $data = array('message' => __('Successfully uploaded')); $uploadFileName = $_FILES['uploadFile']['tmp_name']; $row = 0; if (($handle = fopen($uploadFileName, 'r')) !== false) { $template = array('' => '', 'fullNDC' => '', 'directions' => '', 'comments' => '', 'schedule' => '', 'labelId' => '', 'externalUrl' => '', 'price' => '', 'qty' => '', 'quantityQualifier' => '', 'keywords' => '', 'deaSchedule' => '', 'print' => '', 'description' => '', 'dose' => '', 'route' => '', 'prn' => '', 'refills' => '', 'daysSupply' => '', 'substitution' => ''); $arrangements = array('', 'fullNDC', 'directions', 'comments', 'schedule', 'labelId', 'externalUrl', 'price', 'qty', 'quantityQualifier', 'keywords', 'deaSchedule', 'print', 'description', 'dose', 'route', 'prn', 'refills', 'daysSupply', 'substitution'); while (($data = fgetcsv($handle, 0, ',')) !== false) { // 0 = all chars in a line $ctr = count($data); $row++; if ($row == 1) { // headers if ($ctr != count($template)) { $data = array('error' => __('Columns not matched')); break; } // remove all existing formularies $db = Zend_Registry::get('dbAdapter'); $formulary = new FormularyItem($name); $db->delete($formulary->getName()); continue; } $formularyData = $template; for ($i = 1; $i < $ctr; $i++) { $formularyData[$arrangements[$i]] = $data[$i]; } $formulary = new FormularyItem($name); $formulary->populateWithArray($formularyData); $formulary->persist(); } fclose($handle); } else { $data = array('error' => __('Failed opening the uploaded file. Please re-upload')); } $json = Zend_Controller_Action_HelperBroker::getStaticHelper('json'); $json->suppressExit = true; $jsonData = $json->direct($data, false); $this->getResponse()->setHeader('Content-Type', 'text/html'); $this->view->result = $jsonData; $this->render(); }