paristemi
[ class tree: paristemi ] [ index: paristemi ] [ all elements ]

Source for file db_library.php

Documentation is available at db_library.php

  1. <?php
  2. /**
  3. * <b>Database Class : Library</b><br />
  4. * Provides all database access methods for the library section.
  5. * @author Kristen O'Brien <kristen_paristemi-com>
  6. * @copyright Copyright 2004, Kristen O'Brien
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. * @link http://www.paristemi.com Paristemi Main Site
  9. * @package paristemi
  10. * @subpackage paristemi_database_layer
  11. * @since Build 0.5
  12. * @version Build 0.7
  13. * @filesource
  14. */
  15. /**
  16. * <b>Database Class : Library</b><br />
  17. * Provides all database access methods for the library section.
  18. * @author Kristen O'Brien <kristen_paristemi-com>
  19. * @copyright Copyright 2004, Kristen O'Brien
  20. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  21. * @link http://www.paristemi.com Paristemi Main Site
  22. * @package paristemi
  23. * @subpackage paristemi_database_layer
  24. * @since Build 0.5
  25. * @version Build 0.7
  26. * @filesource
  27. */
  28. class DB_Library {
  29. var $grouping = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N',
  30. 'O','P','Q','R','S','T','U','V','W','X','Y','Z');
  31. function DB_Library() { }
  32. function &GetCategoriesUsed() {
  33. $topics = Array();
  34. $result = mysql_query("SELECT DISTINCT Category
  35. FROM Library
  36. ORDER BY Category");
  37. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  38. $topics[] = $row['Category'];
  39. }
  40. return $topics;
  41. }
  42. function &GetKeywordsUsed() {
  43. $topics = Array();
  44. $result = mysql_query("SELECT DISTINCT Keywords FROM Library");
  45. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  46. $topics[] = $row['Keywords'];
  47. }
  48. return $topics;
  49. }
  50. function &GroupFunct($item) {
  51. $flag = 0;
  52. foreach($this->grouping as $letter) {
  53. if($item{0} == $letter) { $flag = 1; }
  54. }
  55. return $flag;
  56. }
  57. function &GetKeywordsUsedByGroup($group) {
  58. $this->grouping = $group;
  59. $topics = Array();
  60. $result = mysql_query("SELECT DISTINCT Keywords FROM Library");
  61. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  62. $tok = strtok($row['Keywords'],",");
  63. while ($tok) {
  64. $topics[] = trim($tok);
  65. $tok = strtok(",");
  66. }
  67. }
  68. $unique_topics = array_values(array_unique($topics));
  69. $new_arr = array_filter($unique_topics,array($this,"GroupFunct"));
  70. sort($new_arr);
  71. return $new_arr;
  72. }
  73. //Pass it the ID.
  74. //There must be an ID associated with all of the elements.
  75. function &GetLibraryData(&$id) {
  76. $result = mysql_query("select L.ID, L.Title, L.Author, L.Editor, L.CatalogNumber, L.ISBN,
  77. L.Pages, L.Copies, L.Description, L.Format, L.Category,
  78. L.Keywords, L.Year, L.Publisher, L.Series, L.Notes,
  79. L.CopiesOut, L.DatesOut, L.DatesDue, L.PersonsOut,
  80. L.PersonsEmailOut, L.PersonsPhoneOut, L.NumWaiting,
  81. L.PersonsWaiting, L.PersonsEmailWaiting, L.PersonsPhoneWaiting
  82. from Library L
  83. where L.ID = $id
  84. limit 1");
  85. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  86.  
  87. $data = new LibraryItemDetailed($row['ID'], $row['Title'],$row['Author'],
  88. $row['Editor'], $row['CatalogNumber'], $row['ISBN'], $row['Pages'],
  89. $row['Copies'],$row['Description'],$row['Format'],
  90. $row['Category'],$row['Keywords'], $row['Year'], $row['Publisher'],
  91. $row['Series'], $row['Notes'], $row['CopiesOut'], $row['DatesOut'],
  92. $row['DatesDue'], $row['PersonsOut'], $row['PersonsEmailOut'],
  93. $row['PersonsPhoneOut'], $row['NumWaiting'], $row['PersonsWaiting'],
  94. $row['PersonsEmailWaiting'], $row['PersonsPhoneWaiting']);
  95. return $data;
  96. }
  97. //Pass it the ID.
  98. //There must be an ID associated with all of the elements.
  99. function &GetAllLibraryData() {
  100. $data = Array();
  101. $result = mysql_query("select L.ID, L.Title, L.Author, L.Editor, L.CatalogNumber, L.ISBN,
  102. L.Pages, L.Copies, L.Description, L.Format, L.Category,
  103. L.Keywords, L.Year, L.Publisher, L.Series, L.Notes,
  104. L.CopiesOut, L.DatesOut, L.DatesDue, L.PersonsOut,
  105. L.PersonsEmailOut, L.PersonsPhoneOut, L.NumWaiting,
  106. L.PersonsWaiting, L.PersonsEmailWaiting, L.PersonsPhoneWaiting
  107. from Library L");
  108.  
  109. //Process each row.
  110. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  111. $data[] = new LibraryItemDetailed($row['ID'], $row['Title'],$row['Author'],
  112. $row['Editor'], $row['CatalogNumber'], $row['ISBN'], $row['Pages'],
  113. $row['Copies'],$row['Description'],$row['Format'],
  114. $row['Category'],$row['Keywords'], $row['Year'], $row['Publisher'],
  115. $row['Series'], $row['Notes'], $row['CopiesOut'], $row['DatesOut'],
  116. $row['DatesDue'], $row['PersonsOut'], $row['PersonsEmailOut'],
  117. $row['PersonsPhoneOut'], $row['NumWaiting'], $row['PersonsWaiting'],
  118. $row['PersonsEmailWaiting'], $row['PersonsPhoneWaiting']);
  119. }
  120. return $data;
  121. }
  122. //Pass it the ID.
  123. //There must be an ID associated with all of the elements.
  124. function &GetAllLibraryDataByLimit($limit,$blimit) {
  125. $data = Array();
  126. $result = mysql_query("select L.ID, L.Title, L.Author, L.Editor, L.CatalogNumber, L.ISBN,
  127. L.Pages, L.Copies, L.Description, L.Format, L.Category,
  128. L.Keywords, L.Year, L.Publisher, L.Series, L.Notes,
  129. L.CopiesOut, L.DatesOut, L.DatesDue, L.PersonsOut,
  130. L.PersonsEmailOut, L.PersonsPhoneOut, L.NumWaiting,
  131. L.PersonsWaiting, L.PersonsEmailWaiting, L.PersonsPhoneWaiting
  132. from Library L
  133. limit $blimit,$limit");
  134.  
  135. //Process each row.
  136. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  137. $data[] = new LibraryItemDetailed($row['ID'], $row['Title'],$row['Author'],
  138. $row['Editor'], $row['CatalogNumber'], $row['ISBN'], $row['Pages'],
  139. $row['Copies'],$row['Description'],$row['Format'],
  140. $row['Category'],$row['Keywords'], $row['Year'], $row['Publisher'],
  141. $row['Series'], $row['Notes'], $row['CopiesOut'], $row['DatesOut'],
  142. $row['DatesDue'], $row['PersonsOut'], $row['PersonsEmailOut'],
  143. $row['PersonsPhoneOut'], $row['NumWaiting'], $row['PersonsWaiting'],
  144. $row['PersonsEmailWaiting'], $row['PersonsPhoneWaiting']);
  145. }
  146. return $data;
  147. }
  148. //There must be an ID associated with all of the elements.
  149. function &SearchLibrary(&$item,$atype,$limit,$blimit) {
  150. $data = Array();
  151. $query_string = "select L.ID, L.Title, L.Author, L.Editor, L.CatalogNumber,
  152. L.ISBN, L.Description, L.Format, L.Category,
  153. L.Keywords, L.Publisher, L.Series
  154. from Library L
  155. where (";
  156. foreach($atype as $type) {
  157. switch($type) {
  158. case "title" : $query_string .= "(L.Title LIKE '%$item%' OR
  159. L.Series LIKE '%$item%') OR "; break;
  160. case "author" : $query_string .= "(L.Author LIKE '%$item%' OR
  161. L.Editor LIKE '%$item%' OR
  162. L.Publisher LIKE '%$item%') OR "; break;
  163. case "catnum" : $query_string .= "L.CatalogNumber = '$item' OR "; break;
  164. case "isbn" : $query_string .= "L.ISBN = '$item' OR "; break;
  165. case "format" : $query_string .= "L.Format LIKE '%$item%' OR "; break;
  166. case "category" : $query_string .= "L.Category LIKE '%$item%' OR "; break;
  167. case "keywords" : $query_string .= "L.Keywords LIKE '%$item%' OR "; break;
  168. default : die("Invalid Parameters"); break;
  169. }
  170. }
  171. if(count($atype) == 0) { die("Invalid Parameters"); }
  172. $query_string = substr($query_string,0,strlen($query_string)-4);
  173. $query_string = $query_string . ") order by L.Title asc, L.CatalogNumber asc,
  174. L.Author asc
  175. limit $blimit,$limit";
  176. $result = mysql_query($query_string);
  177.  
  178. //Process each row.
  179. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  180. $data[] = new LibraryItemSimple($row['ID'], $row['Title'], $row['Author'],
  181. $row['Editor'], $row['CatalogNumber'], $row['ISBN'],
  182. $row['Description'], $row['Format'], $row['Category'],
  183. $row['Keywords'], $row['Publisher'], $row['Series']);
  184. }
  185.  
  186. return $data;
  187. }
  188. //There must be an ID associated with all of the elements.
  189. function &SearchLibraryCount(&$item,$atype) {
  190. $data = Array();
  191. $query_string = "SELECT COUNT(*)
  192. from Library L
  193. where (";
  194. foreach($atype as $type) {
  195. switch($type) {
  196. case "title" : $query_string .= "(L.Title LIKE '%$item%' OR
  197. L.Series LIKE '%$item%') OR "; break;
  198. case "author" : $query_string .= "(L.Author LIKE '%$item%' OR
  199. L.Editor LIKE '%$item%' OR
  200. L.Publisher LIKE '%$item%') OR "; break;
  201. case "catnum" : $query_string .= "L.CatalogNumber = '$item' OR "; break;
  202. case "isbn" : $query_string .= "L.ISBN = '$item' OR "; break;
  203. case "format" : $query_string .= "L.Format LIKE '%$item%' OR "; break;
  204. case "category" : $query_string .= "L.Category LIKE '%$item%' OR "; break;
  205. case "keywords" : $query_string .= "L.Keywords LIKE '%$item%' OR "; break;
  206. default : $this->Error("Invalid Parameters"); break;
  207. }
  208. }
  209. if(count($atype) == 0) { $this->Error("Invalid Parameters"); }
  210. $query_string = substr($query_string,0,strlen($query_string)-4);
  211. $query_string = $query_string . ")";
  212. $result = mysql_query($query_string);
  213. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  214. foreach($row as $item) { $count = $item; }
  215. return $count;
  216. }
  217. //There must be an ID associated with all of the elements.
  218. function &GetLibraryCategoryItems(&$cat,$limit,$blimit) {
  219. $data = Array();
  220. $query_string = "select L.ID, L.Title, L.Author, L.Editor, L.CatalogNumber,
  221. L.ISBN, L.Description, L.Format, L.Category,
  222. L.Keywords, L.Publisher, L.Series
  223. from Library L
  224. where L.Category LIKE '%$cat%'
  225. order by L.Title
  226. limit $blimit,$limit";
  227. $result = mysql_query($query_string);
  228.  
  229. //Process each row.
  230. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  231. $data[] = new LibraryItemSimple($row['ID'], $row['Title'], $row['Author'],
  232. $row['Editor'], $row['CatalogNumber'], $row['ISBN'],
  233. $row['Description'], $row['Format'], $row['Category'],
  234. $row['Keywords'], $row['Publisher'], $row['Series']);
  235. }
  236.  
  237. return $data;
  238. }
  239. function &GetLibraryCategoryCount(&$cat) {
  240. $data = Array();
  241. $query_string = "SELECT COUNT(*)
  242. from Library L
  243. where L.Category LIKE '%$cat%'";
  244. $result = mysql_query($query_string);
  245. $row = mysql_fetch_array($result, MYSQL_ASSOC);
  246. foreach($row as $item) { $count = $item; }
  247. return $count;
  248. }
  249. }
  250.  
  251. /**
  252. * <b>Database Container Class - Library Item Detailed</b><br />
  253. * Contains all of the specific data for a library item.
  254. * @author Kristen O'Brien <kristen_paristemi-com>
  255. * @copyright Copyright 2004, Kristen O'Brien
  256. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  257. * @link http://www.paristemi.com Paristemi Main Site
  258. * @package paristemi
  259. * @subpackage paristemi_database_layer
  260. * @since Build 0.5
  261. * @version Build 0.7
  262. * @filesource
  263. */
  264. class LibraryItemDetailed {
  265. var $ID;
  266. var $Title;
  267. var $Author;
  268. var $Editor;
  269. var $CatalogNumber;
  270. var $ISBN;
  271. var $Pages;
  272. var $Copies;
  273. var $Description;
  274. var $Format;
  275. var $Category;
  276. var $Keywords;
  277. var $Year;
  278. var $Publisher;
  279. var $Series;
  280. var $Notes;
  281. var $CopiesOut;
  282. var $DatesOut;
  283. var $DatesDue;
  284. var $PersonsOut;
  285. var $PersonsEmailOut;
  286. var $PersonsPhoneOut;
  287. var $NumWaiting;
  288. var $PersonsWaiting;
  289. var $PersonsEmailWaiting;
  290. var $PersonsPhoneWaiting;
  291. function LibraryItemDetailed($id, $title, $author, $editor, $catnum, $isbn, $pages, $copies,
  292. $desc, $format, $category, $keywords, $year, $publisher,
  293. $series, $notes, $copiesout, $datesout, $datesdue,
  294. $personsout, $personsemailout, $personsphoneout,
  295. $numwaiting, $personswaiting, $personsemailwaiting, $personsphonewaiting) {
  296. $this->ID = $id;
  297. $this->Title = $title;
  298. $this->Author = $author;
  299. $this->Editor = $editor;
  300. $this->CatalogNumber = $catnum;
  301. $this->ISBN = $isbn;
  302. $this->Pages = $pages;
  303. $this->Copies = $copies;
  304. $this->Description = $desc;
  305. $this->Format = $format;
  306. $this->Category = $category;
  307. $this->Keywords = $keywords;
  308. $this->Year = $year;
  309. $this->Publisher = $publisher;
  310. $this->Series = $series;
  311. $this->Notes = $notes;
  312. $this->CopiesOut = $copiesout;
  313. $this->DatesOut = $datesout;
  314. $this->DatesDue = $datesdue;
  315. $this->PersonsOut = $personsout;
  316. $this->PersonsEmailOut = $personsemailout;
  317. $this->PersonsPhoneOut = $personsphoneout;
  318. $this->NumWaiting = $numwaiting;
  319. $this->PersonsWaiting = $personswaiting;
  320. $this->PersonsEmailWaiting = $personsemailwaiting;
  321. $this->PersonsPhoneWaiting = $personsphonewaiting;
  322. }
  323. }
  324.  
  325. /**
  326. * <b>Database Container Class : Library Item Simple</b><br />
  327. * Contains all of the important data for a library item.
  328. * @author Kristen O'Brien <kristen_paristemi-com>
  329. * @copyright Copyright 2004, Kristen O'Brien
  330. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  331. * @link http://www.paristemi.com Paristemi Main Site
  332. * @package paristemi
  333. * @subpackage paristemi_database_layer
  334. * @since Build 0.5
  335. * @version Build 0.7
  336. * @filesource
  337. */
  338. class LibraryItemSimple {
  339. var $ID;
  340. var $Title;
  341. var $Author;
  342. var $Editor;
  343. var $CatalogNumber;
  344. var $ISBN;
  345. var $Description;
  346. var $Format;
  347. var $Category;
  348. var $Keywords;
  349. var $Publisher;
  350. var $Series;
  351. function LibraryItemSimple($id, $title, $author, $editor, $catnum,
  352. $isbn, $desc, $format, $cat, $keywords,
  353. $publisher, $series) {
  354. $this->ID = $id;
  355. $this->Title = $title;
  356. $this->Author = $author;
  357. $this->Editor = $editor;
  358. $this->CatalogNumber = $catnum;
  359. $this->ISBN = $isbn;
  360. $this->Description = $desc;
  361. $this->Format = $format;
  362. $this->Category = $cat;
  363. $this->Keywords = $keywords;
  364. $this->Publisher = $publisher;
  365. $this->Series = $series;
  366. }
  367. }
  368.  
  369. ?>

Documentation generated on Mon, 10 May 2004 12:08:42 -0700 by phpDocumentor 1.3.0RC3