Пример #1
0
 public static function normalize($db, $userid, $parameters)
 {
     $tripid = Exporter::get_default("t", $parameters);
     $tripname = Exporter::get_default("tn", $parameters);
     if (!is_null($tripname)) {
         if (!is_null($tripid)) {
             throw new InvalidArgumentException("Either define trip id or name but not both.");
         } else {
             if ($tripname === "<None>") {
                 $tripid = null;
             } else {
                 if ($tripname === "") {
                     $tripid = true;
                 } else {
                     $tripid = $db->exec_sql("SELECT `ID` FROM `trips` WHERE `Name` = ? AND `FK_Users_ID` = ?", $tripname, $userid)->fetchColumn();
                 }
             }
         }
     } else {
         if (!is_null($tripid)) {
             if ($tripid === "n") {
                 $tripid = null;
             } else {
                 if ($tripid === "a") {
                     $tripid = true;
                 } else {
                     if (ctype_digit($parameters["t"])) {
                         $tripid = intval($tripid);
                     } else {
                         throw new InvalidArgumentException("Trip id must be number.");
                     }
                 }
             }
         } else {
             throw new InvalidArgumentException("Neither tripname or trip id are defined.");
         }
     }
     return $tripid;
 }