Flake\Core\Model\Db::persist PHP Method

persist() public method

public persist ( )
    function persist()
    {
        if ($this->floating()) {
            $GLOBALS["DB"]->exec_INSERTquery(self::getDataTable(), $this->getData());
            $sPrimary = $GLOBALS["DB"]->lastInsertId();
            $this->initByPrimary($sPrimary);
            $this->bFloating = false;
        } else {
            $GLOBALS["DB"]->exec_UPDATEquery(self::getDataTable(), self::getPrimaryKey() . "='" . $GLOBALS["DB"]->quote($this->getPrimary()) . "'", $this->getData());
        }
    }

Usage Example

Example #1
0
 public function persist()
 {
     $bFloating = $this->floating();
     # Persisted first, as Model users loads this data
     $this->oIdentityPrincipal->set("uri", "principals/" . $this->get("username"));
     $this->oIdentityPrincipal->persist();
     parent::persist();
     if ($bFloating) {
         # Creating default calendar for user
         $oDefaultCalendar = new \Baikal\Model\Calendar();
         $oDefaultCalendar->set("principaluri", "principals/" . $this->get("username"))->set("displayname", "Default calendar")->set("uri", "default")->set("ctag", 1)->set("description", "Default calendar")->set("components", "VEVENT,VTODO");
         $oDefaultCalendar->persist();
         # Creating default address book for user
         $oDefaultAddressBook = new \Baikal\Model\AddressBook();
         $oDefaultAddressBook->set("principaluri", "principals/" . $this->get("username"))->set("displayname", "Default Address Book")->set("uri", "default")->set("description", "Default Address Book for " . $this->get("displayname"));
         $oDefaultAddressBook->persist();
     }
 }