Commit f0b490f8e708d8d4f496646455ee9daa0ec67aa6
1 parent
a4a22e79
Modernise to use $_aFieldToSelect, use Id instead of ID
Add most common read operation - getByDocumentAndField git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3913 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
33 additions
and
28 deletions
lib/documentmanagement/DocumentFieldLink.inc
| @@ -29,12 +29,18 @@ class DocumentFieldLink extends KTEntity { | @@ -29,12 +29,18 @@ class DocumentFieldLink extends KTEntity { | ||
| 29 | /** document field link primary key */ | 29 | /** document field link primary key */ |
| 30 | var $iId; | 30 | var $iId; |
| 31 | /** primary key of document to which field is linked */ | 31 | /** primary key of document to which field is linked */ |
| 32 | - var $iDocumentID; | 32 | + var $iDocumentId; |
| 33 | /** primary key of field to which document is linked */ | 33 | /** primary key of field to which document is linked */ |
| 34 | - var $iDocumentFieldID; | 34 | + var $iDocumentFieldId; |
| 35 | /** field value */ | 35 | /** field value */ |
| 36 | var $sValue; | 36 | var $sValue; |
| 37 | - | 37 | + |
| 38 | + var $_aFieldToSelect = array( | ||
| 39 | + 'iId' => 'id', | ||
| 40 | + 'iDocumentId' => 'document_id', | ||
| 41 | + 'iDocumentFieldId' => 'document_field_id', | ||
| 42 | + 'sValue' => 'value', | ||
| 43 | + ); | ||
| 38 | 44 | ||
| 39 | /** | 45 | /** |
| 40 | * Default constructor | 46 | * Default constructor |
| @@ -44,11 +50,11 @@ class DocumentFieldLink extends KTEntity { | @@ -44,11 +50,11 @@ class DocumentFieldLink extends KTEntity { | ||
| 44 | * @param Value of field | 50 | * @param Value of field |
| 45 | * | 51 | * |
| 46 | */ | 52 | */ |
| 47 | - function DocumentFieldLink($iNewDocumentID, $iNewDocumentFieldID, $sNewValue) { | 53 | + function DocumentFieldLink($iNewDocumentId = null, $iNewDocumentFieldId = null, $sNewValue = null) { |
| 48 | //object not create in database yet | 54 | //object not create in database yet |
| 49 | $this->iId = -1; | 55 | $this->iId = -1; |
| 50 | - $this->iDocumentID = $iNewDocumentID; | ||
| 51 | - $this->iDocumentFieldID = $iNewDocumentFieldID; | 56 | + $this->iDocumentId = $iNewDocumentId; |
| 57 | + $this->iDocumentFieldId = $iNewDocumentFieldId; | ||
| 52 | $this->sValue = $sNewValue; | 58 | $this->sValue = $sNewValue; |
| 53 | } | 59 | } |
| 54 | 60 | ||
| @@ -58,7 +64,7 @@ class DocumentFieldLink extends KTEntity { | @@ -58,7 +64,7 @@ class DocumentFieldLink extends KTEntity { | ||
| 58 | * @return int document field link primary key | 64 | * @return int document field link primary key |
| 59 | * | 65 | * |
| 60 | */ | 66 | */ |
| 61 | - function getID() { | 67 | + function getId() { |
| 62 | return $this->iId; | 68 | return $this->iId; |
| 63 | } | 69 | } |
| 64 | 70 | ||
| @@ -68,8 +74,8 @@ class DocumentFieldLink extends KTEntity { | @@ -68,8 +74,8 @@ class DocumentFieldLink extends KTEntity { | ||
| 68 | * @return int document primary key to which the field is linked | 74 | * @return int document primary key to which the field is linked |
| 69 | * | 75 | * |
| 70 | */ | 76 | */ |
| 71 | - function getDocumentID() { | ||
| 72 | - return $this->iDocumentID; | 77 | + function getDocumentId() { |
| 78 | + return $this->iDocumentId; | ||
| 73 | } | 79 | } |
| 74 | 80 | ||
| 75 | /** | 81 | /** |
| @@ -78,8 +84,8 @@ class DocumentFieldLink extends KTEntity { | @@ -78,8 +84,8 @@ class DocumentFieldLink extends KTEntity { | ||
| 78 | * @param Document primary key to which field is linked | 84 | * @param Document primary key to which field is linked |
| 79 | * | 85 | * |
| 80 | */ | 86 | */ |
| 81 | - function setDocumentID($iNewValue) { | ||
| 82 | - $this->iDocumentID = $iNewValue; | 87 | + function setDocumentId($iNewValue) { |
| 88 | + $this->iDocumentId = $iNewValue; | ||
| 83 | } | 89 | } |
| 84 | 90 | ||
| 85 | /** | 91 | /** |
| @@ -88,8 +94,8 @@ class DocumentFieldLink extends KTEntity { | @@ -88,8 +94,8 @@ class DocumentFieldLink extends KTEntity { | ||
| 88 | * @return int primary key of field to which the document is related | 94 | * @return int primary key of field to which the document is related |
| 89 | * | 95 | * |
| 90 | */ | 96 | */ |
| 91 | - function getDocumentFieldID() { | ||
| 92 | - return $this->iDocumentFieldID; | 97 | + function getDocumentFieldId() { |
| 98 | + return $this->iDocumentFieldId; | ||
| 93 | } | 99 | } |
| 94 | 100 | ||
| 95 | /** | 101 | /** |
| @@ -98,8 +104,8 @@ class DocumentFieldLink extends KTEntity { | @@ -98,8 +104,8 @@ class DocumentFieldLink extends KTEntity { | ||
| 98 | * @param New primary key of field to which document is related | 104 | * @param New primary key of field to which document is related |
| 99 | * | 105 | * |
| 100 | */ | 106 | */ |
| 101 | - function setDocumentFieldID($iNewVale) { | ||
| 102 | - $this->iDocumentFieldID = $iNewValue; | 107 | + function setDocumentFieldId($iNewVale) { |
| 108 | + $this->iDocumentFieldId = $iNewValue; | ||
| 103 | } | 109 | } |
| 104 | 110 | ||
| 105 | /** | 111 | /** |
| @@ -122,14 +128,6 @@ class DocumentFieldLink extends KTEntity { | @@ -122,14 +128,6 @@ class DocumentFieldLink extends KTEntity { | ||
| 122 | $this->sValue = $sNewValue; | 128 | $this->sValue = $sNewValue; |
| 123 | } | 129 | } |
| 124 | 130 | ||
| 125 | - function _fieldValues () { | ||
| 126 | - return array( | ||
| 127 | - 'document_id' => $this->iDocumentID, | ||
| 128 | - 'document_field_id' => $this->iDocumentFieldID, | ||
| 129 | - 'value' => $this->sValue, | ||
| 130 | - ); | ||
| 131 | - } | ||
| 132 | - | ||
| 133 | function _table () { | 131 | function _table () { |
| 134 | global $default; | 132 | global $default; |
| 135 | return $default->document_fields_link_table; | 133 | return $default->document_fields_link_table; |
| @@ -143,16 +141,16 @@ class DocumentFieldLink extends KTEntity { | @@ -143,16 +141,16 @@ class DocumentFieldLink extends KTEntity { | ||
| 143 | * | 141 | * |
| 144 | * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"] | 142 | * @return DocumentFieldLink populated DocumentFieldLink object on success, false otherwise and set $_SESSION["errorMessage"] |
| 145 | */ | 143 | */ |
| 146 | - function & get($iDocumentFieldLinkID) { | 144 | + function & get($iDocumentFieldLinkId) { |
| 147 | global $default, $lang_err_doc_not_exist; | 145 | global $default, $lang_err_doc_not_exist; |
| 148 | $sql = $default->db; | 146 | $sql = $default->db; |
| 149 | - $sql->query(array("SELECT * FROM " . $default->document_fields_link_table . " WHERE id = ?", $iDocumentFieldLinkID));/*ok*/ | 147 | + $sql->query(array("SELECT * FROM " . $default->document_fields_link_table . " WHERE id = ?", $iDocumentFieldLinkId));/*ok*/ |
| 150 | if ($sql->next_record()) { | 148 | if ($sql->next_record()) { |
| 151 | $oDocumentFieldLink = & new DocumentFieldLink($sql->f("document_id"), $sql->f("document_field_id"), $sql->f("value")); | 149 | $oDocumentFieldLink = & new DocumentFieldLink($sql->f("document_id"), $sql->f("document_field_id"), $sql->f("value")); |
| 152 | - $oDocumentFieldLink->iId = $iDocumentFieldLinkID; | 150 | + $oDocumentFieldLink->iId = $iDocumentFieldLinkId; |
| 153 | return $oDocumentFieldLink; | 151 | return $oDocumentFieldLink; |
| 154 | } | 152 | } |
| 155 | - $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentID . " table = $default->document_fields_link_table"; | 153 | + $_SESSION["errorMessage"] = $lang_err_object_not_exist . "id = " . $iDocumentId . " table = $default->document_fields_link_table"; |
| 156 | return false; | 154 | return false; |
| 157 | } | 155 | } |
| 158 | 156 | ||
| @@ -163,8 +161,15 @@ class DocumentFieldLink extends KTEntity { | @@ -163,8 +161,15 @@ class DocumentFieldLink extends KTEntity { | ||
| 163 | 161 | ||
| 164 | function &getByDocument($oDocument) { | 162 | function &getByDocument($oDocument) { |
| 165 | return KTEntityUtil::getByDict('DocumentFieldLink', array( | 163 | return KTEntityUtil::getByDict('DocumentFieldLink', array( |
| 166 | - 'document_id' => $oDocument->getID(), | 164 | + 'document_id' => $oDocument->getId(), |
| 167 | ), array('multi' => true)); | 165 | ), array('multi' => true)); |
| 168 | } | 166 | } |
| 167 | + | ||
| 168 | + function &getByDocumentAndField($oDocument, $oField) { | ||
| 169 | + return KTEntityUtil::getByDict('DocumentFieldLink', array( | ||
| 170 | + 'document_id' => KTUtil::getId($oDocument), | ||
| 171 | + 'document_field_id' => KTUtil::getId($oDocument), | ||
| 172 | + )); | ||
| 173 | + } | ||
| 169 | } | 174 | } |
| 170 | ?> | 175 | ?> |