Esempio n. 1
0
 /**
  * Creates or updates the ban and returns it.
  *
  * @param WiseChatBan $ban
  *
  * @return WiseChatBan
  * @throws Exception On validation error
  */
 public function save($ban)
 {
     global $wpdb;
     // low-level validation:
     if ($ban->getTime() === null) {
         throw new Exception('Time cannot equal null');
     }
     if ($ban->getCreated() === null) {
         throw new Exception('Created time cannot equal null');
     }
     if ($ban->getIp() === null) {
         throw new Exception('IP address cannot equal null');
     }
     // prepare ban data:
     $columns = array('time' => $ban->getTime(), 'created' => $ban->getCreated(), 'ip' => $ban->getIp());
     // update or insert:
     if ($ban->getId() !== null) {
         $wpdb->update($this->table, $columns, array('id' => $ban->getId()), '%s', '%d');
     } else {
         $wpdb->insert($this->table, $columns);
         $ban->setId($wpdb->insert_id);
     }
     return $ban;
 }