<?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $sortnum = array(); for ($i = 0; $i < count($_POST['categoryid']); $i++) { if (!isset($sortnum[$_POST['parentid'][$i]])) { $sortnum[$_POST['parentid'][$i]] = 0; } $category = Model_News_Category::Get($_POST['categoryid'][$i]); $category['parentid'] = $_POST['parentid'][$i]; $category['sortnum'] = $sortnum[$_POST['parentid'][$i]]; $category->save(); $sortnum[$_POST['parentid'][$i]]++; } Typeframe::Redirect('Sorted.', Typeframe::CurrentPage()->applicationUri()); }
} $settings = Typeframe::CurrentPage()->settings(); $typef_app_dir = Typeframe::CurrentPage()->applicationUri(); //var_dump($_SERVER);die; // get category id from request if not in path info if (!$categoryid) { $categoryid = @$_REQUEST['categoryid']; } // validate category id in settings $setcat = @$settings['categoryid']; if ($setcat && !in_array(0, $setcat) && !in_array($categoryid, $setcat)) { Typeframe::Redirect('Invalid category specified.', $typef_app_dir, 1); return; } // create news category object $category = Model_News_Category::Get($categoryid); // redirect if category id is invalid if (!$category->exists()) { Typeframe::Redirect('Invalid category specified.', $typef_app_dir, 1); return; } // determine if there are 0 or more than 1 categories; add flag to template if ($setcat && (in_array(0, $setcat) || count($setcat) > 1)) { $pm->setVariable('multicats', true); } // add category name, id, and object to template $pm->setVariable('categoryname', $category->get('categoryname')); $pm->setVariable('categoryid', $category->get('categoryid')); $pm->setVariable('category', $category); // create news article factory; filter by category id $articles = new Model_News_Article();
public function testNewsAdminCreateEditAndDeleteCategory() { /* Assertions: * Create category * Edit category * Delete category */ $this->get(TYPEF_WEB_DIR . '/admin/news/categories'); $this->get(TYPEF_WEB_DIR . '/admin/news/categories/add'); $form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/categories/add"]'); $categoryname = 'Integration Test ' . time(); $categorydescr = "{$categoryname} description"; $form->first('input[name="categoryname"]')->setValue($categoryname); $form->first('input[name="categorydescr"]')->setValue($categorydescr); $form->first('input[name="categorydescr"]')->setValue(TYPEF_DIR . '/tests/images/placeholders/generic/1024x768.jpg'); $form->submit(); $catmod = new Model_News_Category(); $catmod->where('categoryname = ?', $categoryname); $category = $catmod->getFirst(); $this->assertTrue($category->exists(), 'Failed to create news category'); if ($category->exists()) { $id = $category['id']; $categoryname .= ' updated'; $this->get(TYPEF_WEB_DIR . '/admin/news/categories/edit?categoryid=' . $id); $form = $this->first('form[action="' . TYPEF_WEB_DIR . '/admin/news/categories/edit"]'); $form->first('input[name="categoryname"]')->setValue($categoryname); $form->submit(); $catmod = new Model_News_Category(); $catmod->where('categoryname = ?', $categoryname); $category = $catmod->getFirst(); $this->assertTrue($category->exists(), 'Failed to edit news category'); $this->post(TYPEF_WEB_DIR . '/admin/news/categories/delete', array('categoryid' => $id)); $category = Model_News_Category::Get($id); $this->assertFalse($category->exists(), 'Failed to delete news category'); } }
<?php $category = Model_News_Category::Get($_REQUEST['categoryid']); if (!$category->exists()) { Typeframe::Redirect('Invalid category specified.', Typeframe::CurrentPage()->applicationUri() . '/categories', -1); return; } $parentid = $category['parentid']; if ($category['articles']->getTotal() && $parentid == 0) { Typeframe::Redirect('Category has articles that cannot be recategorized.', Typeframe::CurrentPage()->applicationUri() . '/categories', -1); return; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { if ($category['articles']->getTotal()) { foreach ($category['articles']->getAll() as $article) { $article['categoryid'] = $parentid; $article->save(); } } if ($category['children']->getTotal()) { foreach ($category['children']->getAll() as $child) { $child['parentid'] = $parentid; $child->save(); } } $category->delete(); Typeframe::Redirect('Category deleted.', Typeframe::CurrentPage()->applicationUri() . '/categories'); }