public function save()
{
$this->events()->trigger(__CLASS__, 'before.save', $this);
$arraySave = array('name' => $this->getName(), 'description' => $this->getDescription());
try {
$roleId = $this->getId();
if (empty($roleId)) {
$this->insert($arraySave);
$this->setId($this->getLastInsertId());
} else {
$this->update($arraySave, array('id' => $this->getId()));
}
$permissions = $this->getPermissions();
if (!empty($permissions)) {
$aclTable = new TableGateway('user_acl', $this->getAdapter());
$aclTable->delete(array('user_acl_role_id' => $this->getId()));
foreach ($permissions as $permissionId => $value) {
if (!empty($value)) {
$aclTable->insert(array('user_acl_role_id' => $this->getId(), 'user_acl_permission_id' => $permissionId));
}
}
}
$this->events()->trigger(__CLASS__, 'after.save', $this);
return $this->getId();
} catch (\Exception $e) {
$this->events()->trigger(__CLASS__, 'after.save.failed', $this);
throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
}
}