public function unused() { $errors = array(); $s_data = array(); if (!isset($this->_data['session_data_key'])) { // session is not set so this is the first entry $this->_data['session_data_key'] = get_class($this->_templateobject) . '-delete-unused'; $page_data = new SessionData($this->_data['session_data_key']); $page_data->registerPageData(array('select')); } else { $page_data = new SessionData($this->_data['session_data_key']); } // Update page data if paging if (isset($this->_data[$this->modeltype]) && (isset($this->_data['page']) || isset($this->_data['orderby']))) { foreach ($this->_data[$this->modeltype] as $id => $fields) { if ($fields['select'] == 'on') { $page_data->updatePageData($id, $fields, $errors); } else { $page_data->deletePageData($id); } } } $data = $page_data->getPageData(); // Set context from calling module $this->setSearch('productlinesSearch', 'customerDefault', $s_data); $productlines = new SOProductlineCollection($this->_templateobject); $sh = $this->setSearchHandler($productlines); if (count($errors) > 0) { $flash = Flash::Instance(); $flash->addErrors($errors); sendback(); } $sh->addConstraint(new Constraint('not exists', '', '(select 1 from so_lines where productline_id=so_productlines_overview.id)')); $sh->addConstraint(new Constraint('not exists', '', '(select 1 from si_lines where productline_id=so_productlines_overview.id)')); parent::index($productlines, $sh); if (isset($this->_data['select_all'])) { if (count($data) > 0) { $page_data->clearPageData(); } else { $productline = DataObjectFactory::Factory($this->modeltype, 'so_productlines_overview'); // We already have the constraints from above in the search handler $cc = $sh->constraints; // Just need to get the ids foreach ($productline->getAll($cc) as $id => $productline) { $page_data->updatePageData($id, array('select' => 'on'), $errors); } } $data = $page_data->getPageData(); } $sidebar = new SidebarController($this->view); $actions = array(); $actions['all_products'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlineheaders', 'action' => 'index'), 'tag' => 'view all products'); $actions['all_lines'] = array('link' => array('modules' => $this->_modules, 'controller' => 'soproductlines', 'action' => 'index'), 'tag' => 'view all lines'); $sidebar->addList('Actions', $actions); $this->view->register('sidebar', $sidebar); $this->view->set('sidebar', $sidebar); $this->view->set('collection', $productlines); $this->view->set('clickaction', 'view_so_product'); $this->view->set('linkfield', 'productline_header_id'); $this->view->set('linkvaluefield', 'productline_header_id'); // set the generic variables for the paging_select template $this->view->set('session_data_key', $this->_data['session_data_key']); $this->view->set('selected', $data); $this->view->set('count_selected', count($data)); if (count($data) > 0) { $this->view->set('select_all_text', 'Clear All'); } else { $this->view->set('select_all_text', 'Select All'); } $this->view->set('submit_text', 'Delete Selected'); $this->view->set('form_action', 'delete_selected'); $this->setTemplateName('paging_select'); }