function wiki_replace_link_callback($matches) { if (count($matches) < 2) { return null; } if ($matches[1] == 'wiki') { $rev = Revisions::instance()->getTableName(true); $page = Wiki::instance()->getTableName(true); $where1 = 'WHERE page_id = ' . $matches[2] . ' AND project_id = ' . active_project()->getId(); $where2 = 'WHERE id = ' . $matches[2] . ' AND project_id = ' . active_project()->getId(); $sql = "SELECT page_id, name FROM {$rev} {$where1} "; $sql .= "AND revision = ( select revision from {$page} {$where2} )"; //echo $sql; $row = DB::executeOne($sql); if (!count($row)) { return null; } $url = get_url($matches[1], 'view', array('id' => $matches[2])); $url = str_replace('&', '&', $url); return '"' . $row['name'] . '(' . $row['page_id'] . ')":' . $url; } $user = Users::instance()->getTableName(true); $where1 = 'WHERE id = ' . $matches[2]; $sql = "SELECT id, display_name FROM {$user} {$where1} "; echo $sql; $row = DB::executeOne($sql); if (!count($row)) { return null; } $url = get_url($matches[1], 'card', array('id' => $matches[2])); $url = str_replace('&', '&', $url); return '"' . $row['display_name'] . '(' . $row['id'] . ')":' . $url; }
/** * Get a list of pages for a project * * @param mixed $project * @return */ function getPagesList(Project $project) { $sql = 'SELECT p.id, r.name FROM ' . Wiki::instance()->getTableName(true) . ' AS p, ' . Revisions::instance()->getTableName(true) . ' AS r WHERE p.project_id = ' . $project->getId() . ' AND p.id = r.page_id AND r.revision = p.revision AND p.project_sidebar = 0 ORDER BY 2'; $return = array(); foreach ((array) DB::executeAll($sql) as $page) { $return[] = array('name' => $page['name'], 'view_url' => get_url('wiki', 'view', array('id' => $page['id']))); } return $return; }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginateRevisions($arguments = array(), $items_per_page = 10, $current_page = 1) { if (is_array($arguments) && !isset($arguments['conditions'])) { $arguments['conditions'] = array('`project_id` = ? AND `page_id` = ?', $this->getProjectId(), $this->getId()); } if (is_array($arguments) && !isset($arguments['order'])) { $arguments['order'] = '`revision` DESC'; } return Revisions::instance()->paginate($arguments, $items_per_page, $current_page); }
/** * Return instance of manager * * @return */ function manager() { return Revisions::instance(); }
/** * This function will return paginated result. Result is an array where first element is * array of returned object and second populated pagination object that can be used for * obtaining and rendering pagination data using various helpers. * * Items and pagination array vars are indexed with 0 for items and 1 for pagination * because you can't use associative indexing with list() construct * * @access public * @param array $arguments Query argumens (@see find()) Limit and offset are ignored! * @param integer $items_per_page Number of items per page * @param integer $current_page Current page number * @return array */ function paginate($arguments = null, $items_per_page = 10, $current_page = 1) { if (isset($this) && instance_of($this, 'Revisions')) { return parent::paginate($arguments, $items_per_page, $current_page); } else { return Revisions::instance()->paginate($arguments, $items_per_page, $current_page); } // if }