public static function setStationGroupArray($data)
 {
     self::model()->deleteAll();
     foreach ($data as $station_id => $groups) {
         foreach ($groups as $group_id => $check) {
             if ($check == 1) {
                 $item = new StationGroupDestination();
                 $item->station_id = $station_id;
                 $item->group_id = $group_id;
                 $item->save(false);
             }
         }
     }
 }
 public function init()
 {
     $this->stations = Station::getStationName();
     $this->groups = StationGroup::getGroupName();
     $this->data = StationGroupDestination::getStationGroupArray();
 }
Beispiel #3
0
 /**
  * station groups
  */
 public function actionStationGroups()
 {
     $accessEdit = Yii::app()->user->isSuperAdmin();
     $group = new StationGroup();
     if (isset($_GET['group_id'])) {
         $group_id = $_GET['group_id'];
         if ($_GET['action'] == 'delete') {
             StationGroup::deleteGroupId($group_id);
             $this->redirect($this->createUrl('admin/StationGroups'));
         }
         $group = StationGroup::model()->findByPk($group_id);
     }
     if (isset($_POST['StationGroup']['name']) && $_POST['StationGroup']['name']) {
         if (isset($_POST['StationGroup']['group_id']) && $_POST['StationGroup']['group_id']) {
             $group = StationGroup::model()->findByPk($_POST['StationGroup']['group_id']);
         }
         $group->name = $_POST['StationGroup']['name'];
         if ($group->validate()) {
             $group->save();
             $this->redirect($this->createUrl('admin/StationGroups'));
         }
     }
     if (isset($_POST['StationGroupsForm'])) {
         StationGroupDestination::setStationGroupArray($_POST['StationGroupsForm']['data']);
     }
     $form = new StationGroupsForm();
     $this->render('station_groups', array('form' => $form, 'group' => $group, 'accessEdit' => $accessEdit));
 }