Blame | Last modification | View Log | RSS feed
<?phpdate_default_timezone_set("Asia/Kolkata");class UploadoffersShell extends AppShell {public $uses = array('Offer');public function main() {$file = fopen($this->args[0],"r");$row = 0;$offers = array();$columnNames = array();while(! feof($file)) {if($row++==0){$columnNames = fgetcsv($file);// $this->out(print_r($columnNames,1));continue;}$line = fgetcsv($file);$this->out(sizeof($line));$temp = array();if(sizeof($line)==10) {foreach($columnNames AS $key => $name) {/*if($key<2) {$temp[$name] = date('Y/m/d h:i:00',strtotime($line[$key]));}else{*/$temp[$name] = $line[$key];//}}$offers[] = $temp;}}// $this->out(print_r($offers,1));die;fclose($file);$this->Offer->create();if($this->Offer->saveall($offers)) {$this->out("all saved");}else{$this->out(print_r($this->Offer->validationErrors,1));}}private function formatDate($datestr){$dateParts = explode(' ', $datestr);$yrmnd = explode("/", $dateParts[0]);return $yrmnd[2].'/'.$yrmnd[1].'/'.$yrmnd[0].' '.$dateParts[1];}}