Beispiel #1
0
 public function run()
 {
     $signups = \Workshop\SignUp::get_all()->where(array("lunch" => true, "canceled" => false))->add_filter(array("attr" => "id_assigned_to", "type" => "exact", "exact" => [3, 5, 9, 10]))->fetch();
     $stats = array();
     $default = [1, 2];
     $foods = \Food\Item::get_all()->where(array('date' => $this::DATE))->fetch();
     $canSend = array();
     foreach ($foods as $food) {
         $canSend[$food->id] = $food;
         $stats[$food->id] = 0;
     }
     foreach ($signups as $person) {
         $food = $person->food->where(array('date' => $this::DATE))->fetch();
         if (count($food)) {
             foreach ($food as $item) {
                 $stats[$item->id] += 1;
             }
         } else {
             foreach ($default as $item) {
                 $stats[$item] += 1;
             }
         }
     }
     $this->partial('stats/delivery', array("stats" => $stats, "foods" => $canSend));
 }
Beispiel #2
0
 public function run_form()
 {
     $end = \DateTime::createFromFormat('Y-m-d H:i:s', static::EDITABLE_UNTIL);
     $this->req('symvar');
     $check = \Workshop\Check::get_first(array("symvar" => $this->symvar))->fetch();
     if (!$check) {
         throw new \System\Error\NotFound();
     }
     $signup = $check->signup;
     if (!$signup) {
         throw new \System\Error\NotFound();
     }
     $picked = $signup->food->fetch();
     $food = \Food\Item::get_all(array("edible" => true))->sort_by('blank desc')->fetch();
     $days = array();
     $data = array('soup_2016-05-14' => 1, 'main_2016-05-14' => 11, 'soup_2016-05-15' => 5, 'main_2016-05-15' => 12);
     foreach ($picked as $item) {
         $date = $item->date->format('Y-m-d');
         $type = $item->type == 1 ? 'soup' : 'main';
         $name = $type . '_' . $date;
         $data[$name] = $item->id;
     }
     foreach ($food as $item) {
         $date = $item->date->format('Y-m-d');
         $type = $item->type == 1 ? 'soup' : 'main';
         if (!array_key_exists($date, $days)) {
             $days[$date] = array("date" => $item->date, "soup" => array(), "main" => array());
         }
         $days[$date][$type][] = array("name" => $item->name, "value" => $item->id);
     }
     $f = $this->response->form(array("desc" => 'Předvol si obědy na Improtřesk 2016. Tato možnost končí ' . $end->format('j. n. v H:i') . '. Můžeš si zvolit "překvapte mě" a my jídlo vybereme za tebe.', "id" => 'food-picker', "default" => $data));
     foreach ($days as $date => $day) {
         $f->input(array("type" => 'radio', "label" => 'Polévka ' . $day['date']->format('j.n.'), "name" => 'soup_' . $date, "options" => $day['soup'], "required" => true));
         $f->input(array("type" => 'radio', "label" => 'Hlavní chod ' . $day['date']->format('j.n.'), "name" => 'main_' . $date, "options" => $day['main'], "required" => true));
     }
     $f->submit('Uložit');
     $f->out($this);
     if ($f->submited()) {
         if ($f->passed()) {
             $data = $f->get_data();
             $use = array();
             foreach ($data as $key => $val) {
                 if ($val != 666 && (strpos($key, 'soup') === 0 || strpos($key, 'main') === 0)) {
                     $use[] = $val;
                 }
             }
             $signup->food = $use;
             $signup->save();
             $this->partial('forms/message', array("msg" => 'Uloženo'));
         } else {
             $this->partial('forms/message', array("msg" => 'Neplatný vstup, zkus to prosím znova'));
         }
     }
 }
 public function run()
 {
     $ppl = \Workshop\SignUp::get_all(array("solved" => true, "lunch" => true, 'canceled' => false))->add_filter(array("attr" => 'id_assigned_to', "type" => 'is_null', "is_null" => false))->sort_by('name_first, name_last')->fetch();
     $defaults = array('2016-05-14' => array(\Food\Item::find(1), \Food\Item::find(2)), '2016-05-15' => array(\Food\Item::find(5), \Food\Item::find(7)));
     $participants = array();
     $focus = array('2016-05-14', '2016-05-15');
     foreach ($ppl as $person) {
         $days = array();
         foreach ($focus as $date_str) {
             $date = new \DateTime($date_str);
             $days[$date_str] = array("date" => $date->format('d. m. Y'), "items" => array(), 'food' => $defaults[$date->format('Y-m-d')]);
             $food = $person->food->where(array("date" => $date_str))->fetch();
             if (any($food)) {
                 $days[$date_str]['food'] = $food;
             }
         }
         $participants[] = array("days" => $days, "name" => $person->toName());
     }
     $this->partial('stats/participant-lunch', array("participants" => $participants));
 }
Beispiel #4
0
 public function run()
 {
     $food = \Food\Item::get_all(array("edible" => true))->sort_by('type, blank desc')->fetch();
     $days = array();
     foreach ($food as $item) {
         $date = $item->date->format('Y-m-d');
         if (!array_key_exists($date, $days)) {
             $days[$date] = array("date" => $item->date, "items" => array());
         }
         $item->type_label = $item->type == 1 ? 'Polévka' : 'Hlavní';
         $item->total = $item->eaters->where(array("solved" => true))->count();
         if ($item->blank) {
             $today_picked = \Workshop\SignUp::get_all()->where(array('solved' => true, 'canceled' => false))->join('workshop_signup_has_food_item', 'USING(id_workshop_signup)', 'wshfi', 'left')->join('food_item', 'USING(id_food_item)', 'fi', 'left')->where(array('type' => $item->type, 'date' => $item->date->format('Y-m-d H:i:s')), 'fi')->count();
             $signups_total = \Workshop\SignUp::get_all()->where(array('solved' => true, 'lunch' => true))->count();
             $unpicked = $signups_total - $today_picked;
             $item->total += $unpicked;
         }
         $days[$date]['items'][] = $item;
     }
     $this->partial('stats/meals', array("days" => $days));
 }