Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $parcelsTable = 'parcels_short';
- $personTable = 'personal_data';
- $contactTable = 'contact_data';
- $addressTable = 'address';
- $transporterTable = 'transporters';
- $personJoinCond = ' ( '.$parcelsTable.'.person_info = '.$personTable.'.person_id ) ';
- $contactJoinCond = ' ( '.$parcelsTable.'.contact = '.$contactTable.'.contact_id ) ';
- $addressJoinCond = ' ( '.$parcelsTable.'.address = '.$addressTable.'.address_id ) ';
- $transporterJoinCond = ' ( ' . $parcelsTable . '.transporter_code = ' . $transporterTable . '.code )';
- $personJoin = ' JOIN '.$personTable.' ON '.$personJoinCond;
- $contactJoin = ' JOIN '.$contactTable.' ON '.$contactJoinCond;
- $addressJoin = ' JOIN '.$addressTable.' ON '.$addressJoinCond;
- $transporterJoin = ' JOIN ' . $transporterTable . ' ON ' . $transporterJoinCond;
- $query = 'SELECT * FROM '.$parcelsTable.$personJoin.$contactJoin.$addressJoin.$transporterJoin;
- if ( $condition !== NULL ) {
- $date = new \DateTime();
- if( isset($condition['greater_date']) ) {
- $date->setDate(substr($condition['greater_date'], 8, 4), substr($condition['greater_date'], 4, 2), substr($condition['greater_date'], 0, 2));
- $condition['greater_date'] = $date->format('Y-m-d');
- }
- if( isset($condition['lower_date']) ) {
- $date->setDate(substr($condition['lower_date'], 8, 4), substr($condition['lower_date'], 4, 2), substr($condition['lower_date'], 0, 2));
- $condition['lower_date'] = $date->format('Y-m-d');
- }
- $conditionText = '';
- foreach ($condition as $key => $value) {
- if (substr($key, 0, 8) == 'greater_' ) {
- $conditionText .= ' '.substr($key, 8, strlen($key) - 8).' >= "'.$value.'" AND ';
- }
- elseif (substr($key, 0, 6) == 'lower_' ) {
- $conditionText .= ' '.substr($key, 6, strlen($key) - 6).' <= "'.$value.'" AND ';
- }
- else {
- $conditionText .= ' '.$key.' = "'.$value.'" AND ';
- }
- }
- $conditionText = substr($conditionText, 0, strlen($conditionText) - 5);
- $query .= 'WHERE '.$conditionText.' ';
- }
- $query .= 'ORDER BY '.$column;
- return $this->database->query($query);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement