0) { $cond = " AND $cond"; } $sql = sprintf("SELECT TOP 1 [FirstName] AS firstName, [LastName] AS lastName, [DisplayName] AS displayName, [UserDefined1] AS freeOne, [ActualAddressID] AS addressId, [Email] AS mail, [TelephoneMobile] AS mobilePhone, [TelephonePrivate] AS privatePhone, [Telephone] AS officePhone, [%s] AS id, REPLACE(UseraccountNr, ' ', '') AS login FROM [%s] AS u LEFT JOIN [%s] AS a ON a.[%s] = u.[ActualAddressID] WHERE REPLACE(UseraccountNr, ' ', '') = '%s' AND disabled = 1 %s;", self::$idColumn, self::$tableName, self::$addressTableName, self::$addressIdColumn, $login, $cond); $results = Connection::execute($sql, $raiseError); return $results->current() !== false ? new User($results->current()) : null; } public function __toString() { return $this->displayName; } /** * Update the database. Note that new user insertion don't work in this implementation. */ public function save() { $strSQL = "UPDATE " . User::$tableName . " SET FirstName = '$this->sql_firstName', LastName = '$this->sql_lastName', "; $strSQL .= "DisplayName = '$this->sql_displayName'"; $strSQL .= "WHERE Replace(UseraccountNr, ' ', '') = '$this->sql_login'"; Connection::execute($strSQL, true); $strSQL = "UPDATE " . User::$addressTableName . " SET Email = '$this->sql_mail', TelephoneMobile = '$this->sql_mobilePhone', "; $strSQL .= "Telephone = '$this->sql_officePhone', TelephonePrivate = '$this->sql_privatePhone' "; $strSQL .= "WHERE " . User::$addressTableName . "." . User::$addressIdColumn . " = $this->sql_addressId"; Connection::execute($strSQL, true); if ($this->password) { $strSQL = "UPDATE " . User::$tableName . " SET Password = UPPER('$this->sql_password') "; $strSQL .= "WHERE Replace(UseraccountNr, ' ', '') = '$this->sql_login'"; Connection::execute($strSQL, true); } } public function reload() { $this->setAttributes(User::find($this->login)->toArray()); } public function getCirculations() { if (!$this->circulations) { $strSQL = "SELECT NoticeId, CheckOutDate, ItemNr FROM Circulations, Items " . "WHERE Circulations.UseraccountId = $this->id and Items.ItemId=Circulations.ItemId " . "ORDER BY ItemNr asc"; $result = Connection::execute($strSQL); $ids = array(); $checkOutDates = array(); $itemNrs = array(); while ($row = $result->next()) { $ids[] = $row['NoticeId']; $checkOutDates[] = $row['CheckOutDate']; $itemNrs[] = $row['ItemNr']; } $this->circulations = AudioBook::find($ids); // ici je remplace le champs date du livre par la date du prêt $counter = 0; foreach ($this->circulations as &$circulation) { $circulation->date = substr($checkOutDates[$counter], 0, 10); $circulation->itemNr = $itemNrs[$counter]; $counter++; } } return $this->circulations; } public function getOldCirculations() { //if(!$this->oldCirculations){ $strSQL = "SELECT NoticeId, CheckOutDate FROM OldCirculations, Items " . "WHERE OldCirculations.UseraccountId = $this->id and Items.ItemId=OldCirculations.ItemId " . "ORDER BY CheckOutDate desc"; $result = Connection::execute($strSQL); $ids = array(); $checkOutDates = array(); while ($row = $result->next()) { $ids[] = $row['NoticeId']; $checkOutDates[] = $row['CheckOutDate']; } $this->oldCirculations = AudioBook::find($ids); // ici je remplace le champs date du livre par la date du prêt $counter = 0; foreach ($this->oldCirculations as &$circulation) { $circulation->date = substr($checkOutDates[$counter], 0, 10); $counter++; } //} return $this->oldCirculations; } /** * Add a book to the wish list if it is not already inside. * * delete the wishes cache for it to be reloaded the next time getWishes will be called. * @param int $noticeId * @return bool */ public function addWish($noticeId) { $noticeId = str_replace("'", "''", $noticeId); if (!$this->hasWish($noticeId)) { // recover last id $idSQL = "SELECT WishID from Counters"; $idResult = Connection::execute($idSQL, true); // return print_r($idResult, 1); if ($row = $idResult->next()) { // get new value $newWishID = $row['WishID'] + 1; // update counter $idSQL = "UPDATE Counters SET WishID=" . $newWishID; Connection::execute($idSQL, true); $table = User::$wishTableName; $employee_id = Configuration::get('www_employee_id'); $library_id = Configuration::get('www_library_id'); $strSQL = "INSERT INTO $table (WishID, " . AudioBook::$idColumn . ", " . User::$idColumn . ", CreationDate, EmployeeID, BranchOfficeID, Remark, ModificationDate)"; $strSQL .= " VALUES($newWishID, $noticeId, $this->id, GETDATE(), $employee_id, $library_id, '', GETDATE())"; // return $strSQL; Connection::execute($strSQL); // $this->wishes = NULL; return true; } else { return false; } } return false; } /** * Return true if the book is in the wish list * @param int $noticeId * @return bool */ public function hasWish($noticeId) { foreach ($this->getWishes() as $book) { if ($book->id == $noticeId) { return true; } } return false; } /** * Wishes are all the books that this user want to read. * @param int $limit * @return AudioBook[] */ public function getWishes($limit = 50) { if (!$this->wishes) { $strSQL = "SELECT TOP " . $limit . AudioBook::$idColumn . " FROM " . User::$wishTableName . " WHERE " . User::$idColumn . " = $this->id ORDER BY CreationDate desc"; $result = Connection::execute($strSQL); $ids = array(); while ($row = $result->next()) { $ids[] = $row['NoticeID']; } $this->wishes = AudioBook::find($ids); } return $this->wishes; } /** * Remove a book from the wish list * @param int $noticeId */ public function deleteWish($noticeId) { $noticeId = str_replace("'", "''", $noticeId); $table = User::$wishTableName; $strSQL = "DELETE FROM $table"; $strSQL .= " WHERE " . AudioBook::$idColumn . " = $noticeId AND " . User::$idColumn . " = $this->id;"; Connection::execute($strSQL, true); } }