Skip to content

Commit

Permalink
Merge branch 'master' of github.com:joni/Instabook
Browse files Browse the repository at this point in the history
  • Loading branch information
joni committed Apr 28, 2012
2 parents 9a94a2a + 10499f1 commit d70817f
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 38 deletions.
36 changes: 27 additions & 9 deletions yii-app/protected/models/Book.php
Expand Up @@ -20,33 +20,51 @@ class Book
public $title = null;
public $description = null;
public $image = null;
public $hash = null;
public $google_id = null;
public $vote = 0;
public $n_vote = 0;
public $category = null;
public $author = null;

public function save()
{
// ..
BooksParseService::getInstance()->save($this);
}

public function vote($vote = 1)
public function nVote()
{

$this->n_vote++;
$this->save();
}

public function __construct($hash = null)
public function vote()
{
if ($hash)
$this->vote++;
$this->save();
}

public function toArray()
{
$array = array();
foreach ($this as $key => $value)
{
$array[$key] = $value;
}
unset($array["createdAt"], $array["updatedAt"], $array["objectId"]);
return $array;
}

public function __construct($google_id = null)
{
if ($google_id)
{
$this->hash = (string) $hash;
if ($response = BooksParseService::getInstance()->get($this->hash))
$this->google_id = (string) $google_id;
if ($response = BooksParseService::getInstance()->get($this->google_id))
{
foreach ($response as $key => $value)
{
$this->$key = $value;
}
die(var_dump($this));
}
}
}
Expand Down
28 changes: 8 additions & 20 deletions yii-app/protected/models/BooksParseService.php
Expand Up @@ -39,7 +39,6 @@ final public static function getInstance()
{
self::$instances[$class] = new $class();
}

return self::$instances[$class];
}

Expand All @@ -57,19 +56,18 @@ public function search($query)

}

public function get($hash = null)
public function get($google_id = null)
{
$params = array(
'className' => 'Books',
'object' => array(),
'query' => array(
'hash' => $hash
'google_id' => $google_id
),
'limit' => 1,
);
);
$response = json_decode($this->parse->query($params));

if ($response->results)
if ($response && isset($response->results) && count($response->results))
{
return $response->results[0];
} else
Expand All @@ -81,31 +79,21 @@ public function get($hash = null)
public function save(Book $book)
{
if ($response = $this->get($book->google_id))
{
{
$params = array(
'className' => 'Books',
'objectId' => $response->objectId,
'object' => array(
'hash' => $book->google_id,
'link' => $book->link,
'title' => $book->title,
'description' => $book->description,
)
'object' => $book->toArray(),
);
$this->parse->update($params);
} else
{
$params = array(
'className' => 'Books',
'object' => array(
'hash' => $book->google_id,
'link' => $book->link,
'title' => $book->title,
'description' => $book->description,
)
'object' => $book->toArray(),
);
$this->parse->create($params);
}
}

}
}
11 changes: 8 additions & 3 deletions yii-app/protected/models/BooksService.php
Expand Up @@ -63,7 +63,9 @@ public function search($query)
if (isset($item->selfLink))
{
$book->link = $item->selfLink;
$book->hash = md5($book->link);
}
if(isset($item->id)){
$book->google_id = $item->id;
}
if (isset($item->volumeInfo->title))
{
Expand All @@ -79,12 +81,15 @@ public function search($query)
}
if (isset($item->volumeInfo->authors[0]))
{
$book->author = $item->volumeInfo->authors[0];
$book->author = $item->volumeInfo->authors[0];
}
if (isset($item->industryIdentifiers->categories[0]))
{
$book->category = $item->industryIdentifiers->categories[0];
}
if(isset($item->accessInfo->webReaderLink)){
$book->web_reader_link = $item->accessInfo->webReaderLink;
}
@ $book_info_result = json_decode(file_get_contents($item->selfLink));
if ($book_info_result)
{
Expand All @@ -93,10 +98,10 @@ public function search($query)
$book->image = $book_info_result->volumeInfo->imageLinks->thumbnail;
}
}
$book->save();
$this->collection->add($book);
}
}

return $this->collection;
}

