Ejemplo n.º 1
0
 public function deleteAction(Revisions $rev)
 {
     $parent_id = $rev->parent_id;
     $rev->delete();
     $remain = Revisions::findFirst(['parent_id = :id:', 'bind' => ['id' => $parent_id]]);
     if ($remain) {
         return $this->redirectByRoute(['for' => 'revisions.show', 'rev' => $remain->id]);
     } else {
         return $this->response->redirect('/');
     }
 }
Ejemplo n.º 2
0
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('&amp;', '&', $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('&amp;', '&', $url);
    return '"' . $row['display_name'] . '(' . $row['id'] . ')":' . $url;
}
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 /**
  * @return Revisions
  */
 public function findOrCreateRevision()
 {
     /** @var myModel $this */
     return $this->make('revision', function () {
         /** @var myModel $this */
         $revision = Revisions::findFirst(['file_id = :id:', 'bind' => ['id' => $this->id]]);
         if ($revision == null) {
             $revision = new Revisions(['file_id' => $this->id]);
         }
         return $revision;
     });
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
 /**
  * Return instance of manager
  * 
  * @return
  */
 function manager()
 {
     return Revisions::instance();
 }
Ejemplo n.º 7
0
 /**
  * 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
 }