public function save()
{
if (!$this->id) {
$this->db->Execute("INSERT INTO roles SET\n name\t\t= ?,\n dtadded = NOW(),\n description\t= ?,\n generation\t= ?,\n origin\t\t= ?,\n env_id\t\t= ?,\n cat_id = ?,\n client_id\t= ?,\n behaviors\t= ?,\n\n added_by_userid = ?,\n added_by_email = ?,\n\n os_id\t\t = ?,\n is_scalarized\t= ?\n ", array($this->name, $this->description, $this->generation, $this->origin, empty($this->envId) ? null : $this->envId, $this->catId, empty($this->clientId) ? null : $this->clientId, $this->behaviorsRaw, $this->addedByUserId, $this->addedByEmail, $this->osId, $this->isScalarized));
$this->id = $this->db->Insert_ID();
$this->db->Execute("DELETE FROM role_behaviors WHERE role_id = ?", array($this->id));
foreach ($this->getBehaviors() as $behavior) {
$this->db->Execute("INSERT IGNORE INTO role_behaviors SET role_id = ?, behavior = ?", array($this->id, $behavior));
}
} else {
$this->db->Execute("\n UPDATE roles SET\n name\t\t= ?,\n description\t= ?,\n behaviors\t= ?,\n dt_last_used = ?,\n is_quick_start = ?,\n is_deprecated = ?\n WHERE id =?\n ", array($this->name, $this->description, $this->behaviorsRaw, $this->dtLastUsed, $this->isQuickStart, $this->isDeprecated, $this->id));
$this->db->Execute("DELETE FROM role_behaviors WHERE role_id = ?", array($this->id));
foreach ($this->getBehaviors() as $behavior) {
$this->db->Execute("INSERT IGNORE INTO role_behaviors SET role_id = ?, behavior = ?", array($this->id, $behavior));
}
}
$this->syncAnalyticsTags();
return $this;
}