function admin_category_addchange($request, $taxonomy = 'Post', $id = false) { $templateArr = array('current_admin_menu' => $taxonomy, 'current_admin_submenu' => $taxonomy, 'current_admin_submenu2' => 'PostCategory', 'title' => __('Post Category Add/Change')); if (!$request->user->has_perm($taxonomy . '.can_change_PostCategory')) { Messages::Error(__('Do not have permission to do this.')); HttpResponseRedirect($_SERVER['HTTP_REFERER']); } $modelClass = 'PostCategory'; if ($taxonomy == 'Post') { $formClass = 'Pjango\\Contrib\\Post\\Forms\\PostCategoryForm'; } else { $formClass = $taxonomy . '\\Forms\\PostCategoryForm'; } $formData = array(); $lng = pjango_ini_get('LANGUAGE_CODE'); //eğer kategori yoksa ekle $catTest = Doctrine_Query::create()->from('PostCategory o')->where('o.site_id = ? AND o.taxonomy = ?', array(SITE_ID, $taxonomy))->count(); if ($catTest <= 0) { $category = new PostCategory(); $category->Translation[$lng]->name = __($taxonomy . ' Main Category'); $category->Translation[$lng]->slug = __(ucfirst($taxonomy) . '-main-category'); $category->site_id = SITE_ID; $category->taxonomy = $taxonomy; $category->save(); $treeObject = Doctrine_Core::getTable('PostCategory')->getTree(); $treeObject->createRoot($category); } if ($id) { $addchangeObj = Doctrine_Query::create()->from('PostCategory o')->leftJoin('o.Translation t')->addWhere('o.site_id = ? AND o.id = ?', array(SITE_ID, $id))->fetchOne(); if ($addchangeObj) { $parent = $addchangeObj->getNode()->getParent(); $formData = $addchangeObj->toArray(); $templateArr['addchange_obj'] = $addchangeObj; $formData['parent_id'] = $parent->id; $formData['name'] = $addchangeObj->Translation[$lng]->name; $formData['slug'] = $addchangeObj->Translation[$lng]->slug; } } if ($request->POST) { $form = new $formClass($taxonomy, $request->POST); if ($form->is_valid()) { $formData = $form->cleaned_data(); if (!$addchangeObj) { $addchangeObj = new $modelClass(); } try { $parent = Doctrine::getTable($modelClass)->find($formData['parent_id']); $addchangeObj->taxonomy = $taxonomy; $addchangeObj->site_id = SITE_ID; $addchangeObj->Translation[$lng]->name = $formData['name']; $addchangeObj->Translation[$lng]->slug = $formData['slug']; if ($addchangeObj->state() == Doctrine_Record::STATE_TDIRTY || $addchangeObj->state() == Doctrine_Record::STATE_TCLEAN) { $addchangeObj->getNode()->insertAsLastChildOf($parent); } else { $addchangeObj->save(); $curParent = $addchangeObj->getNode()->getParent(); if ($curParent->id != $parent->id) { $addchangeObj->getNode()->moveAsLastChildOf($parent); } } Messages::Info(pjango_gettext('The operation completed successfully')); HttpResponseRedirect('/admin/' . $taxonomy . '/' . $modelClass . '/'); } catch (Exception $e) { Messages::Error($e->getMessage()); } } } if (!$form) { $form = new $formClass($taxonomy, $formData); } $templateArr['addchange_form'] = $form; $templateArr['taxonomy'] = $taxonomy; render_to_response('admin/addchange.html', $templateArr); }
function admin_group_addchange($request, $id = false) { $templateArr = array('current_admin_menu' => 'Auth', 'current_admin_submenu' => 'Auth', 'current_admin_submenu2' => 'Group', 'title' => 'Auth Group Add/Change'); $modelClass = 'Group'; $formClass = 'Pjango\\Contrib\\Auth\\Forms\\GroupForm'; $formData = array(); if (!$request->user->has_perm('Auth.can_change_Group')) { Messages::Error(__('Do not have permission to do this.')); HttpResponseRedirect($_SERVER['HTTP_REFERER']); } if ($id) { $modelObj = Doctrine::getTable($modelClass)->find($id); if ($modelObj) { $formData = $modelObj->toArray(); $templateArr['group_permissions'] = $modelObj->GroupPermissions; } } if ($request->POST) { $form = new $formClass($request->POST); try { if (!$form->is_valid()) { throw new Exception('There are incomplete required fields. Please complete them.'); } $formData = $form->cleaned_data(); if (!$modelObj) { $modelObj = new $modelClass(); } $modelObj->fromArray($formData); $modelObj->save(); $modelObj->unlink('Permissions'); $modelObj->link('Permissions', $request->POST['permissions']); $modelObj->site_id = SITE_ID; $modelObj->save(); Messages::Info(pjango_gettext('The operation completed successfully')); HttpResponseRedirect('/admin/Auth/Group/'); } catch (Exception $e) { Messages::Error($e->getMessage()); } } $templateArr['permissions'] = Doctrine_Query::create()->from('Permission')->execute(); if (!$form) { $form = new $formClass($formData); } $templateArr['addchange_form'] = $form; render_to_response('admin/addchange.html', $templateArr); }
function app_model_settings($request, $app_label = false, $model = false) { $templateArr = array('current_admin_menu' => $app_label, 'current_admin_submenu' => $model, 'current_admin_submenu2' => 'Settings', 'title' => __(sprintf('%s %s Settings', $app_label, $model))); $coreApps = array('Post'); $app_label0 = $app_label; if (in_array($app_label, $coreApps)) { $app_label = sprintf('Pjango\\Contrib\\%s', $app_label); } $contentType = ContentType::get_for_model($model, $app_label); $formClass = sprintf('%s\\Forms\\%sSettingsForm', $app_label, $model); $formData = array(); $ignoredSettings = array('is_active', 'title', 'show_title', 'category_id', 'content'); $settings = Doctrine_Query::create()->from('Settings o')->where('o.category = ? AND o.site_id = ? ', array($app_label, SITE_ID))->fetchArray(); foreach ($settings as $settingsValue) { $formData[$settingsValue['name']] = $settingsValue['value']; } if (class_exists('PageLayout')) { $pageLayout = Doctrine_Query::create()->from('PageLayout o')->where('o.site_id = ? AND o.content_type_id = ?', array(SITE_ID, $contentType->id))->fetchOne(); if ($pageLayout) { $formData = array_merge($formData, $pageLayout->toArray()); } } if ($request->POST) { $form = new $formClass($request->POST); try { if (!$form->is_valid()) { throw new Exception(pjango_gettext('There are some errors, please correct them below.')); } $formData = $form->cleaned_data(); if (class_exists('PageLayout')) { if (!$pageLayout) { $pageLayout = new PageLayout(); } $pageLayout->fromArray($formData); $pageLayout->content_type_id = $contentType->id; $pageLayout->site_id = SITE_ID; $pageLayout->save(); } foreach ($formData as $key => $value) { if (in_array($key, $ignoredSettings)) { unset($formData[$key]); } } Settings::saveFromArray($app_label, $formData); Messages::Info('The operation completed successfully'); HttpResponseRedirect(sprintf('/admin/%s/%s/settings/', $app_label0, $model)); } catch (Exception $e) { Messages::Error($e->getMessage()); } } if (!$form) { $form = new $formClass($formData); } $templateArr['addchange_form'] = $form; render_to_response('admin/addchange.html', $templateArr); }