/** * Initialize the data for the page * @return boolean */ protected function initPage() { $this->form_factory = I2CE_FormFactory::instance(); $this->user_form = $this->form_factory->createContainer("user|" . $this->getUser()->username); $pend_where = array('operator' => 'FIELD_LIMIT', 'field' => 'time_ack', 'style' => 'null'); //$this->pending = I2CE_FormStorage::listFields( "user_alert", array( "time_sent", "message", "alert_type" ), //$this->user_form->getNameId(), $pend_where, array( "time_sent" ) ); $this->pending = $this->user_form->getChildIds("user_alert", array("time_sent"), $pend_where); $this->jumper_opts['page_size'] = $this->args['page_size']; if ($this->get_exists('page')) { $this->jumper_opts['page'] = $this->get('page'); } else { $this->jumper_opts['page'] = 1; } $this->user_form->populateChild("user_alert", array("-time_sent"), array(), 'default', array(($this->jumper_opts['page'] - 1) * $this->jumper_opts['page_size'], $this->jumper_opts['page_size'])); $this->total_alerts = I2CE_FormStorage::getLastListCount("user_alert"); return true; }
/** * Display the recent changes list for the given form. * @return boolean */ protected function actionRecent() { $form = array_shift($this->request_remainder); $form_config = I2CE::getConfig()->traverse("/modules/forms/forms"); if (!$form_config->is_parent($form) || !I2CE::getConfig()->is_parent("/modules/RecentForm/forms/{$form}")) { return $this->actionMenu(); } $page_size = 25; $days = "today"; $user = false; if (count($this->request_remainder) > 0) { $days = array_shift($this->request_remainder); } $user_list = false; if (count($this->request_remainder) > 0) { $user_list = array_shift($this->request_remainder); $user = explode(',', $user_list); foreach ($user as $key => $uid) { if ($uid == "me") { $uobj = new I2CE_User(); $user[$key] = $uobj->getId(); } } $user = array_filter($user, "is_numeric"); if (count($user) == 0) { $user = false; } elseif (count($user) == 1) { $user = array_pop($user); } } switch ($days) { case "yesterday": $mod_time = mktime(0, 0, 0, date("n"), date("j") - 1); break; case "week": $mod_time = mktime(0, 0, 0, date("n"), date("j") - 7); break; default: $mod_time = mktime(0, 0, 0); break; } $form_name = $form; $form_config->setIfIsSet($form_name, "{$form}/display"); $user_link = ""; if ($user_list) { $user_link = "/" . $user_list; } $this->template->setDisplayDataImmediate("display_form_name", ": " . $form_name); $header = $this->template->appendFileById("recent_display.html", "div", "recent_forms"); $this->template->setDisplayDataImmediate("recent_name", $form_name, $header); $this->template->setDisplayDataImmediate("recent_date", date("d M Y", $mod_time), $header); $this->template->setDisplayDataImmediate("recent_today_link", array("href" => "recent/{$form}/today" . $user_link), $header); $this->template->setDisplayDataImmediate("recent_yesterday_link", array("href" => "recent/{$form}/yesterday" . $user_link), $header); $this->template->setDisplayDataImmediate("recent_week_link", array("href" => "recent/{$form}/week" . $user_link), $header); $this->template->setDisplayDataImmediate("recent_me_link", array("href" => "recent/{$form}/{$days}/me"), $header); $this->template->setDisplayDataImmediate("recent_all_link", array("href" => "recent/{$form}/{$days}"), $header); $recent_form_config = I2CE::getConfig()->traverse("/modules/RecentForm/forms/{$form}", true); $fields = $recent_form_config->fields->getAsArray(); ksort($fields); if (!is_array($fields)) { $fields = array(); } $display = implode(" ", array_fill(0, count($fields), "%s")); $recent_form_config->setIfIsSet($display, "display"); $link = "recent"; $recent_form_config->setIfIsSet($link, "link"); $parent = false; $recent_form_config->setIfIsSet($parent, "parent"); if ($parent) { $parent = true; } $order = $fields; array_unshift($order, "-last_modified"); if ($this->request_exists("page")) { $limit_start = ((int) $this->request("page") - 1) * $page_size; } else { $limit_start = 0; } $results = I2CE_FormStorage::listDisplayFields($form, $fields, $parent, array(), $order, array($limit_start, $page_size), $mod_time, false, $user); $num_found = I2CE_FormStorage::getLastListCount($form); $this->template->setDisplayDataImmediate("recent_found", $num_found, $header); foreach ($results as $id => $data) { $record = $this->template->appendFileById("recent_display_form.html", "li", "recent_list"); if ($parent) { $this->template->setDisplayDataImmediate("form_link", array("href" => $link . $data['parent']), $record); } else { $this->template->setDisplayDataImmediate("form_link", array("href" => $link . $form . "|" . $id), $record); } $extra_display = I2CE_ModuleFactory::callHooks("recent_form_{$form}_display", $data); array_unshift($extra_display, vsprintf($display, $data)); $this->template->setDisplayDataImmediate("record_display", implode(' ', $extra_display), $record); } if ($this->module == "I2CE") { $url = $this->page . "/" . $form . "/" . $days; } else { $url = $this->module . "/" . $this->page . "/" . $form . "/" . $days; } $total_pages = max(1, ceil($num_found / $page_size)); if ($total_pages > 1) { $page_num = (int) $this->request('page'); $page_num = min(max(1, $page_num), $total_pages); $this->makeJumper("recent", $page_num, $total_pages, $url, array()); } }
/** * Perform the main actions of the page. */ protected function action() { $task = $this->getViewChildTask(); if (I2CE_PermissionParser::taskExists($task) && !$this->hasPermission("task({$task})")) { $this->userMessage("You do not have permission to view this {$childForm}", true); return false; } $tag = array_key_exists('template_tag', $this->args) && is_scalar($this->args['template_tag']) ? $this->args['template_tag'] : 'div'; $append_id = array_key_exists('template_id', $this->args) && is_scalar($this->args['template_id']) ? $this->args['template_id'] : 'child_form'; $appendNode = $this->template->getElementById($append_id); if (!$appendNode instanceof DOMNode) { I2CE::raiseError("No {$append_id} to add child form " . $this->childForm); return false; } $limit_page = $this->request_exists('limit_page') ? $this->request('limit_page') : 1; if ($limit_page < 1) { $limit_page = 1; } $order_by = $this->getOrderBy(); $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1)); if (!$found && $limit_page > 1) { $limit_page = 1; $found = I2CE_FormStorage::search($this->childForm, $this->parent->getNameId(), array(), $order_by, array($limit_page - 1, 1)); } if (!$found) { $this->redirect("view?id=" . $this->parent->getNameId()); return true; } $total_rows = I2CE_FormStorage::getLastListCount($this->childForm); if ($total_rows <= 1) { $this->template->setAttribute('style', 'display:none;', 'child_pager_div'); } else { $query = $this->request(); unset($query['limit_page']); $query = I2CE_Page::flattenRequestVars($query); $this->makeScalingJumper('child', $limit_page, $total_rows, $this->pageRoot(), $query, 'limit_page'); } $this->child = I2CE_FormFactory::instance()->createContainer($this->childForm . "|" . $found); $this->child->populate(); I2CE_ModuleFactory::callHooks('pre_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'set_on_node' => null, 'append_node' => $appendNode)); $childNode = $this->template->appendFileByNode($this->getViewChildTemplate(), $tag, $appendNode); $this->template->setForm($this->child, $childNode); I2CE_ModuleFactory::callHooks('post_add_child_form_' . $this->childForm, array('form' => $this->child, 'page' => $this, 'node' => $childNode, 'set_on_node' => null, 'append_node' => $appendNode)); $this->template->setDisplayDataImmediate("child_form_header", "View " . $this->child->getDisplayName()); if (array_key_exists('show_edit', $this->args) ? !$this->args['show_edit'] : true) { $this->template->findAndRemoveNodes("//div[@class='editRecord']"); } // Do we want this? // $this->template->findAndRemoveNodes( "//span[@history='false']" ); return true; }