root / trunk / class.tx_pmkglossary_extraeval.php
History | View | Annotate | Download (4.5 kB)
| 1 | <?php
|
|---|---|
| 2 | /***************************************************************
|
| 3 | * Copyright notice |
| 4 | * |
| 5 | * (c) 2010 Peter Klein (pmk@io.dk) |
| 6 | * All rights reserved |
| 7 | * |
| 8 | * This script is part of the TYPO3 project. The TYPO3 project is |
| 9 | * free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * The GNU General Public License can be found at |
| 15 | * http://www.gnu.org/copyleft/gpl.html. |
| 16 | * A copy is found in the textfile GPL.txt and important notices to the license |
| 17 | * from the author is found in LICENSE.txt distributed with these scripts. |
| 18 | * |
| 19 | * |
| 20 | * This script is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * This copyright notice MUST APPEAR in all copies of the script! |
| 26 | ***************************************************************/ |
| 27 | /**
|
| 28 | * [CLASS/FUNCTION INDEX of SCRIPT] |
| 29 | * |
| 30 | * |
| 31 | * |
| 32 | * 49: class tx_pmkglossary_extraeval |
| 33 | * 59: function evaluateFieldValue($value, $is_in, &$set) |
| 34 | * 101: function getPid($uid) |
| 35 | * 114: function checkForDupe($value) |
| 36 | * |
| 37 | * TOTAL FUNCTIONS: 3 |
| 38 | * (This index is automatically created/updated by the extension "extdeveval") |
| 39 | * |
| 40 | */ |
| 41 | |
| 42 | /**
|
| 43 | * 'Custom TCA eval' for the 'pmkglossary' extension. |
| 44 | * |
| 45 | * @author Peter Klein <pmk@io.dk> |
| 46 | * @package TYPO3 |
| 47 | * @subpackage tx_pmkglossary |
| 48 | */ |
| 49 | class tx_pmkglossary_extraeval { |
| 50 | |
| 51 | /**
|
| 52 | * Checks if catchword is unique in pid. |
| 53 | * |
| 54 | * @param mixed $value: The value that has to be checked. |
| 55 | * @param string $is_in: Is-In String |
| 56 | * @param integer $set: Determines if the field can be set (value correct) or not (PASSED BY REFERENCE!) |
| 57 | * @return string $value: The new value of the field |
| 58 | */ |
| 59 | function evaluateFieldValue($value, $is_in, &$set) { |
| 60 | |
| 61 | // Data of current record
|
| 62 | $this->table = 'tx_pmkglossary_glossary'; |
| 63 | $tmp = $GLOBALS['SOBE']->editconf[$this->table]; |
| 64 | $this->data = array_pop($GLOBALS['SOBE']->data[$this->table]); |
| 65 | $this->mode = array_pop($tmp); |
| 66 | switch ((string)$this->mode) { |
| 67 | case 'new': |
| 68 | $this->uid = -1; |
| 69 | // If creating new record , then the value is the pid of the storage folder
|
| 70 | $this->pid = array_pop(array_keys($GLOBALS['SOBE']->editconf[$this->table])); |
| 71 | break;
|
| 72 | case 'edit': |
| 73 | // But if editing existing record , then the value is the uid of the record!!
|
| 74 | $this->uid = array_pop(array_keys($GLOBALS['SOBE']->editconf[$this->table])); |
| 75 | $this->pid = $this->getPid($this->uid); |
| 76 | break;
|
| 77 | default;
|
| 78 | } |
| 79 | |
| 80 | // Reverse the use of the "is_in" field in order to remove possible commas from the title field
|
| 81 | $value = str_replace($is_in,'',$value); |
| 82 | |
| 83 | $out = array(); |
| 84 | $values = t3lib_div::trimExplode(',',$value); |
| 85 | foreach ($values as $value) { |
| 86 | if (!$this->checkForDupe($value)) { |
| 87 | $out[] = $value; |
| 88 | } |
| 89 | } |
| 90 | $value = implode(',',$out); |
| 91 | |
| 92 | return $value ? $value : ' '; |
| 93 | } |
| 94 | |
| 95 | /**
|
| 96 | * Get Page Id (PID) of record. |
| 97 | * |
| 98 | * @param integer $uid: Id of record. |
| 99 | * @return integer $row['pid']: Id of storage folder. |
| 100 | */ |
| 101 | function getPid($uid) { |
| 102 | $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('pid', $this->table,'uid='.$uid.' AND deleted=0'); |
| 103 | $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); |
| 104 | return $row['pid']; |
| 105 | } |
| 106 | |
| 107 | /**
|
| 108 | * Check if there already exists a record with the same title. |
| 109 | * Or if the title is present in the altitle of another record. |
| 110 | * |
| 111 | * @param string $value: The value that has to be checked. |
| 112 | * @return boolean true if duplicate title is found |
| 113 | */ |
| 114 | function checkForDupe($value) { |
| 115 | $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('title', $this->table, |
| 116 | 'pid='.intval($this->pid).' AND uid!='.intval($this->uid).' AND deleted=0'. |
| 117 | ' AND sys_language_uid IN (-1,'.intval($this->data['sys_language_uid']). |
| 118 | ') AND (title='.$GLOBALS['TYPO3_DB']->fullQuoteStr($value, $this->table) . |
| 119 | ' OR '.$GLOBALS['TYPO3_DB']->listQuery('alttitle', $value, $this->table).')'); |
| 120 | $result = $GLOBALS['TYPO3_DB']->sql_num_rows($res); |
| 121 | $GLOBALS['TYPO3_DB']->sql_free_result($res); |
| 122 | return $result>0 ? true : false; |
| 123 | } |
| 124 | |
| 125 | } |
| 126 | |
| 127 | |
| 128 | if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/pmkglossary/class.tx_pmkglossary_extraeval.php']) { |
| 129 | include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/pmkglossary/class.tx_pmkglossary_extraeval.php']); |
| 130 | } |
| 131 | ?> |