Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
13532 anikendra 1
<?php
2
date_default_timezone_set("Asia/Kolkata");
3
class UploadoffersShell extends AppShell {
4
    public $uses = array('Offer');
5
 
6
    public function main() {
7
	$file = fopen($this->args[0],"r");
8
	$row = 0;
9
	$offers = array();
10
	$columnNames = array();
11
	while(! feof($file)) {
12
		if($row++==0){
13
			$columnNames = fgetcsv($file);
14
//			$this->out(print_r($columnNames,1));
15
			continue;
16
		}
17
		$line = fgetcsv($file);
18
		$this->out(sizeof($line));
19
		$temp = array();
20
		if(sizeof($line)==10) {
21
			foreach($columnNames AS $key => $name) {
22
				/*
23
				if($key<2) {
24
					$temp[$name] = date('Y/m/d h:i:00',strtotime($line[$key]));
25
				}else{
26
				*/
27
				$temp[$name] = $line[$key];
28
				//}
29
			}
30
			$offers[] = $temp; 
31
		}
32
	}
33
//	$this->out(print_r($offers,1));die;
34
	fclose($file);
35
	$this->Offer->create();
36
	if($this->Offer->saveall($offers)) {
37
		$this->out("all saved");
38
	}else{
39
		$this->out(print_r($this->Offer->validationErrors,1));
40
	}
41
    }
42
 
43
 
44
    private function formatDate($datestr){
45
    	$dateParts = explode(' ', $datestr);
46
    	$yrmnd = explode("/", $dateParts[0]);
47
    	return $yrmnd[2].'/'.$yrmnd[1].'/'.$yrmnd[0].' '.$dateParts[1];
48
    }
49
}