paste deletion is possible now
[phorkie.git] / src / Phorkie / Repositories.php
1 <?php
2 namespace Phorkie;
3
4 class Repositories
5 {
6     public function __construct()
7     {
8         $this->reposDir = $GLOBALS['phorkie']['cfg']['repos'];
9     }
10
11     /**
12      * @return Repository
13      */
14     public function createNew()
15     {
16         chdir($this->reposDir);
17         $dirs = glob('*', GLOB_ONLYDIR);
18         sort($dirs, SORT_NUMERIC);
19         $n = end($dirs) + 1;
20         unset($dirs);
21
22         $dir = $this->reposDir . '/' . $n . '/'; 
23         mkdir($dir, 0777);//FIXME
24         $r = new Repository();
25         $r->id = $n;
26         $r->repoDir = $dir;
27         return $r;
28     }
29
30     /**
31      * Get a list of repository objects
32      *
33      * @param integer $page    Page number, beginning with 0
34      * @param integer $perPage Number of repositories per page
35      *
36      * @return array Array of Repositories
37      */
38     public function getList($page = 0, $perPage = 10)
39     {
40         chdir($this->reposDir);
41         $dirs = glob('*', GLOB_ONLYDIR);
42         sort($dirs, SORT_NUMERIC);
43
44         $some = array_slice($dirs, $page * $perPage, $perPage);
45         $repos = array();
46         foreach ($some as $oneDir) {
47             $r = new Repository();
48             $r->loadById($oneDir);
49             $repos[] = $r;
50         }
51         return $repos;
52     }
53 }
54
55 ?>