My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
class BooksController extends AppController {

var $name = 'Books';
var $helpers = array('Html', 'Form','Chief','Javascript');

/**
* index
*/
function index() {
$this->Book->recursive =2;
$this->set('books', $this->paginate());
}

/**
* view
*
* @param int $id Id of the Book
*/
function view($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid Book.', true));
$this->redirect(array('action'=>'index'));
}
$this->set('book', $this->Book->read(null, $id));
}

/**
* add
*/
function add() {

if (!empty($this->data)) {
$this->Book->create();
$this->Book->trace($this->Auth->user('id'));
$this->Book->PublishPlace->create();
$this->Book->PublishPlace->trace($this->Auth->user('id'));
$this->Book->MaterialType->create();
$this->Book->MaterialType->trace($this->Auth->user('id'));

if ($this->Book->save($this->data)) {
$this->Session->setFlash(__('The Book has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Book could not be saved. Please, try again.', true));
}
}
$authors = $this->Book->Author->find('list');
$disciplines = $this->Book->Discipline->find('list');
$languages = $this->Book->Language->find('list');
$subjectHeadings = $this->Book->SubjectHeading->find('list');
$publishers = $this->Book->Publisher->find('list');
$publishPlaces = $this->Book->PublishPlace->find('list');
$sections = $this->Book->Section->find('list');
$materialTypes = $this->Book->MaterialType->find('list');
$editions = $this->Book->Edition->find('list');
$encoders = $this->Book->Encoder->find('list');
$editors = $this->Book->Editor->find('list');
$this->set(compact('authors', 'disciplines', 'languages', 'subjectHeadings', 'publishers', 'publishPlaces', 'sections', 'materialTypes', 'editions', 'encoders', 'editors'));
}

/**
* edit
*
* @param int $id Id of the Book
*/
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->Session->setFlash(__('Invalid Book', true));
$this->redirect(array('action'=>'index'));
}
if (!empty($this->data)) {
$this->Book->trace($this->Auth->user('id'));
if ($this->Book->save($this->data)) {
$this->Session->setFlash(__('The Book has been saved', true));
$this->redirect(array('action'=>'index'));
} else {
$this->Session->setFlash(__('The Book could not be saved. Please, try again.', true));
}
}
if (empty($this->data)) {
$this->data = $this->Book->read(null, $id);
}
$authors = $this->Book->Author->find('list');
$disciplines = $this->Book->Discipline->find('list');
$languages = $this->Book->Language->find('list');
$subjectHeadings = $this->Book->SubjectHeading->find('list');
$publishers = $this->Book->Publisher->find('list');
$publishPlaces = $this->Book->PublishPlace->find('list');
$sections = $this->Book->Section->find('list');
$materialTypes = $this->Book->MaterialType->find('list');
$editions = $this->Book->Edition->find('list');
$encoders = $this->Book->Encoder->find('list');
$editors = $this->Book->Editor->find('list');
$this->set(compact('authors','disciplines','languages','subjectHeadings','publishers','publishPlaces','sections','materialTypes','editions','encoders','editors'));
}

/**
* delete
*
* @param int $id Id of the Book
*/
function delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Invalid id for Book', true));
$this->redirect(array('action'=>'index'));
}
if ($this->Book->del($id)) {
$this->Session->setFlash(__('Book deleted', true));
$this->redirect(array('action'=>'index'));
}
}

/**
* ajax_open_library_isbn
*/
function ajax_open_library_isbn() {
$this->layout = 'ajax';
$book = null;
$authors = null;

$isbn = $this->params['form']['isbn'];

$ol_images = array();
$lt_images = array();

$ol_sizes = array('S','M','L');
$lt_sizes = array('small','medium','large');

$ol_image_write_error = array();
$lt_image_write_error = array();
// try getting the image
foreach($ol_sizes as $ol_size){
$ol_string = 'http://covers.openlibrary.org/b/isbn/'.$isbn.'-'.$ol_size.'.jpg';
$ol_images[$ol_size] = file_get_contents($ol_string);
}

foreach($lt_sizes as $lt_size){
$devkey = 'eea965edcef313bb468597d22e120b56';
$lt_string = 'http://covers.librarything.com/devkey/'.$devkey.'/'.$lt_size.'/isbn/'.$isbn;
$lt_images[$lt_size] = file_get_contents($lt_string);
sleep(1); // As per Terms and Conditions, we need to fetch every second only.
}

if (!$ol_images['M']) {
$this->set('ol_img_read_error', 'No image available.');
} else {
// try writing the file with the original filename -- note that this will overwrite any existing filename in the same directory -- that's up to you to check for
foreach ($ol_sizes as $ol_size) {
$ol_filename = WWW_ROOT.'img/isbn/openlibrary/'.$isbn.'-'.$ol_size.'.jpg';
$ol_current_image = $ol_images[$ol_size];
if (!file_put_contents($ol_filename, $ol_current_image)) {
$ol_image_write_error[] = $ol_size;
}
}
}

$this->set('img_write_error',$ol_image_write_error);

if (!$lt_images['small']) {
$this->set('lt_img_read_error', 'No image available.');
} else {
// try writing the file with the original filename -- note that this will overwrite any existing filename in the same directory -- that's up to you to check for
foreach ($lt_sizes as $lt_size){
$lt_filename = WWW_ROOT.'img/isbn/librarything/'.$isbn.'-'.$lt_size.'.jpg';
$lt_current_image = $lt_images[$lt_size];
if (!file_put_contents($lt_filename, $lt_current_image)) {
$lt_image_write_error[] = $lt_size;
}
}
}
$this->set('img_write_error',$ol_image_write_error);

if ($this->OpenLibrary->isbn($isbn)) {
foreach($this->OpenLibrary->isbn($isbn) as $key) {
$key_request = $this->OpenLibrary->key($key);
$output = print_r($key_request, true).">>\n";
foreach($key_request['authors'] as $_author){
$author = $this->OpenLibrary->author($_author['key']);
$authors[] = $author['name'];
}
}
$book = $key_request;
} else {
$output = 'No results found.';
}
$this->set(compact('output','book','authors'));
}
}
?>

Change log

r242 by sonnygauran on Mar 19, 2009   Diff
// Merged changes from
/branches/sonny/Release-0.6@239 to
/chieftain to /trunk/chieftain
Go to: 
Sign in to write a code review

Older revisions

r234 by reonmercado on Mar 2, 2009   Diff
// Merged from /branches/sonny/Release
-0.6/chieftain@232 to
/branches/reon/Release-0.6/chieftain
r228 by sonnygauran on Feb 28, 2009   Diff
// Merged from
/branches/sonny/Release-0.6@227 to
/trunk/
r213 by sonnygauran on Feb 8, 2009   Diff
// Merged changes from /branches/sonny
/Release-0.6/chieftain@212 to
/trunk/chieftain
All revisions of this file

File info

Size: 7005 bytes, 190 lines

File properties

svn:eol-style
native
svn:keywords
Date Author Rev URL Id
Powered by Google Project Hosting