function do_storeRelationship()
 {
     // handle the store, and DON'T give a 500 ;)  does not act on the information.
     global $default;
     $default->log->error(http_build_query($_REQUEST));
     $iFieldsetId = KTUtil::arrayGet($_REQUEST, 'fieldset_id');
     $parent_field = KTUtil::arrayGet($_REQUEST, 'parent_field');
     $parent_lookup = KTUtil::arrayGet($_REQUEST, 'parent_lookup');
     $child_lookups = KTUtil::arrayGet($_REQUEST, 'child_lookups');
     // child lookups is a nested array. in python it would be:
     // child_lookups =
     //  {
     //     field_id:[lookup_id, lookup_id],
     //     field_id:[lookup_id, lookup_id],
     //  }
     $oFieldset =& KTFieldset::get($iFieldsetId);
     $oFieldset->setIsComplete(false);
     $oFieldset->update();
     $oParentInstance = KTMetadataUtil::getOrCreateValueInstanceForLookup($parent_lookup);
     $iBehaviourId = $oParentInstance->getBehaviourId();
     $oParentMetadata =& MetaData::get($oParentInstance->getFieldValueId());
     if (is_null($iBehaviourId)) {
         $oBehaviour =& KTFieldBehaviour::createFromArray(array('name' => 'autoinstance' . $oParentInstance->getId(), 'humanname' => 'Auto instance' . $oParentMetadata->getName(), 'fieldid' => $oParentInstance->getFieldId()));
     } else {
         $oBehaviour =& KTFieldBehaviour::get($iBehaviourId);
     }
     if (PEAR::isError($oBehaviour)) {
         var_dump($oBehaviour);
         return $oBehaviour;
     }
     $iBehaviourId = $oBehaviour->getId();
     $oParentInstance->setBehaviourId($iBehaviourId);
     $oParentInstance->update();
     $sTable = KTUtil::getTableName('field_behaviour_options');
     $aOptions = array('noid' => true);
     $aQuery = array("DELETE FROM {$sTable} WHERE behaviour_id = ?", array($iBehaviourId));
     $res = DBUtil::runQuery($aQuery);
     foreach ($child_lookups as $iFieldId => $aLookups) {
         foreach ($aLookups as $iLookupId) {
             $oValueInstance =& KTMetadataUtil::getOrCreateValueInstanceForLookup($iLookupId);
             if (PEAR::isError($oValueInstance)) {
                 var_dump($oValueInstance);
                 return $oValueInstance;
             }
             $res = DBUtil::autoInsert($sTable, array('behaviour_id' => $iBehaviourId, 'field_id' => $iFieldId, 'instance_id' => $oValueInstance->getId()), $aOptions);
             if (PEAR::isError($res)) {
                 var_dump($res);
                 return $res;
             }
         }
     }
 }
