/** * Returns array of SQL WHERE conditions based on given criteria. * * @param WiseChatMessagesCriteria $criteria * * @return array */ private function getSQLConditionsByCriteria($criteria) { $conditions = array(); if ($criteria->getChannelName() !== null) { $channelName = addslashes($criteria->getChannelName()); $conditions[] = "channel = '{$channelName}'"; } if ($criteria->getUserId() !== null) { $conditions[] = "chat_user_id = " . intval($criteria->getUserId()); } if ($criteria->getOffsetId() !== null) { $conditions[] = "id > " . intval($criteria->getOffsetId()); } if (!$criteria->isIncludeAdminMessages()) { $conditions[] = "admin = 0"; } if ($criteria->getMaximumTime() !== null) { $conditions[] = "time < " . intval($criteria->getMaximumTime()); } if ($criteria->getMinimumTime() !== null) { $conditions[] = "time >= " . intval($criteria->getMinimumTime()); } if ($criteria->getIp() !== null) { $ip = addslashes($criteria->getIp()); $conditions[] = "ip = '{$ip}'"; } if (count($conditions) == 0) { $conditions[] = '1 = 1'; } return $conditions; }