コード例 #1
0
ファイル: Home.php プロジェクト: JC5/marauder
 /**
  * Gets the weather data as used by the front page.
  *
  * @param Device $thermostat
  * @param array  $fields
  *
  * @return array
  */
 public function getWeather(Device $thermostat, array $fields = [])
 {
     $return = [];
     // get the city by the structure's info:
     $city = City::findCity($thermostat->structure->postal_code, $thermostat->structure->country_code);
     // get some weather data going.
     $query = Report::onDay(new Carbon())->whereCityId($city->id);
     $get = ['reports.time'];
     foreach ($fields as $field) {
         $query->withReportValue($field);
         $get[] = str_replace('.', '_', $field) . '.value as ' . str_replace('.', '_', $field);
     }
     $result = $query->orderBy('reports.time', 'DESC')->first($get);
     if ($result) {
         $return = $result->toArray();
     }
     foreach ($return as $field => $value) {
         $return[$field] = Format::format($field, $value);
     }
     return $return;
 }
コード例 #2
0
ファイル: TableController.php プロジェクト: JC5/marauder
 /**
  * Get raw entries with a selected set of values to grab.
  */
 public function rawLogEntriesTable()
 {
     $title = 'Raw log entries';
     $fields = Config::get('marauder.rawLogEntries');
     // all of the users log entries:
     $get = ['log_entries.id', 'structures.time_zone', 'log_entries.time', 'devices.name'];
     $query = LogEntry::leftJoin('devices', 'devices.id', '=', 'log_entries.device_id')->leftJoin('structures', 'structures.id', '=', 'devices.structure_id')->where('structures.user_id', Auth::user()->id)->take(Config::get('marauder.logTableLimit'))->orderBy('time', 'DESC')->orderBy('devices.id', 'ASC');
     // ignore stuff from the query:
     $ignore = ['id', 'time_zone'];
     foreach ($fields as $field) {
         $query->withLogValue($field);
         $get[] = $field . '.value as ' . $field;
     }
     $result = $query->get($get);
     if ($result->count() > 0) {
         $result = $result->toArray();
     }
     foreach ($result as $key => $entry) {
         foreach ($entry as $name => $value) {
             if ($name == 'time') {
                 // time zone correction!
                 $value = new Carbon($value, 'UTC');
                 $timezone = strlen($result[$key]['time_zone']) > 0 ? $result[$key]['time_zone'] : 'Europe/Amsterdam';
                 $value->setTimezone($timezone);
             }
             $result[$key][$name] = Format::format($name, $value);
         }
     }
     return View::make('raw.table', compact('result', 'ignore', 'title'));
 }