示例#1
0
文件: Alert.php 项目: sbraz/LBCAlerte
 public function save(\App\Mail\Alert $alert, $forceInsert = false)
 {
     $options = $alert->toArray();
     if (!$alert->id || $forceInsert) {
         $options["user_id"] = $this->_user->getId();
         if (!$alert->id) {
             $id = sha1(uniqid());
             $alert->id = $id;
         }
         $options["idstr"] = $alert->id;
         unset($options["id"]);
         $sqlOptions = array();
         foreach ($options as $name => $value) {
             if ($value === null) {
                 $value = "NULL";
             } elseif (is_bool($value)) {
                 $value = (int) $value;
             } elseif (!is_numeric($value)) {
                 $value = "'" . $this->_connection->real_escape_string($value) . "'";
             }
             $sqlOptions[$name] = $value;
         }
         $this->_connection->query("INSERT INTO " . $this->_table . " (`" . implode("`, `", array_keys($options)) . "`, `date_created`) VALUES (" . implode(", ", $sqlOptions) . ", NOW())");
     } else {
         $idStr = $options["id"];
         $sqlOptions = array();
         unset($options["id"]);
         foreach ($options as $name => $value) {
             if ($value === null) {
                 $value = "NULL";
             } elseif (is_bool($value)) {
                 $value = (int) $value;
             } elseif (!is_numeric($value)) {
                 $value = "'" . $this->_connection->real_escape_string($value) . "'";
             }
             $sqlOptions[] = "`" . $name . "` = " . $value;
         }
         $this->_connection->query("UPDATE " . $this->_table . " SET\n                " . implode(",", $sqlOptions) . " WHERE idstr = '" . $this->_connection->real_escape_string($idStr) . "'");
     }
     return $this;
 }
示例#2
0
文件: User.php 项目: sbraz/LBCAlerte
 public function delete(\App\User\User $user)
 {
     $this->_connection->query("DELETE FROM " . $this->_table . " WHERE id = " . $user->getId());
     return $this;
 }
示例#3
0
文件: User.php 项目: sbraz/LBCAlerte
 protected function _deleteUserOptions(\App\User\User $user)
 {
     $dir = DOCUMENT_ROOT . DS . "var" . DS . "configs";
     $filename = $dir . DS . "user_" . $user->getUsername() . ".json";
     if (is_file($filename)) {
         unlink($filename);
     }
     return $this;
 }