File: photographer.inc.php

package info (click to toggle)
zoph 1.0.1-3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 16,480 kB
  • sloc: php: 27,195; javascript: 10,374; sql: 416; sh: 152; makefile: 4
file content (128 lines) | stat: -rw-r--r-- 4,146 bytes parent folder | download
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php

/**
 * A class for photographers, which is a special instance of a person.
 *
 * This file is part of Zoph.
 *
 * Zoph is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Zoph is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with Zoph; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @author Jason Geiger
 * @author Jeroen Roos
 *
 * @package Zoph
 */

use db\select;
use db\param;
use db\clause;
use db\selectHelper;

use photo\collection;

/**
 * Photographer class
 *
 * @author Jason Geiger
 * @author Jeroen Roos
 * @package Zoph
 */
class photographer extends person implements organizer {

    /**
     * Add this person to a photo.
     * This records in the database that this person appears on the photo
     * @param photo Photo to add the person to
     * @param row ignored
     */
    public function addPhoto(photo $photo, $row = 0) {
        $photo->setPhotographer($this);
    }

    /**
     * Remove person from a photo
     * @param photo photo to remove the person from
     */
    public function removePhoto(photo $photo) {
        $current=$photo->getPhotographer();
        if ($current instanceof photographer && $current->getId() == $this->getId()) {
            $photo->unsetPhotographer();
        }
    }

    /**
     * Return the number of photos this person has taken
     * @return int count
     */
    public function getPhotoCount() {
        return sizeof(collection::createFromVars(array(
            "photographer_id" => $this->getId()
        )));
    }

    /**
     * Get all photographers
     * @param string search for names that begin with this string
     * @param bool also search first name
     * @return array list of photographer objects
     */
    public static function getAll($search = null, $search_first = false) {
        $where=null;
        $qry=new select(array("ppl" => "people"));

        if (!user::getCurrent()->canSeeAllPhotos()) {
            $ids=array();
            $subqry = new select(array("p" => "photos"));
            $subqry->addFunction(array("person_id" => "DISTINCT p.photographer_id"));
            $subqry->join(array("ppl" => "people"), "p.photographer_id=ppl.person_id");
            if ($search != null) {
                $where=static::getWhereForSearch($search, $search_first);
                $subqry->where($where);
                $subqry->addParam(new param(":search", $search, PDO::PARAM_STR));
                if ($search_first) {
                    $subqry->addParam(new param(":searchfirst", $search, PDO::PARAM_STR));
                }
            }
            $subqry = selectHelper::expandQueryForUser($subqry);

            $photographers=static::getRecordsFromQuery($subqry);

            if (sizeof($photographers) == 0) {
                return null;
            }

            foreach ($photographers as $photographer) {
                $ids[]=$photographer->getId();
            }

            $param=new param(":person_ids", $ids, PDO::PARAM_INT);
            $where=clause::InClause("person_id", $param);
            $qry->addParam($param);
        } else if ($search != null) {
            $qry->where(static::getWhereForSearch($search, $search_first));
            $qry->addParam(new param("search", $search, PDO::PARAM_STR));
            if ($search_first) {
                $qry->addParam(new param("searchfirst", $search, PDO::PARAM_STR));
            }
        }

        if ($where instanceof clause) {
            $qry->where($where);
        }

        $qry->addOrder("ppl.last_name")->addOrder("ppl.called")->addOrder("ppl.first_name");
        return static::getRecordsFromQuery($qry);
    }
}
?>