function getByCompanyIdAndRecipientId($company_id, $id, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } if ($id == '') { return FALSE; } $mrf = new MessageRecipientFactory(); $uf = new UserFactory(); $ph = array('company_id' => $company_id); //Ignore deleted message_sender rows, as the sender could have deleted the original message. $query = ' SELECT a.* FROM ' . $this->getTable() . ' as a LEFT JOIN ' . $mrf->getTable() . ' as b ON a.id = b.message_sender_id LEFT JOIN ' . $uf->getTable() . ' as c ON a.user_id = c.id WHERE c.company_id = ? AND b.id in (' . $this->getListSQL($id, $ph) . ') AND ( b.deleted = 0 ) '; $this->ExecuteSQL($query, $ph); return $this; }
function getAPIMessageByCompanyIdAndArrayCriteria($company_id, $filter_data, $limit = NULL, $page = NULL, $where = NULL, $order = NULL) { if ($company_id == '') { return FALSE; } if (!is_array($order)) { //Use Filter Data ordering if its set. if (isset($filter_data['sort_column']) and $filter_data['sort_order']) { $order = array(Misc::trimSortPrefix($filter_data['sort_column']) => $filter_data['sort_order']); } } $additional_order_fields = array('from_last_name', 'to_last_name', 'subject', 'object_type_id'); $strict = TRUE; if ($order == NULL) { $strict = FALSE; $order = array('a.created_date' => 'asc'); } $mrf = new MessageRecipientFactory(); $msf = new MessageSenderFactory(); $rf = new RequestFactory(); $uf = new UserFactory(); $udf = new UserDateFactory(); $pptsvf = new PayPeriodTimeSheetVerifyFactory(); $ph = array('company_id' => $company_id, 'id' => $filter_data['id'], 'id_b' => $filter_data['id'], 'id_c' => $filter_data['id'], 'id_d' => $filter_data['id'], 'user_id' => $filter_data['current_user_id'], 'user_id_b' => $filter_data['current_user_id']); //Need to include all threads that user has posted to. $query = ' SELECT a.*, b.id as id, c.status_id as status_id, b.user_id as from_user_id, bb.first_name as from_first_name, bb.middle_name as from_middle_name, bb.last_name as from_last_name, c.user_id as to_user_id, cb.first_name as to_first_name, cb.middle_name as to_middle_name, cb.last_name as to_last_name FROM ' . $this->getTable() . ' as a LEFT JOIN ' . $msf->getTable() . ' as b ON a.id = b.message_control_id LEFT JOIN ' . $uf->getTable() . ' as bb ON b.user_id = bb.id LEFT JOIN ' . $mrf->getTable() . ' as c ON b.id = c.message_sender_id LEFT JOIN ' . $uf->getTable() . ' as cb ON c.user_id = cb.id WHERE cb.company_id = ? AND cb.company_id = bb.company_id AND ( b.id = ? OR b.id = ( select parent_id from ' . $msf->getTable() . ' where id = ? AND parent_id != 0 ) OR b.parent_id = ( select parent_id from ' . $msf->getTable() . ' where id = ? AND parent_id != 0 ) OR ( b.parent_id = ? ) ) AND ( b.user_id = ? OR c.user_id = ? ) AND ( a.deleted = 0 AND c.deleted = 0 ) '; $query .= $this->getWhereSQL($where); $query .= $this->getSortSQL($order, $strict, array('from_last_name', 'to_last_name')); $this->ExecuteSQL($query, $ph, $limit, $page); return $this; }