示例#2
0
 function check()
 {
     $this->browse_mode = KTUtil::arrayGet($_REQUEST, 'fBrowseMode', 'folder');
     $action = KTUtil::arrayGet($_REQUEST, $this->event_var, 'main');
     $this->editable = false;
     // catch the alternative actions.
     if ($action != 'main') {
         return true;
     }
     // if we're going to main ...
     // folder browse mode
     if ($this->browse_mode == 'folder') {
         $in_folder_id = KTUtil::arrayGet($_REQUEST, 'fFolderId');
         if (empty($in_folder_id)) {
             $oConfig = KTConfig::getSingleton();
             if ($oConfig->get('tweaks/browseToUnitFolder')) {
                 $iHomeFolderId = $this->oUser->getHomeFolderId();
                 if ($iHomeFolderId) {
                     $in_folder_id = $iHomeFolderId;
                 }
             }
         }
         $folder_id = (int) $in_folder_id;
         // conveniently, will be 0 if not possible.
         if ($folder_id == 0) {
             $folder_id = 1;
         }
         $_REQUEST['fBrowseMode'] = 'folder';
         // here we need the folder object to do the breadcrumbs.
         $oFolder =& Folder::get($folder_id);
         if (PEAR::isError($oFolder)) {
             return false;
             // just fail.
         }
         // check whether the user can edit this folder
         $oPerm = KTPermission::getByName('ktcore.permissions.write');
         if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, $oPerm, $oFolder)) {
             $this->editable = true;
         } else {
             $this->editable = false;
         }
         // set the title and breadcrumbs...
         $this->oPage->setTitle(_kt('Browse'));
         if (KTPermissionUtil::userHasPermissionOnItem($this->oUser, 'ktcore.permissions.folder_details', $oFolder)) {
             $this->oPage->setSecondaryTitle($oFolder->getName());
         } else {
             if (KTBrowseUtil::inAdminMode($this->oUser, $oFolder)) {
                 $this->oPage->setSecondaryTitle(sprintf('(%s)', $oFolder->getName()));
             } else {
                 $this->oPage->setSecondaryTitle('...');
             }
         }
         //Figure out if we came here by navigating trough a shortcut.
         //If we came here from a shortcut, the breadcrumbspath should be relative
         //to the shortcut folder.
         $iSymLinkFolderId = KTUtil::arrayGet($_REQUEST, 'fShortcutFolder', null);
         if (is_numeric($iSymLinkFolderId)) {
             $oBreadcrumbsFolder = Folder::get($iSymLinkFolderId);
             $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForFolder($oBreadcrumbsFolder, array('final' => false)));
             $this->aBreadcrumbs[] = array('name' => $oFolder->getName());
         } else {
             $this->aBreadcrumbs = kt_array_merge($this->aBreadcrumbs, KTBrowseUtil::breadcrumbsForFolder($oFolder));
         }
         $this->oFolder =& $oFolder;
         // we now have a folder, and need to create the query.
         $aOptions = array('ignorepermissions' => KTBrowseUtil::inAdminMode($this->oUser, $oFolder));
         $this->oQuery = new BrowseQuery($oFolder->getId(), $this->oUser, $aOptions);
         $this->resultURL = KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fFolderId=%d', $oFolder->getId()));
         // and the portlets
         $portlet = new KTActionPortlet(sprintf(_kt('About this folder')));
         $aActions = KTFolderActionUtil::getFolderInfoActionsForFolder($this->oFolder, $this->oUser);
         $portlet->setActions($aActions, $this->sName);
         $this->oPage->addPortlet($portlet);
         $portlet = new KTActionPortlet(sprintf(_kt('Actions on this folder')));
         $aActions = KTFolderActionUtil::getFolderActionsForFolder($oFolder, $this->oUser);
         $portlet->setActions($aActions, null);
         $this->oPage->addPortlet($portlet);
     } else {
         if ($this->browse_mode == 'lookup_value') {
             // browsing by a lookup value
             $this->editable = false;
             // check the inputs
             $field = KTUtil::arrayGet($_REQUEST, 'fField', null);
             $oField = DocumentField::get($field);
             if (PEAR::isError($oField) || $oField == false) {
                 $this->errorRedirectToMain('No Field selected.');
                 exit(0);
             }
             $value = KTUtil::arrayGet($_REQUEST, 'fValue', null);
             $oValue = MetaData::get($value);
             if (PEAR::isError($oValue) || $oValue == false) {
                 $this->errorRedirectToMain('No Value selected.');
                 exit(0);
             }
             $this->oQuery = new ValueBrowseQuery($oField, $oValue);
             $this->resultURL = KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fBrowseMode=lookup_value&fField=%d&fValue=%d', $field, $value));
             // setup breadcrumbs
             $this->aBreadcrumbs = array(array('name' => _kt('Lookup Values'), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'action=selectField')), array('name' => $oField->getName(), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'action=selectLookup&fField=' . $oField->getId())), array('name' => $oValue->getName(), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fBrowseMode=lookup_value&fField=%d&fValue=%d', $field, $value))));
         } else {
             if ($this->browse_mode == 'document_type') {
                 // browsing by document type
                 $this->editable = false;
                 $doctype = KTUtil::arrayGet($_REQUEST, 'fType', null);
                 $oDocType = DocumentType::get($doctype);
                 if (PEAR::isError($oDocType) || $oDocType == false) {
                     $this->errorRedirectToMain('No Document Type selected.');
                     exit(0);
                 }
                 $this->oQuery = new TypeBrowseQuery($oDocType);
                 // FIXME probably want to redirect to self + action=selectType
                 $this->aBreadcrumbs[] = array('name' => _kt('Document Types'), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'action=selectType'));
                 $this->aBreadcrumbs[] = array('name' => $oDocType->getName(), 'url' => KTUtil::addQueryString($_SERVER['PHP_SELF'], 'fBrowseMode=document_type&fType=' . $oDocType->getId()));
                 $this->resultURL = KTUtil::addQueryString($_SERVER['PHP_SELF'], sprintf('fType=%s&fBrowseMode=document_type', $doctype));
             } else {
                 // FIXME what should we do if we can't initiate the browse?  we "pretend" to have no perms.
                 return false;
             }
         }
     }
     return true;
 }
 /**
  * Given a behaviour, return an array of lookup ids (Metadata->id)
  * that are available for each of the columns/fields that this
  * behaviour's column affects.
  *
  * Return value:
  *
  * Associative array keyed by field_id, value is an array of lookup
  * ids.
  *
  * array(
  *      1 => array(1, 2, 3, 4),
  *      ...
  * );
  */
 function getNextValuesForBehaviour($oBehaviour)
 {
     $oBehaviour =& KTUtil::getObject('KTFieldBehaviour', $oBehaviour);
     $aValues = array();
     $sTable = KTUtil::getTableName('field_behaviour_options');
     $aChildFieldIds = KTMetadataUtil::getChildFieldIds($oBehaviour->getFieldId());
     foreach ($aChildFieldIds as $iFieldId) {
         $aValues[$iFieldId] = array();
     }
     $aQuery = array("SELECT field_id, instance_id FROM {$sTable} WHERE behaviour_id = ?", array($oBehaviour->getId()));
     $aRows = DBUtil::getResultArray($aQuery);
     if (PEAR::isError($aRows)) {
         return $aRows;
     }
     foreach ($aRows as $aRow) {
         $oInstance =& KTValueInstance::get($aRow['instance_id']);
         // need to wean out the disabled values.
         // now get the metadata value.
         $oMetadata = MetaData::get($oInstance->getFieldValueId());
         if (PEAR::isError($oMetadata)) {
             continue;
             // invalid link.  bugger.
         }
         if ($oMetadata->getDisabled()) {
             continue;
             // disabled.
         }
         $aValues[$aRow['field_id']][] = $oInstance->getFieldValueId();
     }
     return $aValues;
 }
示例#4
0
 function subact_unlinkKeyword(&$constructedTree, $keyword)
 {
     $oKW = MetaData::get($keyword);
     if (PEAR::isError($oKW)) {
         return true;
     }
     $constructedTree->reparentKeyword($oKW->getId(), 0);
     return true;
 }
 function get_nofollow($postid)
 {
     return MetaData::get($postid, 'nofollow');
 }