/** * get id by email * @param string $email * @return null|int id */ public function getIdByEmail($email) { //sql check $email = $this->connection->getEscapedString($email); //get id and return return $this->operations->getValue("id", "email = '{$email}'"); }
/** * Stores a given notification in the provided db * * @param ClientNotification $notification A notification to be store in the specified db * @return int the id of notification inserted * @throws DatabaseException If an error occured in the storing of the notification in the db */ public function store(ClientNotification $notification) { //String conversion and escaping in order to perform a correct and safe sql query $user_id = $notification->getUserId(); $message = $this->dbConnection->getEscapedString((string) $notification->getMessage()); $mediums = $notification->getNotificationMediums(); try { //Notification insert $this->dbOperations->insert('user_id,message', $user_id . ",'" . $message . "'"); //Id of the record just inserted $recordId = $this->dbOperations->getLastId(); if (is_array($mediums)) { foreach ($mediums as $medium) { //TODO this code doesn't work, use the code in the 'else' branch. Since the code will become the same it's a better choice to insert it into a method $this->dbOperations->insert('notification_id,type_id', $recordId . ", '" . get_class($medium) . "'", $this->notificationTypeTable); } } else { $className = get_class($mediums); $queryResult = $this->dbOperations->getValue('id', 'name = ' . "'" . $className . "'", $this->typesTable); if (is_null($queryResult)) { $this->dbOperations->insert('name', "'" . $className . "'", $this->typesTable); $queryResult = $this->dbOperations->getLastId(); } $this->dbOperations->insert('notification_id,type_id', $recordId . ", " . $queryResult, $this->notificationTypeTable); } return $recordId; } catch (MysqltcsException $e) { throw new DatabaseException('An error occurred in the insertion of the data in the database', 0, $e); } }