/**
  * Create new category
  */
 public function createNewAction()
 {
     $new_category_name = 'My Saved Databases';
     $match = true;
     $categories = $this->knowledgebase->getCategories()->toArray(false);
     while ($match == true) {
         $loop_match = false;
         foreach ($categories as $category) {
             // already have a default name
             if ($new_category_name == $category['name']) {
                 $last_char = substr($category['name'], -1, 1);
                 // it also already has a number on the end
                 if (is_numeric($last_char)) {
                     $last_char += 1;
                     // so increment it
                     $new_category_name = substr($category['name'], 0, -1) . $last_char;
                     $loop_match = true;
                     // need to keep checking
                 } else {
                     $new_category_name .= '1';
                     $loop_match = true;
                     // need to keep checking
                 }
             }
         }
         // not matches on any of the existing categories
         if ($loop_match == false) {
             $match = false;
             // stop the while loop
         }
     }
     // create new one
     $category = $this->knowledgebase->createCategory();
     $category->setName($new_category_name);
     $subcategory = new Subcategory();
     $subcategory->setName('Databases');
     $category->addSubcategory($subcategory);
     $this->knowledgebase->updateCategory($category);
     // redirect to subject
     return $this->returnToCategory($category->getId());
 }
예제 #2
0
 /**
  * Add a Subcategory
  * 
  * @param int $category_id          internal category id
  * @param string $subcategory_name  subcategory name
  */
 public function addSubcategory($category_id, $subcategory_name)
 {
     // get category
     $category = $this->getCategoryById($category_id);
     // create subcategory
     $subcategory = new Subcategory();
     $subcategory->setName($subcategory_name);
     $subcategory->setOwner($this->owner);
     // assign subcategory to category
     $subcategory->setCategory($category);
     // update
     $this->update($subcategory);
 }
예제 #3
0
 /**
  * @param Subcategory $subcategory
  */
 public function addSubcategory(Subcategory $subcategory)
 {
     $subcategory->setCategory($this);
     $subcategory->setOwner($this->owner);
     $this->subcategories->add($subcategory);
 }