Overview

Namespaces

  • Charcoal
    • Object
    • User
      • Acl

Classes

  • Charcoal\Object\Content
  • Charcoal\Object\ObjectRevision
  • Charcoal\Object\ObjectRoute
  • Charcoal\Object\ObjectSchedule
  • Charcoal\Object\UserData
  • Charcoal\User\AbstractUser
  • Charcoal\User\Acl\Manager
  • Charcoal\User\Acl\Permission
  • Charcoal\User\Acl\PermissionCategory
  • Charcoal\User\Acl\Role
  • Charcoal\User\Authenticator
  • Charcoal\User\Authorizer
  • Charcoal\User\AuthToken
  • Charcoal\User\AuthTokenMetadata
  • Charcoal\User\GenericUser

Interfaces

  • Charcoal\Object\ArchivableInterface
  • Charcoal\Object\CategorizableInterface
  • Charcoal\Object\CategorizableMultipleInterface
  • Charcoal\Object\CategoryInterface
  • Charcoal\Object\ContentInterface
  • Charcoal\Object\HierarchicalInterface
  • Charcoal\Object\ObjectRevisionInterface
  • Charcoal\Object\ObjectRouteInterface
  • Charcoal\Object\ObjectScheduleInterface
  • Charcoal\Object\PublishableInterface
  • Charcoal\Object\RevisionableInterface
  • Charcoal\Object\RoutableInterface
  • Charcoal\Object\UserDataInterface
  • Charcoal\User\UserInterface

Traits

  • Charcoal\Object\ArchivableTrait
  • Charcoal\Object\CategorizableMultipleTrait
  • Charcoal\Object\CategorizableTrait
  • Charcoal\Object\CategoryTrait
  • Charcoal\Object\HierarchicalTrait
  • Charcoal\Object\PublishableTrait
  • Charcoal\Object\RevisionableTrait
  • Charcoal\Object\RoutableTrait
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: namespace Charcoal\Object;
 4: 
 5: use Exception;
 6: use InvalidArgumentException;
 7: 
 8: /**
 9:  *
10:  */
11: trait CategoryTrait
12: {
13:     /**
14:      * @var string $itemType
15:      */
16:     private $categoryItemType;
17: 
18:     /**
19:      * @var Collection $categoryItems
20:      */
21:     private $categoryItems;
22: 
23:     /**
24:      * @param string $type The category item type.
25:      * @throws InvalidArgumentException If the type argument is not a string.
26:      * @return CategoryInterface Chainable
27:      */
28:     public function setCategoryItemType($type)
29:     {
30:         if (!is_string($type)) {
31:             throw new InvalidArgumentException(
32:                 'Item type must be a string.'
33:             );
34:         }
35:         $this->categoryItemType = $type;
36:         return $this;
37:     }
38: 
39:     /**
40:      * @throws Exception If no item type was previously set.
41:      * @return string
42:      */
43:     public function categoryItemType()
44:     {
45:         if ($this->categoryItemType === null) {
46:             throw new Exception(
47:                 'Item type is unset. Set item type before calling getter.'
48:             );
49:         }
50:         return $this->categoryItemType;
51:     }
52: 
53:     /**
54:      * @return integer
55:      */
56:     public function numCategoryItems()
57:     {
58:         $items = $this->categoryItems();
59:         return count($items);
60:     }
61: 
62:     /**
63:      * @return boolean
64:      */
65:     public function hasCategoryItems()
66:     {
67:         $numItems = $this->numCategoryItems();
68:         return ($numItems > 0);
69:     }
70: 
71:     /**
72:      * @return Collection A list of `CategorizableInterface` objects
73:      */
74:     public function categoryItems()
75:     {
76:         if ($this->categoryItems === null) {
77:             $this->categoryItems = $this->loadCategoryItems();
78:         }
79:         return $this->categoryItems;
80:     }
81: 
82:     /**
83:      * @return Collection
84:      */
85:     abstract public function loadCategoryItems();
86: }
87: 
API documentation generated by ApiGen