/**
  */
 public function actionPopulateclassdivisions()
 {
     ClassDivision::deleteAll();
     $classes = AClass::find()->all();
     $groups = [];
     foreach ($classes as $class) {
         $key = join('|', [$class->room_id, $class->day_id, $class->type_id, $class->frequency_id, $class->start_time]);
         //echo $key . ': ' . $class->fullName . PHP_EOL;
         if (!isset($groups[$key])) {
             $groups[$key] = [];
         }
         $groups[$key][] = $class;
     }
     foreach ($groups as $key => $group) {
         $classId = null;
         foreach ($group as $class) {
             // use the ID of the first class in the group for all of them
             if (null === $classId) {
                 $classId = $class->id;
             }
             $cd = new ClassDivision();
             $cd->class_id = $classId;
             $cd->division_id = $class->division_id;
             if (!$cd->save()) {
                 echo $key . ' failed to save' . PHP_EOL;
             }
         }
     }
 }
 /**
  * @return string JSON used to fill a select box.
  */
 public function actionCreateStudentHandAnchors($division_id)
 {
     $query = AClass::find()->joinWith('school')->joinWith('divisions')->joinWith('day')->where(['location_id' => Yii::$app->user->school->id, 'division_id' => $division_id, 'type_id' => 1])->orderBy(['-`day`.`ord`' => SORT_DESC, 'start_time' => SORT_ASC]);
     $models = $query->all();
     $data = [];
     foreach ($models as $m) {
         $data[] = ['value' => $m->id, 'text' => $m->fullName];
     }
     return Json::encode($data);
 }
 public function search($params)
 {
     $query = AClass::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'day_id' => $this->day_id, 'division_id' => $this->division_id, 'room_id' => $this->room_id, 'instructor_id' => $this->instructor_id, 'start_time' => $this->start_time, 'type_id' => $this->type_id, 'frequency' => $this->frequency, 'active' => $this->active]);
     return $dataProvider;
 }
Example #4
0
 /**
  * @return \app\models\AClass[] available class choices
  */
 public function getWeaponAnchors()
 {
     return AClass::find()->joinWith(['school', 'day', 'frequency', 'type'])->andWhere(['location_id' => Yii::$app->user->schoolId])->andWhere(['class_type.name' => 'Weapons'])->andFilterWhere(['division_id' => $this->division_id])->orFilterWhere(['class.id' => $this->affiliation->weapon_anchor_id])->orderBy(['-`day`.`ord`' => SORT_DESC, 'start_time' => SORT_ASC])->all();
 }