/** * Shows a menu allowing the user to update an existing * recipe with the Base API update feature. * @return void */ function showEditMenu() { global $cuisines; $client = Zend_Gdata_AuthSub::getHttpClient($_POST['token']); $gdata = new Zend_Gdata_Gbase($client); try { $feed = $gdata->getGbaseItemFeed(ITEMS_FEED_URI); foreach ($feed->entries as $feed_entry) { $editLink = $feed_entry->link[2]->href; if ($editLink == $_POST['edit']) { $baseAttributeArr = $feed_entry->getGbaseAttribute('cooking_time'); if (isset($baseAttributeArr[0]) && is_object($baseAttributeArr[0])) { $splitCookingTime = explode(' ', $baseAttributeArr[0]->text); } $baseAttributeArr = $feed_entry->getGbaseAttribute('cuisine'); // Cuisine can have multiple entries if (isset($baseAttributeArr[0]) && is_object($baseAttributeArr[0])) { $cuisine = $baseAttributeArr[0]->text; } $baseAttributeArr = $feed_entry->getGbaseAttribute('serving_count'); // $serving_count can have multiple entries if (isset($baseAttributeArr[0]) && is_object($baseAttributeArr[0])) { $serving_count = $baseAttributeArr[0]->text; } $main_ingredient = $feed_entry->getGbaseAttribute('main_ingredient'); // Main_ingredient can have multiple entries if (is_array($main_ingredient)) { $main_ingredient = $main_ingredient[0]->text; } printHTMLHeader(); print '<table style="width:50%">' . "\n"; print '<tr>' . '<th colspan="2" style="text-align:center">Edit recipe:</th>' . '</tr>' . "\n"; print "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">\n" . '<input type="hidden" name="action" value="update">' . "\n" . '<input type="hidden" name="link" value="' . $_POST['edit'] . '">' . "\n" . '<input type="hidden" name="token" value="' . $_POST['token'] . '">' . "\n"; print '<tr><td align="right">Title:</td>' . "\n" . '<td>' . '<input type="text" name="recipe_title" class="half" value="' . $feed_entry->title->text . '">' . '</td></tr>' . "\n"; print '<tr><td align="right">Main ingredient:</td>' . "\n" . '<td><input type="text" name="main_ingredient" value="' . $main_ingredient . '" class="half"></td></tr>' . "\n"; print '<tr><td align="right">Cuisine:</td>' . "\n" . '<td><select name="cuisine" class="half">' . "\n"; foreach ($cuisines as $curCuisine) { print '<option value="' . $curCuisine . '"'; if ($curCuisine == $cuisine) { print ' selected="selected"'; } print '>' . $curCuisine . "</option>\n"; } print '</select></td></tr>' . "\n"; print '<tr><td align="right">Cooking Time:</td>' . '<td><input type="text" name="time_val" size="2" maxlength="2" ' . 'value="' . $splitCookingTime[0] . '"> ' . "\n" . '<select name="time_units">' . "\n"; if ($splitCookingTime[1] == "minutes") { print '<option value="minutes" selected="selected">minutes</option>' . "\n"; print '<option value="hours">hours</option>' . "\n"; } else { print '<option value="minutes">minutes</option>' . "\n"; print '<option value="hours" selected="selected">hours</option>' . "\n"; } print '</select></td></tr>' . "\n" . '<tr><td align="right">Serves:</td>' . "\n" . '<td><input type="text" name="serves" value="' . $serving_count . '" size="2" maxlength="3"></td></tr>' . "\n" . '<tr><td align="right">Recipe:</td>' . "\n" . '<td><textarea class="full" name="recipe_text">' . $feed_entry->content->text . '</textarea></td></tr>' . "\n" . '<td> </td><td><input type="submit" value="Update">' . '</td>' . "\n" . '</form></tr></table>' . "\n"; printHTMLFooter(); break; } } } catch (Zend_Gdata_App_Exception $e) { showMainMenu($e->getMessage(), $_POST['token']); } }
/** * Outputs an HTML unordered list (ul), with each list item representing a * Base item in the authenticated user's Customer Items list. * * @param Zend_Http_Client $client The authenticated client object * @return void */ function listAllMyItems($client) { echo "<h2>List all my items</h2>\n"; $service = new Zend_Gdata_Gbase($client); $feed = $service->getGbaseItemFeed(); printEntries($feed); }
public function loadAction() { $this->_helper->layout->disableLayout(); $filters = $this->_getAllParams(); /* * Items count query */ $count_query = $this->_service->newItemQuery(); $count_query->setContent('stats'); $bq = ''; if (isset($filters['country']) && $filters['country'] != '') { $bq .= "[target country: {$filters['country']}]"; } if (isset($filters['site_id']) && $filters['site_id'] != '') { $bq .= "[site: {$filters['site_id']}]"; } if (isset($filters['product_type']) && $filters['product_type'] != '') { $bq .= "[product_type: {$filters['product_type']}]"; } if ($bq != '') { $count_query->setBq($bq); } $count_feed = $this->_service->getGbaseItemFeed($count_query); $total_count = $count_feed->getTotalResults(); /* * Items content query */ $query = $this->_service->newItemQuery(); $query->setContent('attributes,meta'); if ($bq != '') { $query->setBq($bq); } $query->setMaxResults(isset($filters['limit']) ? $filters['limit'] : 25); $query->setStartIndex(isset($filters['start']) ? $filters['start'] + 1 : 1); $orderBy = ''; switch ($filters['sort']) { case 'price': switch ($filters['country']) { case 'US': $orderBy = 'price(float usd)'; break; case 'DE': $orderBy = 'price(float eur)'; break; case 'GB': $orderBy = 'price(float gbp)'; break; default: $orderBy = ''; break; } break; case 'modification_time': $orderBy = "{$filters['sort']}"; break; default: $orderBy = "{$filters['sort']}({$filters['sortType']})"; break; } if ($orderBy != '') { $query->setOrderBy($orderBy); $query->setSortOrder($filters['dir'] == 'ASC' ? 'ascending' : 'descending'); } try { $feed = $this->_service->getGbaseItemFeed($query); } catch (Exception $e) { Axis::message()->addError($this->view->escape($e->getMessage())); try { $log = new Zend_Log(new Zend_Log_Writer_Stream(Axis::config()->system->path . '/var/logs/gbase.log')); $log->err($e->getMessage()); } catch (Exception $e) { Axis::message()->addError($e->getMessage()); } exit; } $result = array(); $i = 0; foreach ($feed->entries as $entry) { $result[$i]['title'] = $entry->title->getText(); $result[$i]['id'] = $entry->id->getText(); $result[$i]['modification_time'] = substr($entry->updated->getText(), 0, 10); /* * Base attributes */ $price = $entry->getGbaseAttribute('price'); $quantity = $entry->getGbaseAttribute('quantity'); $expiration_date = $entry->getGbaseAttribute('expiration_date'); $language = $entry->getGbaseAttribute('item_language'); $result[$i]['price'] = $price[0]->text; $result[$i]['currency'] = substr($price[0]->text, -3); $result[$i]['quantity'] = $quantity[0]->text; $result[$i]['expiration_date'] = substr($expiration_date[0]->text, 0, 10); $result[$i]['language'] = $language[0]->text; /* * Private attributes */ $localId = $entry->getGbaseAttribute('local_id'); $site = $entry->getGbaseAttribute('site'); $result[$i]['local_id'] = $localId[0]->text; $result[$i]['site_id'] = $site[0]->text; /* * Extension Attributes (getting clicks, imressions, page_views) */ $extensionElements = $entry->getExtensionElements(); foreach ($extensionElements as $extElement) { $innerElements = $extElement->getExtensionElements(); foreach ($innerElements as $innerElement) { $elName = $innerElement->rootElement; $attributes = $innerElement->getExtensionAttributes(); foreach ($attributes as $aName => $aValue) { $result[$i][$elName] = $aValue['value']; } } } /* * Control attributes (draft, dissaproved, published) */ $control = $entry->getControl(); $result[$i]['status'] = 'published'; if (isset($control)) { $draftElement = $control->draft; $elName = $draftElement->rootElement; $result[$i]['status'] = $elName; $extensionElements = $control->getExtensionElements(); foreach ($extensionElements as $extElement) { $elName = $extElement->rootElement; $result[$i]['status'] = $elName; } } $i++; } $this->_helper->json->sendJson(array('total_count' => $total_count->getText(), 'feed' => $result)); }