Exemplo n.º 1
0
 public function main()
 {
     $name = Utility::cleanString($_POST["name"]);
     $notes = Utility::cleanString($_POST["notes"]);
     $is_chapter = Utility::cleanBoolean($_POST["is_chapter"]);
     $all_day_event = !$is_chapter && Utility::cleanBoolean($_POST["is_all_day"]);
     $start = Utility::getDateTimeFromDateYmdHis(Utility::cleanString($_POST["time_start"]));
     $end = Utility::getDateTimeFromDateYmdHis(Utility::cleanString($_POST["time_end"]));
     $is_repeating = !$is_chapter && Utility::cleanBoolean($_POST["is_repeating"]);
     $n_times = Utility::cleanInt($_POST["n_times"], 2);
     $repeat_type = Utility::cleanInt($_POST["repeat_type"], Group::TYPE_DAYS, Group::TYPE_YEARS);
     if ($name == "") {
         $this->setError(self::$E_INVALID_NAME);
     } else {
         if (!$all_day_event && !$start) {
             $this->setError(self::$E_INVALID_DATE_START);
         } else {
             if (!$all_day_event && !$is_chapter && !$end) {
                 $this->setError(self::$E_INVALID_DATE_END);
             } else {
                 if (!$all_day_event && $end <= $start) {
                     $this->setError(self::$E_INVALID_DATE_END_BEFORE_START);
                 } else {
                     if ($is_repeating) {
                         if ($n_times === false) {
                             $this->setError(self::$E_INVALID_REPEAT_TIME);
                         } else {
                             if ($repeat_type === false) {
                                 $this->setError(self::$E_INVALID_REPEAT_TYPE);
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($this->hasError()) {
         return [];
     }
     $_events = [];
     if ($all_day_event) {
         $start = $start ?: null;
         $end = $end ?: null;
     }
     if (!$is_repeating) {
         $_event = new Event($this->_pdo);
         $_event->create($name, $notes, $all_day_event, $is_chapter, $this->_auth->getUser(), $end, $start);
         $_events[] = $_event;
     } else {
         $_group = new Group($this->_pdo);
         $_group->create($name, $notes, $all_day_event, $is_chapter, $n_times, $this->_auth->getUser(), $repeat_type, $start, $end);
         $_events = $_group->generateEvents();
     }
     return $_events;
 }
Exemplo n.º 2
0
 /**
  * @param BasePDO $_pdo
  * @param Group $_group
  * @return self[]
  */
 public static function findAllForGroup(BasePDO $_pdo, Group $_group) : array
 {
     return $_pdo->fetchAssoc("SELECT * FROM `event` WHERE group_id = :id", ["id" => $_group->getId()], function ($row) use($_pdo, $_group) {
         $row = new self($_pdo, $row);
         $row->_group = $_group;
         return $row;
     });
 }