POST /admin/categories
764595
def admin_add
      return unless user_is_allowed('categories', 'add')
      
      if params[:parent_id].nil? or params[:parent_id].empty?
        render :json => { :error => 'Please select a parent category.' }
      elsif params[:name].nil? or params[:name].empty?
        render :json => { :error => 'This title cannot be empty' }
      else
        category           = Category.new
        category.parent_id = params[:parent_id]
        category.name      = params[:name]
        category.slug      = category.generate_slug
        category.url       = "#{Category.find(params[:parent_id]).url}/#{category.slug}"
        
        if category.save
          render :json => { :success => true, :redirect => "/admin/categories/#{category.id}/edit" }
        else
          render :json => { :error => 'There was an error saving the category.' }
        end
      end
    end
990983
public function category(Category $category)
    {
        $this->category = $category;

        $this->category->categorise($this);
    }
1347917
public function setCategories($post)
	{
		foreach ($post->getCategories() as $category) 
		{
			$categoryName = strtolower($category->getName());
			if(in_array($categoryName, array_map('strtolower', $this->categoriesName)))
			{
				$this->categories[$categoryName]->setPost($post);
				continue;
			}

			$this->categories[$categoryName] = new Category($categoryName);
			$this->categories[$categoryName]->setPost($post);
			$this->categoriesName[] = $categoryName;			
		}
	}
235528
def set_categories(self):
        """"""
        self.categories = []
        temp_categories = self.soup.findAll('category')
        for category in temp_categories:
            category_text = category.string
            self.categories.append(category_text)
1372012
def admin_delete
      return unless user_is_allowed('categories', 'delete')
      
      category = Category.find(params[:id])
      
      if category.products.any?
        render :json => { :error => "Can't delete a category that has products in it." }
      elsif category.children.any?
        render :json => { :error => "You can't delete a category that has child categories." }
      else
        render :json => { :success => category.destroy, :redirect => '/admin/categories' }
      end
    end
804957
public static function insertCategories($selectedCategories, $postID, $postTypeSlug)
    {
        if (count($selectedCategories)) {
            $categoriesIDs = [];
            $newCategoryRelation = [];
            foreach ($selectedCategories as $selectedCategory){
                $newCategoryRelation[] = [
                  'categoryID' => $selectedCategory['categoryID'],
                  'postID' => $postID,
                ];
                $categoriesIDs[] = $selectedCategory['categoryID'];
            }

            // if post is only in the archive
            // if post is in the main database
            $insertedCategories = (new CategoryRelation())->setTable($postTypeSlug.'_categories')->insert($newCategoryRelation);
            if ($insertedCategories) {
                return $categoriesIDs;
            }
        }
        return [];
    }
1074536
public function actionJsoncategories()
    {
        header('Content-type: application/json');
        $out = [];
        if(isset($_POST['depdrop_parents']))
        {
            $parents = $_POST['depdrop_parents'];
            if($parents != null)
            {
                $mod_table = $parents[0];
                $out = Categories::jsCategories($mod_table);
                echo Json::encode(['output'=>$out,'selected'=>'']);
                return;
            }
        }
        echo Json::encode(['output'=>'','selected'=>'']);
        exit;
    }
1105489
protected function submitEditCategoryGroup()
    {
        if ($this->isPosted('delete')) {
            $this->deleteCategoryGroup();
        } else if ($this->isPosted('save') && $this->validateEditCategoryGroup()) {
            if (isset($this->data_category_group['category_group_id'])) {
                $this->updateCategoryGroup();
            } else {
                $this->addCategoryGroup();
            }
        }
    }
