public function testAddCategory() { $p = new ae_PostModel(); $c1 = new ae_CategoryModel(); $c1->setId(1); $c2 = new ae_CategoryModel(); $c2->setId(2); $p->addCategory($c1); $p->addCategory($c2); $this->assertEquals($p->getCategories(), array($c1, $c2)); }
/** * Load the category model to the permalink. * @return {ae_CategoryModel} The loaded category model. */ public static function getCategoryModel() { if (!self::isCategory()) { $msg = sprintf('[%s] Permalink does not represent a category.', get_class()); throw new Exception($msg); } $model = new ae_CategoryModel(); if (isset($_GET[PERMALINK_GET_CATEGORY]) && ae_Validate::id($_GET[PERMALINK_GET_CATEGORY])) { if (!$model->load($_GET[PERMALINK_GET_CATEGORY])) { return FALSE; } } else { $permalink = mb_substr(self::$urlNoOffset, 1); $permalink = preg_replace(';^' . PERMALINK_BASE_CATEGORY . ';i', '', $permalink); if (!$model->loadFromPermalink($permalink, TRUE)) { return FALSE; } } return $model; }
/** * Assign the loaded category models to their post models. * @param {array} $categories Category models. */ protected function assignCategoriesToPosts($categories) { $id2Post = array(); foreach ($this->items as $item) { $id2Post[$item->getId()] = $item; } foreach ($categories as $row) { $ca = new ae_CategoryModel(); $ca->setId($row['ca_id']); $ca->setTitle($row['ca_title']); $ca->setPermalink($row['ca_permalink']); $ca->setParent($row['ca_parent']); $ca->setStatus(ae_CategoryModel::STATUS_AVAILABLE); $id2Post[$row['pc_post']]->addCategory($ca); } }
/** * Create the category. * @return {int} ID of the new category. */ function createCategory() { if (!isset($_POST['category-title'], $_POST['category-parent'], $_POST['category-permalink'])) { header('Location: ../admin.php?error=missing_data_for_category'); exit; } $permalink = trim($_POST['category-permalink']); $category = new ae_CategoryModel(); if (isset($_POST['edit-id'])) { $category->setId($_POST['edit-id']); } $category->setTitle($_POST['category-title']); $category->setParent($_POST['category-parent']); if ($permalink != '') { $category->setPermalink($permalink); } $category->save(); return $category->getId(); }
<?php $pageOffset = isset($_GET['offset']) && is_numeric($_GET['offset']) ? $_GET['offset'] : 0; $itemsPerPage = 20; $status = isset($_GET['status']) ? $_GET['status'] : FALSE; $filter = array(); $filter['LIMIT'] = sprintf('%d, %d', $pageOffset * $itemsPerPage, $itemsPerPage); // categories if (isset($_GET['category'])) { $area = 'category'; $areaName = 'Categories'; if (ae_CategoryModel::isValidStatus($status)) { $filter['WHERE'] = 'ca_status = "' . $status . '"'; } $list = new ae_CategoryList($filter); } else { if (isset($_GET['page'])) { $area = 'page'; $areaName = 'Pages'; if (ae_PageModel::isValidStatus($status)) { $filter['WHERE'] = 'pa_status = "' . $status . '"'; } else { $filter['WHERE'] = 'pa_status != "trash"'; } $list = new ae_PageList($filter); } else { if (isset($_GET['post'])) { $area = 'post'; $areaName = 'Posts'; if (ae_PostModel::isValidStatus($status)) { $filter['WHERE'] = 'po_status = "' . $status . '"';
header('Location: ../index.php?error=not_logged_in'); exit; } if (!isset($_POST['area'], $_POST['bulk-status-change'])) { header('Location: ../admin.php?error=no_area_or_status_given'); exit; } if (!isset($_POST['entry']) || count($_POST['entry']) == 0) { header('Location: ../admin.php?error=no_entries_given'); exit; } $status = $_POST['bulk-status-change']; $mainArea = 'manage'; switch ($_POST['area']) { case 'category': $isValidStatus = $status == 'delete' ? TRUE : ae_CategoryModel::isValidStatus($status); $modelName = 'ae_CategoryModel'; $preDelete = ae_CategoryModel::STATUS_TRASH; break; case 'cofilter': $isValidStatus = $status == 'delete' ? TRUE : ae_CommentfilterModel::isValidStatus($status); $mainArea = 'settings'; $modelName = 'ae_CommentfilterModel'; $preDelete = ae_CommentfilterModel::STATUS_INACTIVE; break; case 'comment': $isValidStatus = $status == 'delete' ? TRUE : ae_CommentModel::isValidStatus($status); $modelName = 'ae_CommentModel'; $preDelete = ae_CommentModel::STATUS_TRASH; break; case 'media':
/** * Load post category models. * @return {boolean} TRUE, if loading succeeded, FALSE otherwise. */ public function loadCategories() { if (!ae_Validate::id($this->id)) { throw new Exception('[' . get_class() . '] Cannot load post categories. No valid post ID.'); } $stmt = ' SELECT ca_id, ca_title, ca_parent, ca_permalink FROM ( SELECT * FROM `' . AE_TABLE_POSTS2CATEGORIES . '` WHERE pc_post = :id ) AS `' . AE_TABLE_POSTS2CATEGORIES . '` LEFT JOIN `' . AE_TABLE_CATEGORIES . '` ON pc_category = ca_id WHERE ca_status = :caStatus '; $params = array(':id' => $this->id, ':caStatus' => ae_CategoryModel::STATUS_AVAILABLE); $result = ae_Database::query($stmt, $params); if ($result === FALSE) { return FALSE; } foreach ($result as $row) { $ca = new ae_CategoryModel($row); $ca->setStatus(ae_CategoryModel::STATUS_AVAILABLE); $this->addCategory($ca); } return TRUE; }
<?php if ($area == 'category') { $statuses = ae_CategoryModel::listStatuses(); } else { if ($area == 'cofilter') { $statuses = ae_CommentfilterModel::listStatuses(); } else { if ($area == 'comment') { $statuses = ae_CommentModel::listStatuses(); } else { if ($area == 'media') { $statuses = ae_MediaModel::listStatuses(); } else { if ($area == 'page') { $statuses = ae_PageModel::listStatuses(); } else { if ($area == 'post') { $statuses = ae_PostModel::listStatuses(); } else { if ($area == 'user') { $statuses = ae_UserModel::listStatuses(); } } } } } } } $select = ae_Forms::selectStatus('bulk-status-change', $statuses); if (isset($_GET['status']) && $_GET['status'] == 'trash') {
public function testSetTitle() { $c = new ae_CategoryModel(); $c->setTitle('my-category'); $this->assertEquals($c->getTitle(), 'my-category'); $c->setTitle(4); $this->assertTrue($c->getTitle() === '4'); $this->setExpectedException('Exception'); $c->setTitle(''); }
<?php if (isset($_GET['category']) && ae_Validate::id($_GET['category'])) { $editArea = 'Category'; $areaId = 'category'; $model = new ae_CategoryModel(); $model->load($_GET['category']); } else { if (isset($_GET['cofilter']) && ae_Validate::id($_GET['cofilter'])) { $editArea = 'Comment filter'; $areaId = 'cofilter'; $model = new ae_CommentfilterModel(); $model->load($_GET['cofilter']); } else { if (isset($_GET['comment']) && ae_Validate::id($_GET['comment'])) { $editArea = 'Comment'; $areaId = 'comment'; $model = new ae_CommentModel(); $model->load($_GET['comment']); } else { if (isset($_GET['media']) && ae_Validate::id($_GET['media'])) { $editArea = 'Media'; $areaId = 'media'; $model = new ae_MediaModel(); $model->load($_GET['media']); } else { if (isset($_GET['page']) && ae_Validate::id($_GET['page'])) { $editArea = 'Page'; $areaId = 'page'; $model = new ae_PageModel(); $model->load($_GET['page']);