Initial import from local backup (Documents-Playground/pakerpale)
This commit is contained in:
42
homestead/application/models/StationModel.php
Normal file
42
homestead/application/models/StationModel.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class StationModel extends MY_Model
|
||||
{
|
||||
private $table = 'cm_station';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
private function findByCategoryConfigured()
|
||||
{
|
||||
return $this->db->where('Category >', 0)->select('Id, Category, Title')->get('cm_station')->result();
|
||||
}
|
||||
|
||||
public function save($stations)
|
||||
{
|
||||
$categorizedStations = $this->findByCategoryConfigured();
|
||||
$this->db->where('Category <=', 0)->delete($this->table);
|
||||
$inserted = array();
|
||||
$updated = array();
|
||||
foreach ($stations as $key => $station) {
|
||||
$upd = false;
|
||||
foreach ($categorizedStations as $c) {
|
||||
if ($c->Title == $station->Title) {
|
||||
$stations[$key]->Category = $c->Category;
|
||||
$upd = true;
|
||||
$this->db->where($c->Id)->update($this->table, $station);
|
||||
array_push($updated, $c->Id);
|
||||
}
|
||||
}
|
||||
if (!$upd) {
|
||||
$this->db->insert($this->table, $station);
|
||||
array_push($inserted, $this->db->insert_id());
|
||||
}
|
||||
}
|
||||
return ['inserted' => $inserted, 'updated' => $updated];;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user