function edit($id, Request $request, Application $app) { if (!$this->build($id, $request, $app)) { $app->abort(404, "User Group does not exist."); } $form = $app['form.factory']->create(new UserGroupEditForm($app), $this->parameters['usergroup']); if ('POST' == $request->getMethod()) { $form->bind($request); if ($form->isValid()) { $ugr = new UserGroupRepository(); $meta = new UserGroupEditMetaDataModel(); $meta->setUserAccount($app['currentUser']); $meta->setFromRequest($request); $ugr->editTitleWithMetaData($this->parameters['usergroup'], $meta); return $app->redirect("/admin/usergroup/" . $this->parameters['usergroup']->getId()); } } $this->parameters['form'] = $form->createView(); return $app['twig']->render('site/adminusergroup/edit.html.twig', $this->parameters); }
public function update(UserGroupModel $userGroup, $fields, UserGroupEditMetaDataModel $userGroupEditMetaDataModel) { $alreadyInTransaction = $this->db->inTransaction(); // Make Information Data $fieldsSQL1 = array(); $fieldsParams1 = array('id' => $userGroup->getId()); foreach ($fields as $field) { $fieldsSQL1[] = " " . $field . "=:" . $field . " "; if ($field == 'title') { $fieldsParams1['title'] = substr($userGroup->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'description') { $fieldsParams1['description'] = $userGroup->getDescription(); } else { if ($field == 'is_deleted') { $fieldsParams1['is_deleted'] = $userGroup->getIsDeleted() ? 1 : 0; } else { if ($field == 'is_in_index') { $fieldsParams1['is_in_index'] = $userGroup->getIsDeleted() ? 1 : 0; } else { if ($field == 'is_includes_anonymous') { $fieldsParams1['is_includes_anonymous'] = $userGroup->getIsIncludesAnonymous() ? 1 : 0; } else { if ($field == 'is_includes_users') { $fieldsParams1['is_includes_users'] = $userGroup->getIsIncludesUsers() ? 1 : 0; } else { if ($field == 'is_includes_verified_users') { $fieldsParams1['is_includes_verified_users'] = $userGroup->getIsIncludesVerifiedUsers() ? 1 : 0; } } } } } } } } // Make History Data $fieldsSQL2 = array('user_group_id', 'user_account_id', 'created_at', 'from_ip'); $fieldsSQLParams2 = array(':user_group_id', ':user_account_id', ':created_at', ':from_ip'); $fieldsParams2 = array('user_group_id' => $userGroup->getId(), 'user_account_id' => $userGroupEditMetaDataModel->getUserAccount() ? $userGroupEditMetaDataModel->getUserAccount()->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase(), 'from_ip' => $userGroupEditMetaDataModel->getIp()); foreach ($this->possibleFields as $field) { if (in_array($field, $fields) || $field == 'title') { $fieldsSQL2[] = " " . $field . " "; $fieldsSQLParams2[] = " :" . $field . " "; if ($field == 'title') { $fieldsParams2['title'] = substr($userGroup->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'description') { $fieldsParams2['description'] = $userGroup->getDescription(); } else { if ($field == 'is_deleted') { $fieldsParams2['is_deleted'] = $userGroup->getIsDeleted() ? 1 : 0; } else { if ($field == 'is_in_index') { $fieldsParams2['is_in_index'] = $userGroup->getIsDeleted() ? 1 : 0; } else { if ($field == 'is_includes_anonymous') { $fieldsParams2['is_includes_anonymous'] = $userGroup->getIsIncludesAnonymous() ? 1 : 0; } else { if ($field == 'is_includes_users') { $fieldsParams2['is_includes_users'] = $userGroup->getIsIncludesUsers() ? 1 : 0; } else { if ($field == 'is_includes_verified_users') { $fieldsParams2['is_includes_verified_users'] = $userGroup->getIsIncludesVerifiedUsers() ? 1 : 0; } } } } } } } $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " 0 "; } else { $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " -2 "; } } try { if (!$alreadyInTransaction) { $this->db->beginTransaction(); } // Information SQL $stat = $this->db->prepare("UPDATE user_group_information SET " . implode(",", $fieldsSQL1) . " WHERE id=:id"); $stat->execute($fieldsParams1); // History SQL $stat = $this->db->prepare("INSERT INTO user_group_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")"); $stat->execute($fieldsParams2); if (!$alreadyInTransaction) { $this->db->commit(); } } catch (Exception $e) { if (!$alreadyInTransaction) { $this->db->rollBack(); } throw $e; } }
public function editIsIncludesVerifiedUser(UserGroupModel $userGroupModel, UserAccountModel $userAccountModel = null) { $meta = new UserGroupEditMetaDataModel(); $meta->setUserAccount($userAccountModel); $this->userGroupDBAccess->update($userGroupModel, array('is_includes_verified_users'), $meta); }