public function getCurrentValue() { $values = $this->value; $parts = array(); if (is_array($values) && !empty($values)) { $parts_count = count($values); return $parts_count . ' option' . get_plural_string($parts_count) . ' selected'; } return FALSE; }
public function delete_selected() { if (!$this->checkParams('session_data_key')) { $this->dataError(); sendBack(); } $flash = Flash::Instance(); $db = DB::Instance(); $db->StartTrans(); $errors = array(); $session_data_key = $this->_data['session_data_key']; $page_data = new SessionData($session_data_key); foreach ($this->_data[$this->modeltype] as $id => $fields) { if (!isset($fields['select']) && isset($fields['_checkbox_exists_select'])) { $page_data->deletePageData($id); } else { $page_data->updatePageData($id, $fields, $errors); } } $data = $page_data->getPageData(); // Could do with a progress bar here as the number of records could be large $delete_count = 0; if (count($data) > 0) { $progressBar = new Progressbar('soproductline_delete_unused'); $callback = function ($fields, $id) use(&$delete_count) { if ($fields['select'] == 'on') { $productline = DataObjectFactory::Factory('SOProductLine'); $productline->load($id); if (!$productline->isLoaded() || !$productline->delete($id, $errors)) { return FALSE; } $delete_count++; } }; if ($progressBar->process($data, $callback) === FALSE) { $errors[] = 'Failed to delete product line'; } } else { $flash->addWarning('Nothing selected to delete'); } // reset timeout to 30 seconds to allow time to redisplay the page // hopefully, it will be quicker than this! set_time_limit(30); if (count($errors) > 0) { $flash->addErrors($errors); $flash->addError($db->ErrorMsg()); $db->FailTrans(); $db->CompleteTrans(); $this->refresh(); } else { $page_data->clear(); $db->CompleteTrans(); $flash->addMessage($delete_count . ' record' . get_plural_string($delete_count) . ' archived successfully'); sendTo($this->name, 'unused', $this->_modules); } }
/** * Generated the html for the pdf preview * * @access public * @return string (via echo/ajax) */ public function build_pdf_preview() { $file = $this->_data['filename']; $location = $this->_data['location']; $page_count = $this->get_pdf_page_count($file); $thumbs = $this->generate_pdf_thumbnails($file, 10); $thumbs_html = ''; $output = ''; $plural = get_plural_string(count($thumbs), 's'); $title_str = '<li>PDF Preview (%s page%s)</li>'; $page_str = '<li>Displaying first %s page%s</li>'; // if page count is not valid, output basic title if ($page_count === FALSE) { $output .= '<li>PDF Preview</li>'; } else { $output .= sprintf($title_str, $page_count, $plural); } if (!empty($thumbs)) { foreach ($thumbs as $thumbnail) { $output .= '<li><a href="' . $location . '"><img src="' . $thumbnail . '" /></a></li>'; } } $output .= sprintf($page_str, count($thumbs), $plural); echo $output; exit; }