示例#1
0
 public function createOrUpdate($fields)
 {
     $sid = self::find($fields["address"], $fields["zipcode"]);
     echo "Creating or updating store\n";
     if ($sid) {
         return $sid;
     } else {
         $opening_hours = array();
         foreach ($fields['openingHours'] as $day => $hours) {
             switch (count($hours)) {
                 case 0:
                     $oh = array('weekday' => $day, 'closed' => true);
                     break;
                 case 1:
                     $oh = array('weekday' => $day, 'open_am' => $hours[0]);
                     break;
                 case 2:
                     $oh = array('weekday' => $day, 'open_am' => $hours[0], 'close_am' => $hours[1]);
                     break;
                 case 3:
                     $oh = array('weekday' => $day, 'open_am' => $hours[0], 'close_am' => $hours[1], 'open_pm' => $hours[2]);
                     break;
                 case 4:
                     $oh = array('weekday' => $day, 'open_am' => $hours[0], 'close_am' => $hours[1], 'open_pm' => $hours[2], 'close_pm' => $hours[3]);
                     break;
             }
             $opening_hours[] = $oh;
         }
         $fields['openingHours'] = $opening_hours;
         $res = RestLayer::post('v1/stores', $fields, array('Authorization' => "Bearer " . self::token()))[2];
         return json_decode($res, true)["id"];
     }
 }
示例#2
0
 public function createOrUpdate($name)
 {
     $city = self::find($name);
     if ($city) {
         return $city;
     } else {
         $res = RestLayer::post('v1/cities', array("name" => $name), array('Authorization' => "Bearer " . self::token()))[2];
         return json_decode($res, true)['id'];
     }
 }
示例#3
0
 public function createOrUpdate($fields)
 {
     $lid = self::find($fields["url"]);
     echo "Creating or updating leaflet\n";
     if ($lid) {
         return $lid;
     } else {
         $res = RestLayer::post('v1/leaflets', $fields, array('Authorization' => "Bearer " . self::token()))[2];
         return json_decode($res, true)["id"];
     }
 }