1004442
protected function addCategoryGroup()
    {
        if (!$this->isError()) {
            $id = $this->category_group->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
229491
protected function _addMenuItems()
    {
        $postTypes = Configure::read('CA.PostTypes');

        $this->Controller->Menu->area('main');

        foreach ($postTypes as $name => $options) {
            if ($options['menu']) {
                $this->Controller->Menu->add($options['alias'], [
                    'url' => [
                        'prefix' => 'admin',
                        'plugin' => 'CakeAdmin',
                        'controller' => 'PostTypes',
                        'action' => 'index',
                        'type' => $options['slug']
                    ],
                    'weight' => $options['menuWeight']
                ]);
            }
        }
    }
121586
def update_categories
      @post = LatoBlog::Post.find_by(id: params[:id])
      return unless check_post_presence

      params[:categories].each do |category_id, value|
        category = LatoBlog::Category.find_by(id: category_id)
        next if !category || category.meta_language != @post.meta_language

        category_post = LatoBlog::CategoryPost.find_by(lato_blog_post_id: @post.id, lato_blog_category_id: category.id)
        if value == 'true'
          LatoBlog::CategoryPost.create(lato_blog_post_id: @post.id, lato_blog_category_id: category.id) unless category_post
        else
          category_post.destroy if category_post
        end
      end
    end
1294722
public function DisplayPostsByCategory($title)
    {
        // Get the category
        // Please note that the categories table does *NOT* have a "slug" field!
        $category = $this->repository->findCategoryIdByTitle($title);

        // if category does not exist
        if (count($category) < 1 ) {
            return redirect('home');
        }


        // Process the category's image

        // (i) resize the category image
        $this->imagesHelper->createCategoryResizedImageFiles($category->featured_image);

        // (ii) what is the name of the resized category image that the view will use?
        //      yeah, do this second as about to change $category->featured_image
        $category->featured_image = $this->imagesHelper->getCategoryFeaturedImage($category->featured_image);

        // Get the posts associated with this category
        $posts = $this->repository->findEnabledAllPostsThatHaveCategoryId($category->id);

        if (count($posts) == 0)
        {
            // There are no enabled posts publish_on =< today
            //return view('errors/404');
            return redirect('home');
        }

        // Is the featured image in each post resized?
        $this->checkPostsImagesResized($posts);

        return view('categories/list_posts_associated_with_category', [
            'category'          => $category,
            'posts'             => $posts,
            'pagetitle'         => $category->title,
            'DatesHelper'       => DatesHelper::class,
            'HTMLHelper'        => HTMLHelper::class,
            'ImagesHelper'      => $this->imagesHelper,
        ]);
    }
452010
def create
      @record = Post.new(post_params)
      @record.additional_data(params[:additional_data]) if defined?(params[:additional_data]) && !params[:additional_data].blank?

      respond_to do |format|

        if @record.save

          # assigns and unassigns categories and tags to an individual posts
          Post.deal_with_categories @record, params[:category_ids], params[:tag_ids]

          format.html { redirect_to admin_articles_path, notice: I18n.t("controllers.admin.articles.create.flash.success") }

        else
          format.html {
            # add breadcrumb and set title
            add_breadcrumb I18n.t("controllers.admin.articles.new.breadcrumb")
            @action = 'create'
            flash[:error] = I18n.t('generic.validation.no_passed')
            render action: "new"
          }
        end

      end
    end
883143
public function addCategory($category)
    {
        if (!($category instanceof Category)) {
            $category = new Category($category);
        }
        $this->categories[] = $category;
    }
905747
function(category, name, desc) {

            if(used[name]) return;
            used[name]= 1;

            if(!items[category]) items[category] = [];
            
           items[category].push({
               name: name,
               desc: desc
           });
        }
388555
def _change_kind(self, post_uid):
        '''
        
        '''

        post_data = self.get_post_data()

        logger.info('admin post update: {0}'.format(post_data))

        MPost.update_misc(post_uid, kind=post_data['kcat'])
        # self.update_category(post_uid)

        update_category(post_uid, post_data)
        self.redirect('/{0}/{1}'.format(router_post[post_data['kcat']], post_uid))
204681
public function adminMetaBoxes($post_type, $post){
		if( false !== array_search($post_type, $this->post_types) ){
			switch($this->hook){
				case 'post_submitbox_misc_actions':
				case 'post_submitbox_start':
					add_action($this->hook, function() use ($post){
						if( $this->nonce_key ){
							wp_nonce_field($this->nonce_action, $this->nonce_key);
						}
						$this->editFormX($post);
					}, $this->hook_priority);
					break;
				case 'post_edit_form_tag':
				case 'edit_form_top':
				case 'edit_form_before_permalink':
				case 'edit_form_after_title':
				case 'edit_form_after_editor':
				case 'dbx_post_sidebar':
					add_action($this->hook, function(\WP_Post $post){
						if( $this->nonce_key ){
							wp_nonce_field($this->nonce_action, $this->nonce_key);
						}
						$this->editFormX($post);
					});
					break;
				default:
					$s = explode('\\', get_called_class());
					$name = $this->string->camel_to_hyphen($s[count($s) - 1]);
					add_meta_box("metabox-$name", $this->title, function( \WP_Post $post, array $screen ){
						if( $this->nonce_key ){
							wp_nonce_field($this->nonce_action, $this->nonce_key);
						}
						$this->doMetaBox($post, $screen);
					}, $post_type, $this->context, $this->priority);
					break;
			}
		}

	}