| @@ -140,13 +140,70 @@ | ||
| 140 | 140 | |
| 141 | 141 | /** |
| 142 | 142 | * put your comment there... |
| 143 | 143 | * |
| 144 | + * @param mixed $blockData | |
| 145 | + */ | |
| 146 | + public static function arrangePins(& $blockData) { | |
| 147 | + // Initialize | |
| 148 | + $pinsGroupNames = array_flip(array('pages', 'posts', 'categories', 'pinPoint')); | |
| 149 | + $dbDriver = cssJSToolbox::getInstance()->getDBDriver(); | |
| 150 | + $mdlBlock = new CJTBlocksModel(); | |
| 151 | + $block = $mdlBlock->getBlock($blockData->id, array(), array('id', 'pinPoint')); | |
| 152 | + $submittedPins = array_intersect_key(((array) $blockData), $pinsGroupNames); | |
| 153 | + $assignedPins = array_intersect_key(((array) $block), $pinsGroupNames); | |
| 154 | + // Transfer assigned PinPoint from "FLAGGED INTEGER" TO "ARRAY" like | |
| 155 | + // the other pins. | |
| 156 | + $assignedPins['pinPoint'] = array_keys(CJT_Models_Block_Assignmentpanel_Helpers_Auxiliary | |
| 157 | + ::getInstance() | |
| 158 | + ->getPinsArray($assignedPins['pinPoint'])); | |
| 159 | + // Walk through all assigned pins. | |
| 160 | + // Unassigned any item with 'value=false'. | |
| 161 | + // Whenever an item is found on the submitted | |
| 162 | + // pins it should be removed from the submitted list | |
| 163 | + foreach ($submittedPins as $groupName => $submittedGroup) { | |
| 164 | + // Get assigned pins group if found | |
| 165 | + if (!isset($assignedPins[$groupName])) { | |
| 166 | + // Initialize new assigned group array. | |
| 167 | + $assignedPins[$groupName] = array(); | |
| 168 | + } | |
| 169 | + // Get assigned group array reference. | |
| 170 | + $assignedGroup =& $assignedPins[$groupName]; | |
| 171 | + // For every submitted item there is three types. | |
| 172 | + // 1. Already assigned :WHEN: (sync == true and value == true) | |
| 173 | + // 2. Unassigned :WHEN: (value == false) | |
| 174 | + // 3. Newly assigned :WHEN: (sync = false). | |
| 175 | + foreach ($submittedGroup as $submittedPinId => $submittedPin) { | |
| 176 | + // Unassigned pin | |
| 177 | + if (!$submittedPin['value']) { | |
| 178 | + // Find the submittedPinId AssignedPins index. | |
| 179 | + $assignedIndex = array_search($submittedPinId, $assignedGroup); | |
| 180 | + // Unassigned it :REMOVE FROM ARRAY: | |
| 181 | + unset($assignedGroup[$assignedIndex]); | |
| 182 | + } | |
| 183 | + else if (!$submittedPin['sync']) { | |
| 184 | + // Add newly assigned item. | |
| 185 | + $assignedGroup[] = $submittedPinId; | |
| 186 | + } | |
| 187 | + } | |
| 188 | + } | |
| 189 | + // Copy all assigned pins back to the block object. | |
| 190 | + foreach ($assignedPins as $groupName => $finalGroupAssigns) { | |
| 191 | + // Copy the group back to the block object. | |
| 192 | + $blockData->{$groupName} = $finalGroupAssigns; | |
| 193 | + } | |
| 194 | + // Important for caller short-circle condition. | |
| 195 | + return true; | |
| 196 | + } | |
| 197 | + | |
| 198 | + /** | |
| 199 | + * put your comment there... | |
| 200 | + * | |
| 144 | 201 | * @deprecated Use calculatePinpoint |
| 145 | 202 | */ |
| 146 | - public static function calculateBlockPinPoint(&$block) { | |
| 203 | + public static function calculateBlockPinPoint(& $block) { | |
| 147 | 204 | // Generate PinPoint Value. |
| 148 | - if (is_array($block->pinPoint)) { | |
| 205 | + if (isset($block->pinPoint) && is_array($block->pinPoint)) { | |
| 149 | 206 | $pinPoint = 0; |
| 150 | 207 | // Each item is a bit flag. |
| 151 | 208 | foreach ($block->pinPoint as $pin) { |
| 152 | 209 | $pinPoint |= hexdec($pin); |
| @@ -152,9 +209,12 @@ | ||
| 152 | 209 | $pinPoint |= hexdec($pin); |
| 153 | 210 | } |
| 154 | 211 | } |
| 155 | 212 | else { |
| 156 | - // If provided as integer. | |
| 213 | + // Provided as integer or not even provided! | |
| 214 | + if (!isset($block->pinPoint)) { | |
| 215 | + $block->pinPoint = 0; | |
| 216 | + } | |
| 157 | 217 | $pinPoint = (int) $block->pinPoint; |
| 158 | 218 | } |
| 159 | 219 | // Pin should be set only for not empty properties. |
| 160 | 220 | // This help us retreiving only needed blocks when outputing blocks code. |
| @@ -185,15 +245,6 @@ | ||
| 185 | 245 | $pinPoint = self::calculateBlockPinPoint($block)->pinPoint; |
| 186 | 246 | // Return only pinPoint. |
| 187 | 247 | return $pinPoint; |
| 188 | 248 | } |
| 189 | - | |
| 190 | - /** | |
| 191 | - * put your comment there... | |
| 192 | - * | |
| 193 | - * @param mixed $values | |
| 194 | - */ | |
| 195 | - public static function getInstance($values) { | |
| 196 | - return new CJTBlockModel($values); | |
| 197 | - } | |
| 198 | - | |
| 249 | + | |
| 199 | 250 | } // End class. |