Commit d7e579fb authored by Raph El's avatar Raph El
Browse files

Hotfix event timezone

parent 9be94055
......@@ -7432,8 +7432,11 @@ if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
public function actionRecurentEvents() {
if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
$events=PHDB::find(Event::COLLECTION,
array("openingHours" => array('$exists' => 1)),
array("name", "openingHours", "startDate", "endDate", "created", "updated", "modified", "creator", "source", "address"));
array(
"openingHours" => array('$exists' => 1),
"created_at" => array('$exists' => 0)
),
array("name", "openingHours", "startDate", "endDate", "created", "creator", "source", "address.addressCountry"));
$count = array(
"source" => array(),
"notSource" => 0,
......@@ -7444,11 +7447,16 @@ if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
"fuseau" => array()
);
$timezone = array(
"FR" => "Europe/Paris",
"BE" => "Europe/Brussels",
"RE" => "Indian/Reunion"
);
//Rest::json($count); exit;
foreach ($events as $key => $value) {
if( !empty($value["address"]) ){
if(empty($count[$value["address"]["addressCountry"]]))
if( !empty($value["address"]) && !empty($value["address"]["addressCountry"]) ){
if(empty($count[$value["address"]["addressCountry"]]) )
$count[$value["address"]["addressCountry"]] = 0 ;
$count[$value["address"]["addressCountry"]]++;
......@@ -7456,6 +7464,19 @@ if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
if(empty($count["fuseau"][$value["address"]["addressCountry"]]))
$count["fuseau"][$value["address"]["addressCountry"]] = geoip_time_zone_by_country_and_region($value["address"]["addressCountry"]) ;
if(!empty($timezone[$value["address"]["addressCountry"]])){
$cc = date(DateTime::ISO8601, $value["created"] ) ;
//date_default_timezone_set ( $timezone[$value["address"]["addressCountry"]] );
$mars = new DateTimeZone($timezone[$value["address"]["addressCountry"]]);
$events[$key]["created_at"] = new DateTime($cc) ;
$events[$key]["created_at"]->setTimezone($mars);
//$events[$key]["created_atFormat"] = $events[$key]["created_at"]->format(DateTime::ISO8601);
$events[$key]["timeZone"] = $timezone[$value["address"]["addressCountry"]] ;
$ts = $events[$key]["created_at"]->getTimestamp();
$events[$key]["created_at"] = new MongoDate($ts);
}
}else{
if(!empty($value["source"])){
if(empty($count["source"][$value["source"]["key"]]))
......@@ -7466,17 +7487,104 @@ if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
$count["notAddress"]++;
}
$count["all"]++;
// if(!empty($value["creator"])){
// $events[$key]["creatorNew"] = PHDB::findOneById( Person::COLLECTION,
// $value["creator"],
// array() );
// }
// $events[$key]["createdNew"] =date(DateTime::ISO8601, $value["created"] ) ;
if(!empty($events[$key]["created_at"])){
PHDB::update(Event::COLLECTION,
array("_id" => $events[$key]["_id"]),
array('$set' => array( "created_at" => $events[$key]["created_at"],
"timeZone" => $events[$key]["timeZone"]) )
);
}
}
$result = array(
"count" => $count,
"events" => $events,
);
Rest::json($result);
}
}
public function actionEventsTimeZone() {
if( Role::isSuperAdmin(Role::getRolesUserId(Yii::app()->session["userId"]) )){
$events=PHDB::find(Event::COLLECTION,
array(
"openingHours" => array('$exists' => 0),
"startDateNew" => array('$exists' => 0),
"source.key" => "hva"
),
array("name", "openingHours", "startDate", "endDate", "created", "source", "address.addressCountry"));
$count = array(
"source" => array(),
"notSource" => 0,
"FR" => 0,
"RE" => 0,
"all" => 0,
"notAddress" => 0,
"fuseau" => array()
);
$timezone = array(
"FR" => "Europe/Paris",
"BE" => "Europe/Brussels",
"RE" => "Indian/Reunion"
);
//Rest::json($count); exit;
foreach ($events as $key => $value) {
if( !empty($value["address"]) && !empty($value["address"]["addressCountry"]) ){
if(empty($count[$value["address"]["addressCountry"]]))
$count[$value["address"]["addressCountry"]] = 0 ;
$count[$value["address"]["addressCountry"]]++;
if(empty($count["fuseau"][$value["address"]["addressCountry"]]))
$count["fuseau"][$value["address"]["addressCountry"]] = geoip_time_zone_by_country_and_region($value["address"]["addressCountry"]) ;
if(!empty($timezone[$value["address"]["addressCountry"]])){
$mars = new DateTimeZone($timezone[$value["address"]["addressCountry"]]);
$cc = date(DateTime::ISO8601, $value["startDate"]->sec ) ;
$events[$key]["startDateNew"] = new DateTime($cc) ;
$events[$key]["startDateNew"]->setTimezone($mars);
$events[$key]["startDateNew2"] = $events[$key]["startDateNew"]->format(DateTime::ISO8601);
$events[$key]["timeZone"] = $timezone[$value["address"]["addressCountry"]] ;
$ts = $events[$key]["startDateNew"]->getTimestamp();
$events[$key]["startDateNew"] = new MongoDate($ts);
//$events[$key]["created_atFormat"] = $events[$key]["created_at"]->format(DateTime::ISO8601);
}
}else{
if(!empty($value["source"])){
if(empty($count["source"][$value["source"]["key"]]))
$count["source"][$value["source"]["key"]] = 0;
$count["source"][$value["source"]["key"]]++;
}else
$count["notSource"]++;
$count["notAddress"]++;
}
$count["all"]++;
if(!empty($events[$key]["startDateNew"])){
PHDB::update(Event::COLLECTION,
array("_id" => $events[$key]["_id"]),
array('$set' => array( "startDateNew" => $events[$key]["startDateNew"],
"timeZone" => $events[$key]["timeZone"] ) )
);
}
}
Rest::json($count);
$result = array(
"count" => $count,
"events" => $events,
);
Rest::json($result);
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment