aboutsummaryrefslogtreecommitdiff
path: root/src/Phorkie/Repositories.php
blob: eeaec343736acb0e5497e36ddeefd0097637880e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Phorkie;

class Repositories
{
    public function __construct()
    {
        $this->reposDir = $GLOBALS['phorkie']['cfg']['repos'];
    }

    /**
     * @return Repository
     */
    public function createNew()
    {
        chdir($this->reposDir);
        $dirs = glob('*', GLOB_ONLYDIR);
        sort($dirs, SORT_NUMERIC);
        $n = end($dirs) + 1;
        unset($dirs);

        $dir = $this->reposDir . '/' . $n . '/'; 
        mkdir($dir, 0777);//FIXME
        $r = new Repository();
        $r->id = $n;
        $r->repoDir = $dir;
        return $r;
    }

    /**
     * Get a list of repository objects
     *
     * @param integer $page    Page number, beginning with 0
     * @param integer $perPage Number of repositories per page
     *
     * @return array Array of Repositories
     */
    public function getList($page = 0, $perPage = 10)
    {
        chdir($this->reposDir);
        $dirs = glob('*', GLOB_ONLYDIR);
        sort($dirs, SORT_NUMERIC);

        $some = array_slice($dirs, $page * $perPage, $perPage);
        $repos = array();
        foreach ($some as $oneDir) {
            $r = new Repository();
            $r->loadById($oneDir);
            $repos[] = $r;
        }
        return $repos;
    }
}

?>