public function existsSetting($key) { $cond = new Moonlake_Model_Condition('AND'); $cond->is('userid', $this->user->getId()); $cond->is('key', $key); $data = $this->model->getEntriesByCondition($cond); return isset($data[0]); }
public function deleteAuthorizationForRole($context, Moonlake_Auth_Role $role, $action) { $cond = new Moonlake_Model_Condition(); $cond->is('context', $context); $cond->is('role', $role->getId()); $cond->is('action', $action); $this->model->deleteEntriesByCondition($cond); }
public function delete() { $mb = $this->model->getBackend(); $auth = new Moonlake_Auth_AuthModel($mb); $cond = new Moonlake_Model_Condition(); $cond->is('role', $this->roleid); $auth->deleteEntriesByCondition($cond); $roluser = new Moonlake_Auth_UsersRolesModel($mb); $roluser->deleteEntriesByCondition($cond); $this->model->deleteEntry($this->roleid); }
/** * Update all entries which fit the conditions. * @param String area the area * @param Moonlake_Model_Condition $cond * @param String[] $fields an array with changes */ public function updateEntriesByCondition($area, Moonlake_Model_Condition $cond, $fields) { $sql = 'UPDATE ' . $this->tableName($area) . ' SET '; $count = 0; foreach ($fields as $key => $val) { if ($count++ > 0) { $sql .= ', '; } $sql .= "`{$key}` = '{$val}'"; } // add conditions to SQL if ($cond->hasConditions()) { $sql .= ' WHERE'; $count = 0; foreach ($cond->getAllIs() as $field => $val) { $field = mysql_real_escape_string($field); $val = mysql_real_escape_string($val); if ($count > 0) { $sql .= ' ' . $cond->getOperator(); } $sql .= " `{$field}` = '{$val}'"; $count++; } foreach ($cond->getAllLike() as $field => $val) { $field = mysql_real_escape_string($field); $val = mysql_real_escape_string($val); if ($count > 0) { $sql .= ' ' . $cond->getOperator(); } $sql .= " `{$field}` LIKE '%{$val}%'"; $count++; } foreach ($cond->getAllLesser() as $field => $val) { $field = mysql_real_escape_string($field); $val = mysql_real_escape_string($val); if ($count > 0) { $sql .= ' ' . $cond->getOperator(); } $sql .= " `{$field}` < '{$val}'"; $count++; } foreach ($cond->getAllGreater() as $field => $val) { $field = mysql_real_escape_string($field); $val = mysql_real_escape_string($val); if ($count > 0) { $sql .= ' ' . $cond->getOperator(); } $sql .= " `{$field}` > '{$val}'"; $count++; } } else { // FIXME add an override for that, perhabs that could be useful? // uha, updating all? !! WTF? throw new Moonlake_Exception_ModelBackend("Your using an empty condition together with the request to update entries. Which does not seem to be a good idea."); } $this->con->free_query($this->con->query($sql)); }
public function deleteRole(Moonlake_Auth_Role $role) { $mb = $this->model->getBackend(); $model = new Moonlake_Auth_UsersRolesModel($mb); $cond = new Moonlake_Model_Condition(); $cond->is('user', $this->userid); $cond->is('role', $role->getId()); $model->deleteEntriesByCondition($cond); }