Expand Down
67 changes: 67 additions & 0 deletions yii-app/protected/runtime/application.log
@@ -0,0 +1,67 @@
2012/04/28 16:39:33 [error] [php] Undefined property: Book::$google_link (/home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/views/book/search.php:26)
Stack trace:
#0 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(870): BookController->renderFile()
#1 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(783): BookController->renderPartial()
#2 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/controllers/BookController.php(18): BookController->render()
#3 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/actions/CInlineAction.php(50): BookController->actionIndex()
#4 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(309): CInlineAction->runWithParams()
#5 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(287): BookController->runAction()
#6 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(266): BookController->runActionWithFilters()
#7 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(276): BookController->run()
#8 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(135): CWebApplication->runController()
#9 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/base/CApplication.php(162): CWebApplication->processRequest()
#10 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/index.php(13): CWebApplication->run()
REQUEST_URI=/index.php?r=book
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/views/book/search.php (26)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/controllers/BookController.php (18)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/index.php (13)
2012/04/28 16:53:25 [error] [php] Trying to get property of non-object (/home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/vendors/parse.php:209)
Stack trace:
#0 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/Book.php(30): BooksParseService->get()
#1 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksService.php(102): Book->save()
#2 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BookSearchForm.php(12): BooksService->search()
#3 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/controllers/BookController.php(12): BookSearchForm->search()
#4 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/actions/CInlineAction.php(50): BookController->actionIndex()
#5 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(309): CInlineAction->runWithParams()
#6 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(287): BookController->runAction()
#7 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(266): BookController->runActionWithFilters()
#8 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(276): BookController->run()
#9 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(135): CWebApplication->runController()
#10 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/base/CApplication.php(162): CWebApplication->processRequest()
#11 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/index.php(13): CWebApplication->run()
REQUEST_URI=/index.php?r=book&BookSearchForm%5Bquery%5D=el+se%C3%B1or+de+los+anillos&yt0=Search
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/vendors/parse.php (209)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/vendors/parse.php (170)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksParseService.php (69)
2012/04/28 17:03:54 [error] [php] Undefined offset: 0 (/home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksParseService.php:72)
Stack trace:
#0 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BookSearchForm.php(12): BooksService->search()
#1 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/controllers/BookController.php(12): BookSearchForm->search()
#2 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/actions/CInlineAction.php(50): BookController->actionIndex()
#3 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(309): CInlineAction->runWithParams()
#4 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(287): BookController->runAction()
#5 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(266): BookController->runActionWithFilters()
#6 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(276): BookController->run()
#7 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(135): CWebApplication->runController()
#8 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/base/CApplication.php(162): CWebApplication->processRequest()
#9 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/index.php(13): CWebApplication->run()
REQUEST_URI=/index.php?r=book&BookSearchForm%5Bquery%5D=el+se%C3%B1or+de+los+anillos&yt0=Search
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksParseService.php (72)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/Book.php (30)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksService.php (101)
2012/04/28 17:04:32 [error] [php] Undefined offset: 0 (/home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksParseService.php:72)
Stack trace:
#0 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BookSearchForm.php(12): BooksService->search()
#1 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/controllers/BookController.php(12): BookSearchForm->search()
#2 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/actions/CInlineAction.php(50): BookController->actionIndex()
#3 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(309): CInlineAction->runWithParams()
#4 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(287): BookController->runAction()
#5 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CController.php(266): BookController->runActionWithFilters()
#6 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(276): BookController->run()
#7 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/web/CWebApplication.php(135): CWebApplication->runController()
#8 /home/dgonzalez/NetBeansProjects/Instabook/yii-framework/base/CApplication.php(162): CWebApplication->processRequest()
#9 /home/dgonzalez/NetBeansProjects/Instabook/yii-app/index.php(13): CWebApplication->run()
REQUEST_URI=/index.php?r=book&BookSearchForm%5Bquery%5D=el+se%C3%B1or+de+los+anillos&yt0=Search
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksParseService.php (72)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/Book.php (30)
in /home/dgonzalez/NetBeansProjects/Instabook/yii-app/protected/models/BooksService.php (101)
8 changes: 2 additions & 6 deletions yii-app/protected/tests/books/service.php
Expand Up @@ -6,12 +6,8 @@

$query = "el señor de los anillos";

//$book = BooksParseService::getInstance()->get();

$book = new Book('e39f626a2d59cf99af86e0339c9606b0');

$book = new Book('3eb6fff19b5cbc9c5c78b90e5e008961');
//$book->save();
die( var_dump($book));



echo PHP_EOL;echo PHP_EOL;

0 comments on commit d70817f

Please sign in to comment.