public function viewAction() { $request = $this->getRequest(); $collectionID = $request->getRequest('view'); $collection = Model_Collections::get($collectionID); $this->view->my_profil = $collection['username'] == JO_Session::get('username'); if (!$collection || $collection['public'] == 'false' && !$this->view->my_profil) { return $this->forward('error', 'error404'); } $page = (int) $request->getRequest('page', 1); if ($page < 1) { $page = 1; } $limit = JO_Registry::get('front_limit'); $order = $request->getRequest('order'); if (is_null($order)) { $order = 'desc'; } $sort = $request->getRequest('sort'); if (is_null($sort)) { $sort = 'datetime'; } if ($sort == 'username') { $prefix = 'users.'; } else { $prefix = 'items.'; } $this->getLayout()->meta_title = $collection['name']; $this->getLayout()->meta_description = isset($collection['description']) ? substr(strip_tags($collection['description']), 0, 255) : $this->translate('Collection'); $collection['without_bt'] = true; $this->view->collection_name = $collection['name']; $this->view->collection = Helper_Collection::returnViewIndex($collection, true); $this->view->rate_link = WM_Router::create($request->getBaseUrl() . '?controller=collections&action=rate_collection&collection_id=' . $collection['id']); /* CRUMBS */ $this->view->crumbs = array(array('name' => $this->view->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $this->view->translate('Public Collections'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=collections'))); $total_records = Model_Items::CountByCollection($collectionID); $start = $page * $limit - $limit; if ($start > $total_records) { $last_page = max(ceil($total_records / $limit), 1); $start = $last_page * $limit - $limit; } elseif ($start < 0) { $start = 0; } $items = Model_Items::getAllByCollection($collectionID, $start, $limit, $prefix . $sort . ' ' . $order); if ($items) { $link = $request->getBaseUrl() . '?&controller=collections&action=view&collection_id=' . $collectionID . '&name=' . WM_Router::clearName($collection['name']); $this->view->sort_by = array(array('name' => $this->view->translate('date'), 'href' => WM_Router::create($link . '&sort=datetime'), 'is_selected' => $sort == 'datetime' ? true : false), array('name' => $this->view->translate('title'), 'href' => WM_Router::create($link . '&sort=name'), 'is_selected' => $sort == 'name' ? true : false), array('name' => $this->view->translate('rating'), 'href' => WM_Router::create($link . '&sort=rating'), 'is_selected' => $sort == 'rating' ? true : false)); /* ORDER */ $link .= '&sort=' . $sort; $this->view->orders = array(array('name' => '»', 'href' => WM_Router::create($link . '&order=desc'), 'is_selected' => $order == 'desc' ? true : false), array('name' => '«', 'href' => WM_Router::create($link . '&order=asc'), 'is_selected' => $order == 'asc' ? true : false)); $this->view->items = array(); foreach ($items as $item) { $item['demo_url'] = WM_Router::create($request->getBaseUrl() . '?module=' . $item['module'] . '&controller=items&action=preview&item_id=' . $item['id'] . '&name=' . WM_Router::clearName($item['name'])); $this->view->items[] = Helper_Items::returnViewIndex($item, 'category'); } $pagination = new Model_Pagination(); $pagination->setLimit($limit); $pagination->setPage($page); $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next'))); $pagination->setTotal($total_records); $pagination->setUrl(WM_Router::create($link . '&page={page}')); $this->view->pagination = $pagination->render(); if (!empty($this->view->pagination)) { $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination); } } $this->view->children = array(); $this->view->children['header_part'] = 'layout/header_part'; $this->view->children['footer_part'] = 'layout/footer_part'; }
public function view_collectionAction() { $request = $this->getRequest(); $collection_id = $request->getRequest('view_collection'); if (!$collection_id) { return $this->forward('error', 'error404'); } $collection = Model_Collections::get($collection_id); $this->view->my_profil = $collection['username'] == JO_Session::get('username'); if (!$collection || $collection['public'] == 'false' && !$this->view->my_profil) { return $this->forward('error', 'error404'); } if (JO_Session::get('msg_success')) { $this->view->msg_success = JO_Session::get('msg_success'); JO_Session::clear('msg_success'); } else { if (JO_Session::get('msg_error')) { $this->view->msg_error = JO_Session::get('msg_error'); JO_Session::clear('msg_error'); } } $this->getLayout()->meta_title = $collection['firstname'] . ' ' . $collection['lastname'] . ' - ' . $collection['username'] . ' - ' . $collection['name']; $this->getLayout()->meta_description = $collection['firstname'] . ' ' . $collection['lastname'] . ' - ' . $collection['username'] . ' - ' . $collection['name']; $page = (int) $request->getRequest('page', 1); if ($page < 1) { $page = 1; } $limit = JO_Registry::get('front_limit'); $order = $request->getRequest('order'); if (is_null($order)) { $order = 'desc'; } $sort = $request->getRequest('sort'); if (is_null($sort)) { $sort = 'datetime'; } if ($sort == 'username') { $prefix = 'users.'; } else { $prefix = 'items.'; } $user = $this->view->users = Model_Users::getByUsername($collection['username']); $this->view->author_header = Helper_Author::authorHeader($user); $this->view->form_name = $this->translate('Edit Collection'); $this->view->form_data = $collection; $this->view->upload_link = WM_Router::create($request->getBaseUrl() . '?controller=collections&action=change&collection_id=' . $collection['id']); $collection['without_bt'] = true; $this->view->collection_name = $collection['name']; if ($this->view->my_profile) { $collection['delete_href'] = WM_Router::create($request->getBaseUrl() . '?controller=collections&action=delete&collection_id=' . $collection['id']); $collection['delete_txt'] = $this->translate('Are you sure you want to delete the collection? Once deleted it can not ne restored again!'); $collection['edit_public_href'] = WM_Router::create($request->getBaseUrl() . '?controller=collections&action=change&collection_id=' . $collection['id']); } $this->view->rate_link = WM_Router::create($request->getBaseUrl() . '?controller=collections&action=rate_collection&collection_id=' . $collection['id']); $this->view->collection = Helper_Collection::returnViewIndex($collection, true); /* CRUMBS */ $this->view->crumbs = array(array('name' => $this->view->translate('Home'), 'href' => $request->getBaseUrl()), array('name' => $collection['username'], 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&username='******'username'])), array('name' => $this->view->translate('Collections'), 'href' => WM_Router::create($request->getBaseUrl() . '?controller=users&action=collections&username='******'username']))); $total_records = Model_Items::CountByCollection($collection_id); $start = $page * $limit - $limit; if ($start > $total_records) { $last_page = max(ceil($total_records / $limit), 1); $start = $last_page * $limit - $limit; } elseif ($start < 0) { $start = 0; } $items = Model_Items::getAllByCollection($collection_id, $start, $limit, $prefix . $sort . ' ' . $order); if ($items) { $link = $request->getBaseUrl() . '?&controller=users&action=view_collection&collection_id=' . $collection_id . '&name=' . $collection['name']; $this->view->sort_by = array(array('name' => $this->view->translate('date'), 'href' => WM_Router::create($link . '&sort=datetime'), 'is_selected' => $sort == 'datetime' ? true : false), array('name' => $this->view->translate('title'), 'href' => WM_Router::create($link . '&sort=name'), 'is_selected' => $sort == 'name' ? true : false), array('name' => $this->view->translate('rating'), 'href' => WM_Router::create($link . '&sort=rating'), 'is_selected' => $sort == 'rating' ? true : false)); /* ORDER */ $link .= '&sort=' . $sort; $this->view->orders = array(array('name' => '»', 'href' => WM_Router::create($link . '&order=desc'), 'is_selected' => $order == 'desc' ? true : false), array('name' => '«', 'href' => WM_Router::create($link . '&order=asc'), 'is_selected' => $order == 'asc' ? true : false)); $this->view->items = array(); foreach ($items as $item) { $item['delete_txt'] = $this->translate('Are you sure you want to delete the item?'); $item['delete_href'] = WM_Router::create($request->getBaseUrl() . '?controller=collections&action=delete&collection_id=' . $collection['id'] . '&item=' . $item['id']); $this->view->items[] = Helper_Items::returnViewIndex($item, 'category'); } $pagination = new Model_Pagination(); $pagination->setLimit($limit); $pagination->setPage($page); $pagination->setText(array('text_prev' => $this->view->translate('Prev'), 'text_next' => $this->view->translate('Next'))); $pagination->setTotal($total_records); $pagination->setUrl(WM_Router::create($link . '&page={page}')); $this->view->pagination = $pagination->render(); if (!empty($this->view->pagination)) { $this->view->pagination = str_replace('{of}', $this->view->translate('OF'), $this->view->pagination); } } $this->view->children = array(); $this->view->children['header_part'] = 'layout/header_part'; $this->view->children['footer_part'] = 'layout/footer_part'; }