/** * pigeonholes_content_store * * @param array $pObject * @param array $pParamHash * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function pigeonholes_content_store($pObject, $pParamHash) { global $gBitSmarty, $gBitUser, $gBitSystem; if (is_object($pObject) && isset($pObject->mContentTypeGuid) && !$gBitSystem->isFeatureActive('pigeonhole_no_' . $pObject->mContentTypeGuid) && $gBitUser->hasPermission('p_pigeonholes_insert_member')) { if (is_object($pObject) && empty($pParamHash['content_id'])) { $pParamHash['content_id'] = $pObject->mContentId; } if (!empty($pParamHash['content_id'])) { $pigeonholes = new Pigeonholes(); $pigeonPathList = $pigeonholes->getPigeonholesPathList($pParamHash['content_id']); // here we need to work out if we need to save at all // get all originally selected items $selectedItem = array(); if (!empty($pigeonPathList)) { foreach ($pigeonPathList as $path) { if (!empty($path[0]['selected'])) { $pathItem = array_pop($path); $selectedItem[] = $pathItem['content_id']; } } } // quick and dirty check to start off with if (empty($pParamHash['pigeonholes']) || count($pParamHash['pigeonholes']['pigeonhole']) != count($selectedItem)) { $modified = TRUE; } else { // more thorough check foreach ($selectedItem as $item) { if (!in_array($item, $pParamHash['pigeonholes']['pigeonhole'])) { $modified = TRUE; } } } if (!empty($modified)) { // first remove all entries with this content_id if ($pigeonholes->expungePigeonholeMember(array('member_id' => $pParamHash['content_id'])) && !empty($pParamHash['pigeonholes'])) { // insert the content into the desired pigeonholes foreach ($pParamHash['pigeonholes']['pigeonhole'] as $p_id) { $memberHash[] = array('parent_id' => $p_id, 'content_id' => $pParamHash['content_id']); } if (!$pigeonholes->insertPigeonholeMember($memberHash)) { $gBitSmarty->assign('msg', tra("There was a problem inserting the content into the pigeonholes.")); $gBitSystem->display('error.tpl', NULL, array('display_mode' => 'display')); die; } } } } } }