Exemplo n.º 1
0
 /**
  * Gets rootline of a table downwards
  *
  * @param string $theTable: Database table
  * @param string $parentField: Database field to check with third parameter
  * @param mixed $uids: Uids of (different) parents
  * @return string An rootline array
  *
  */
 public static function getRootLineUpwards($theTable, $parentField, $uids)
 {
     if (!is_array($uids)) {
         $uids = tx_cpsdevlib_div::explode($uids);
     }
     $rootLine = array();
     foreach ($uids as $uid) {
         $result = t3lib_BEfunc::getRecordsByField($theTable, 'uid', $uid);
         $rL = array();
         if (count($result)) {
             $rL = self::getRootLineUpwards($theTable, $parentField, $result[0][$parentField]);
         }
         $rootLine[$uid] = $rL;
     }
     return $rootLine;
 }
Exemplo n.º 2
0
 function renderTree()
 {
     t3lib_div::loadTCA($this->fieldConfig['foreign_table']);
     $orderBy = $GLOBALS['TCA'][$this->fieldConfig['foreign_table']]['ctrl']['sortby'] ? $this->fieldConfig['foreign_table'] . '.' . $GLOBALS['TCA'][$this->fieldConfig['foreign_table']]['ctrl']['sortby'] : substr($GLOBALS['TCA'][$this->fieldConfig['foreign_table']]['ctrl']['default_sortby'], 9);
     $treeViewObj = t3lib_div::makeInstance('tx_cpstcatree_treeview');
     $treeViewObj->thisScript = 'class.tx_cpstcatree.php';
     $treeViewObj->title = $GLOBALS['LANG']->sL($GLOBALS['TCA'][$this->fieldConfig['foreign_table']]['ctrl']['title']);
     $treeViewObj->treeName = $this->table . '_' . $this->field . '_tree';
     $treeViewObj->table = $this->fieldConfig['foreign_table'];
     // Set parent field of table
     if (isset($this->fieldConfig['treeViewParentField'])) {
         $this->parentField = $this->fieldConfig['treeViewParentField'];
     } else {
         $this->parentField = $GLOBALS['TCA'][$this->fieldConfig['foreign_table']]['ctrl']['treeParentField'];
     }
     if (!$this->parentField) {
         $this->parentField = 'pid';
     }
     $treeViewObj->parentField = $this->parentField;
     $treeViewObj->parentField = $this->parentField;
     // Set select fields
     $treeViewObj->fieldArray = array('uid');
     $treeViewObj->addField($GLOBALS['TCA'][$treeViewObj->table]['ctrl']['label']);
     if (isset($GLOBALS['TCA'][$treeViewObj->table]['ctrl']['label_alt'])) {
         $treeViewObj->addField($GLOBALS['TCA'][$treeViewObj->table]['ctrl']['label_alt']);
     }
     $treeViewObj->tceFormsTable = $this->table;
     if ($this->table == 'tt_content') {
         $treeViewObj->tceFormsField = $this->field . ',' . $this->fieldConfig['piFlexFormSheet'] . ',' . $this->fieldConfig['piFlexFormLang'] . ',' . $this->fieldConfig['piFlexFormValue'] . ',' . $this->row['CType'] . ',' . $this->row['list_type'];
     } else {
         $treeViewObj->tceFormsField = $this->field;
     }
     $treeViewObj->tceFormsRecID = $this->row['uid'];
     $treeViewObj->ext_IconMode = '0';
     $treeViewObj->treeView = $this->fieldConfig['treeView'];
     $treeViewObj->expandable = $this->fieldConfig['expandable'];
     $treeViewObj->expandFirst = $this->fieldConfig['expandFirst'];
     $treeViewObj->expandAll = $this->fieldConfig['expandAll'];
     $treeViewObj->ignorePermsClause = $this->fieldConfig['ignorePermsClause'];
     // Get TSconfig
     $TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig($this->table, $this->row);
     // Get TSconfig for field
     if ($this->table == 'tt_content') {
         $fieldTSconfig = t3lib_TCEforms::setTSconfig($this->table, $this->row);
         $fieldTSconfig = $fieldTSconfig['pi_flexform'][$this->row['list_type'] . '.'][$this->field . '.'];
     } else {
         $fieldTSconfig = t3lib_TCEforms::setTSconfig($this->table, $this->row, $this->field);
     }
     $clause = '';
     // removeItems
     if (isset($fieldTSconfig['removeItems'])) {
         $this->removeItems = tx_cpsdevlib_div::toListArray(tx_cpsdevlib_db::getRootLineDownwards($treeViewObj->table, $treeViewObj->parentField, $fieldTSconfig['removeItems']), '', 1, 1, 1);
     }
     // keepItems
     if (isset($fieldTSconfig['keepItems'])) {
         $this->keepItems = tx_cpsdevlib_div::toListArray($fieldTSconfig['keepItems']);
         if (count($this->removeItems)) {
             // If items were removed from list check keepItems to add back
             foreach ($this->keepItems as $value) {
                 if (($key = array_search($value, $this->removeItems)) !== false) {
                     unset($this->removeItems[$key]);
                     // Get rootline upwards to restore parent items
                     $rL = tx_cpsdevlib_div::toListArray(tx_cpsdevlib_db::getRootLineUpwards($treeViewObj->table, 'pid', $value), '', 1, 1, 1);
                     foreach ($rL as $v) {
                         if (($k = array_search($v, $this->removeItems)) !== false) {
                             $treeViewObj->TCEforms_nonSelectableItemsArray[] = $v;
                             unset($this->removeItems[$k]);
                         }
                     }
                 }
             }
         } else {
             // If just keepItems is set only show selected
             if (count($this->keepItems)) {
                 $clause = ' AND ' . $treeViewObj->table . '.uid IN (' . implode(',', $this->keepItems) . ')';
             }
         }
     }
     if (count($this->removeItems)) {
         $clause = ' AND ' . $treeViewObj->table . '.uid NOT IN (' . implode(',', $this->removeItems) . ')';
     }
     // hideItems
     if (isset($fieldTSconfig['hideItems'])) {
         $this->hideItems = tx_cpsdevlib_div::toListArray($fieldTSconfig['hideItems']);
         $treeViewObj->TCEforms_nonSelectableItemsArray = array_merge($treeViewObj->TCEforms_nonSelectableItemsArray, $this->hideItems);
     }
     // Add foreign_table_where
     if ($this->fieldConfig['foreign_table_where']) {
         // Remove ORDER BY part if present
         if (strpos(strtolower($this->fieldConfig['foreign_table_where']), 'order by') !== false) {
             $ftWhere = substr($this->fieldConfig['foreign_table_where'], 0, strpos(strtolower($this->fieldConfig['foreign_table_where']), 'order by'));
         } else {
             $ftWhere = $this->fieldConfig['foreign_table_where'];
         }
         // Replace record maker in foreign_table_where
         if (strstr($ftWhere, '###REC_FIELD_')) {
             $ftWhereParts = explode('###REC_FIELD_', $ftWhere);
             foreach ($ftWhereParts as $key => $value) {
                 if ($key) {
                     $ftWhereSubpart = explode('###', $value, 2);
                     if (substr($ftWhereParts[0], -1) === '\'' && $ftWhereSubpart[1][0] === '\'') {
                         $ftWhereParts[$key] = $GLOBALS['TYPO3_DB']->quoteStr($TSconfig['_THIS_ROW'][$ftWhereSubpart[0]], $treeViewObj->table) . $ftWhereSubpart[1];
                     } else {
                         $ftWhereParts[$key] = $GLOBALS['TYPO3_DB']->fullQuoteStr($TSconfig['_THIS_ROW'][$ftWhereSubpart[0]], $treeViewObj->table) . $ftWhereSubpart[1];
                     }
                 }
             }
             $ftWhere = implode('', $ftWhereParts);
         }
         // Replace special marker in foreign_table_where
         $ftWhere = str_replace('###CURRENT_PID###', intval($TSconfig['_CURRENT_PID']), $ftWhere);
         $ftWhere = str_replace('###THIS_UID###', intval($TSconfig['_THIS_UID']), $ftWhere);
         $ftWhere = str_replace('###THIS_CID###', intval($TSconfig['_THIS_CID']), $ftWhere);
         $ftWhere = str_replace('###STORAGE_PID###', intval($TSconfig['_STORAGE_PID']), $ftWhere);
         $ftWhere = str_replace('###SITEROOT###', intval($TSconfig['_SITEROOT']), $ftWhere);
         $ftWhere = str_replace('###PAGE_TSCONFIG_ID###', intval($TSconfig[$this->field]['PAGE_TSCONFIG_ID']), $ftWhere);
         $ftWhere = str_replace('###PAGE_TSCONFIG_IDLIST###', $GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$this->field]['PAGE_TSCONFIG_IDLIST']), $ftWhere);
         $ftWhere = str_replace('###PAGE_TSCONFIG_STR###', $GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$this->field]['PAGE_TSCONFIG_STR'], $this->fieldConfig['foreign_table']), $ftWhere);
         $clause .= ' ' . trim($ftWhere);
     }
     // Hook to manipulate clause
     $parameter = array('clause' => &$clause, 'treeViewObj' => &$treeViewObj);
     tx_cpsdevlib_div::callHookObjects('cps_tcatree', 'changeClauseHook', $parameter, $this);
     $treeViewObj->init($clause, $orderBy);
     $treeViewObj->TCEforms_itemFormElName = $this->itemFormElName;
     if ($this->table == $this->fieldConfig['foreign_table']) {
         $treeViewObj->TCEforms_nonSelectableItemsArray[] = $this->row['uid'];
     }
     $treeViewObj->TCEforms_selectedItemsArray = $this->selectedItems;
     $treeViewObj->selectedItemsArrayParents = $this->getItemRootline($this->selectedItems);
     $treeContent = $treeViewObj->getBrowsableTree();
     return $treeContent;
 }
 /**
  * @test
  * @depends checkStringToListArray
  * @dataProvider testQueryStringToArrayDataProvider
  * @param string $removeKeys
  * @param string $theSeparator
  * @param string $equalChar
  * @param string $altSeparators
  * @param array $expectedReturnArray
  */
 public function checkQueryStringToArray($removeKeys, $theSeparator, $equalChar, $altSeparators, $expectedReturnArray)
 {
     $this->assertEquals($expectedReturnArray, tx_cpsdevlib_div::queryStringToArray(str_replace('+', $altSeparators, str_replace('=', $equalChar, str_replace('&', $theSeparator, str_replace('&', '+', $this->fixture['testQueryString'])))), $removeKeys, $theSeparator, $equalChar, $altSeparators));
 }