| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJT_Models_Block_Assignmentpanel_Base { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @var mixed |
| 15 |
*/ |
| 16 |
protected $blockId = null; |
| 17 |
|
| 18 |
/** |
| 19 |
* put your comment there... |
| 20 |
* |
| 21 |
* @var mixed |
| 22 |
*/ |
| 23 |
protected $iPerPage = null; |
| 24 |
|
| 25 |
/** |
| 26 |
* put your comment there... |
| 27 |
* |
| 28 |
* @var mixed |
| 29 |
*/ |
| 30 |
protected $offset = null; |
| 31 |
|
| 32 |
/** |
| 33 |
* put your comment there... |
| 34 |
* |
| 35 |
* @var mixed |
| 36 |
*/ |
| 37 |
protected $typeParams = null; |
| 38 |
|
| 39 |
/** |
| 40 |
* put your comment there... |
| 41 |
* |
| 42 |
* @param mixed $offset |
| 43 |
* @param mixed $oPerPage |
| 44 |
* @param mixed $blockId |
| 45 |
* @param mixed $typeParams |
| 46 |
* @return CJT_Models_Block_Assignmentpanel_Base |
| 47 |
*/ |
| 48 |
public function __construct($offset, $iPerPage, $blockId, $typeParams) { |
| 49 |
// Initialize. |
| 50 |
$this->offset = $offset; |
| 51 |
$this->iPerPage = $iPerPage; |
| 52 |
$this->blockId = $blockId; |
| 53 |
$this->typeParams = $typeParams; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* put your comment there... |
| 58 |
* |
| 59 |
* @param mixed $assignedOnly |
| 60 |
* @param mixed $type |
| 61 |
* @param mixed $offset |
| 62 |
* @param mixed $iPerPage |
| 63 |
* @param mixed $blockId |
| 64 |
* @param mixed $typeParams |
| 65 |
*/ |
| 66 |
public static function getInstance($assignedOnly, $type, $offset, $iPerPage, $blockId, $typeParams) { |
| 67 |
// Get type class name. |
| 68 |
$typeName = strtoupper($type); |
| 69 |
// Inistantiate 'pinned' object if assignedOnly flag is set to true. |
| 70 |
if ($assignedOnly) { |
| 71 |
$typeName .= 'pinned'; |
| 72 |
} |
| 73 |
// Build items-list handler class name. |
| 74 |
$typeClass = "CJT_Models_Block_Assignmentpanel_{$typeName}"; |
| 75 |
// Instantiate type object. |
| 76 |
$typeObject = new $typeClass($offset, $iPerPage, $blockId, $typeParams); |
| 77 |
// Return instance. |
| 78 |
return $typeObject; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* put your comment there... |
| 83 |
* |
| 84 |
*/ |
| 85 |
public function getItems() { |
| 86 |
// Initialize. |
| 87 |
$params = $this->getTypeParams(); |
| 88 |
$blockId = $this->getBlockId(); |
| 89 |
$pinsMap = array(); |
| 90 |
$items = array(); |
| 91 |
// Pins map. |
| 92 |
$pinsMap = $this->getPinsMap(); |
| 93 |
// Query all items by the model class. |
| 94 |
$items = $this->queryItems(); |
| 95 |
// Prepare all retrieved items by 'base' and model classes. |
| 96 |
foreach ($items as $key => & $item) { |
| 97 |
// Prepare the item by the model class. |
| 98 |
$this->prepareItem($key, $item); |
| 99 |
// Set if item is assigned to the block! |
| 100 |
$item['assigned'] = isset($pinsMap[$item['id']]); |
| 101 |
} |
| 102 |
// In case the object type is Hierarchical |
| 103 |
// Pass the items list to the filter. |
| 104 |
if ($this->isHierarchical()) { |
| 105 |
// Hierarchical filter. |
| 106 |
$hierarchicalFilter = new CJT_Models_Block_Assignmentpanel_Helpers_Hierarchical( |
| 107 |
$this->getOffset(), |
| 108 |
$this->getIPerPage(), |
| 109 |
$items |
| 110 |
); |
| 111 |
// Get items with childs in the correct order! |
| 112 |
$items = $hierarchicalFilter->getItems(); |
| 113 |
} |
| 114 |
// Return items list. |
| 115 |
return $items; |
| 116 |
} |
| 117 |
|
| 118 |
/** |
| 119 |
* put your comment there... |
| 120 |
* |
| 121 |
*/ |
| 122 |
public function getBlockId() { |
| 123 |
return $this->blockId; |
| 124 |
} |
| 125 |
|
| 126 |
/** |
| 127 |
* put your comment there... |
| 128 |
* |
| 129 |
*/ |
| 130 |
public function getIPerPage() { |
| 131 |
return $this->iPerPage; |
| 132 |
} |
| 133 |
|
| 134 |
/** |
| 135 |
* put your comment there... |
| 136 |
* |
| 137 |
*/ |
| 138 |
public function getOffset() { |
| 139 |
return $this->offset; |
| 140 |
} |
| 141 |
|
| 142 |
/** |
| 143 |
* Query/Get-Cached pins map. |
| 144 |
* |
| 145 |
*/ |
| 146 |
protected final function getPinsMap() { |
| 147 |
// Initialize. |
| 148 |
static $map = null; |
| 149 |
if ($map === null) { |
| 150 |
$map = $this->pinsMap(); |
| 151 |
} |
| 152 |
// Returns. |
| 153 |
return $map; |
| 154 |
} |
| 155 |
|
| 156 |
public abstract function getTotalCount(); |
| 157 |
|
| 158 |
/** |
| 159 |
* put your comment there... |
| 160 |
* |
| 161 |
*/ |
| 162 |
public function & getTypeParams() { |
| 163 |
return $this->typeParams; |
| 164 |
} |
| 165 |
|
| 166 |
/** |
| 167 |
* put your comment there... |
| 168 |
* |
| 169 |
* @return Boolean |
| 170 |
*/ |
| 171 |
protected abstract function isHierarchical(); |
| 172 |
|
| 173 |
/** |
| 174 |
* put your comment there... |
| 175 |
* |
| 176 |
*/ |
| 177 |
protected abstract function pinsMap(); |
| 178 |
|
| 179 |
/** |
| 180 |
* put your comment there... |
| 181 |
* |
| 182 |
* @param mixed $item |
| 183 |
* @return void |
| 184 |
*/ |
| 185 |
protected abstract function prepareItem($key, & $item); |
| 186 |
|
| 187 |
/** |
| 188 |
* put your comment there... |
| 189 |
* |
| 190 |
* @return Array Items list. |
| 191 |
*/ |
| 192 |
protected abstract function queryItems(); |
| 193 |
|
| 194 |
} // End class. |
| 195 |
|