public function postSearch($options) { $result = null; if (!empty($options['plugin'])) { if (!empty($options['plugin'][$this->id])) { $result = array(); $result['join'] = array(); $category_model = new blogCategoryModel(); if ($category = $category_model->getByField('url', $options['plugin'][$this->id], 'id')) { $result['join'] = array(); $result['join']['blog_post_category'] = array('condition' => 'blog_post_category.post_id = blog_post.id'); $result['where'] = array('blog_post_category.category_id IN (' . implode(', ', array_keys($category)) . ')'); } else { $category = array(); $result['where'] = 'FALSE'; } $title = array(); if ($category) { foreach ($category as $item) { $title[] = $item['name']; } } else { $title[] = _wp('not found'); } wa()->getResponse()->setTitle(implode(', ', $title)); } } return $result; }
public function execute() { $this->plugin_id = 'category'; parent::execute(); if ($data = waRequest::post($this->plugin_id)) { $order = 0; $model = new blogCategoryModel(); foreach ($data as $id => &$row) { $id = intval($id); if (!empty($row['name'])) { $row['sort'] = $order++; if ($id > 0) { if (!empty($row['delete'])) { $model->deleteById($id); } else { $model->updateById($id, $row); $row['id'] = $id; } } elseif ($id < 0) { $row['id'] = $model->insert($row); } } } unset($row); } $categories = blogCategory::getAll(); $icons = $this->getConfig()->getIcons(); if (!$categories) { $categories[0] = array('url' => '', 'name' => '', 'icon' => current($icons), 'id' => 0, 'qty' => 0, 'sort' => 0); } $this->view->assign('categories', $categories); $this->view->assign('icons', $icons); }
public function changePost($post_id, $categories, $is_add = false) { $categories = array_map('intval', $categories); $current_categories = array_keys($this->getByField('post_id', $post_id, 'category_id')); if ($new_categories = array_diff($categories, $current_categories)) { foreach ($new_categories as $key => $id) { $this->insert(array('post_id' => $post_id, 'category_id' => $id), 2); } } if ($excluded_categories = array_diff($current_categories, $categories)) { $this->deleteByField(array('post_id' => $post_id, 'category_id' => $excluded_categories)); } if ($updated = array_merge($excluded_categories, $new_categories, $current_categories)) { $category_model = new blogCategoryModel(); $category_model->recalculate($updated); } }
public function execute() { $category_model = new blogCategoryModel(); $this->view->assign('categories', $category_model->getByPost($this->params['post_id'])); $this->view->assign('categories_all', blogCategory::getAll()); }