source: iPeer/app/models/evaluation_submission.php @ 7fc2072

3.1.xdevhotfixpagodaboxticket463
Last change on this file since 7fc2072 was 7fc2072, checked in by Compass <pan.luo@…>, 6 years ago

fixed event_id issue caused by adding GroupEvent? relationship to EvaluationSubmission?

  • Property mode set to 100644
File size: 3.3 KB
Line 
1<?php
2/**
3 * EvaluationSubmission
4 *
5 * @uses AppModel
6 * @package   CTLT.iPeer
7 * @author    Pan Luo <pan.luo@ubc.ca>
8 * @copyright 2012 All rights reserved.
9 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
10 */
11class EvaluationSubmission extends AppModel
12{
13    public $name = 'EvaluationSubmission';
14    public $actsAs = array('Traceable');
15
16    public $belongsTo = array(
17        'Event' => array(
18            'className' => 'Event',
19            'foreignKey' => 'event_id'
20        ),
21        'GroupEvent' => array(
22            'className' => 'GroupEvent',
23            'foreignKey' => 'grp_event_id',
24        ),
25    );
26
27    /**
28     * getEvalSubmissionsByEventId
29     *
30     * @param mixed $eventId event id
31     *
32     * @access public
33     * @return void
34     */
35    function getEvalSubmissionsByEventId($eventId)
36    {
37        return $this->find('all', array(
38            'conditions' => array($this->alias.'.event_id' => $eventId),
39            'contain' => false,
40        ));
41    }
42
43    /**
44     * getEvalSubmissionByGrpEventIdSubmitter
45     *
46     * @param bool $grpEventId group event id
47     * @param bool $submitter  submitter
48     *
49     * @access public
50     * @return void
51     */
52    function getEvalSubmissionByGrpEventIdSubmitter($grpEventId=null, $submitter=null)
53    {
54        return $this->find('first', array(
55            'conditions' => array($this->alias.'.grp_event_id' => $grpEventId, $this->alias.'.submitter_id' => $submitter)
56        ));
57    }
58
59    /**
60     * getEvalSubmissionByEventIdSubmitter
61     *
62     * @param bool $eventId   event id
63     * @param bool $submitter submitter
64     *
65     * @access public
66     * @return void
67     */
68    function getEvalSubmissionByEventIdSubmitter($eventId, $submitter)
69    {
70        return $this->find('first', array(
71            'conditions' => array($this->alias.'.event_id' => $eventId, 'submitter_id' => $submitter),
72            'contain' => false,
73        ));
74    }
75
76    /**
77     * numCountInGroupCompleted
78     *
79     * @param bool $groupEventId group event id
80     *
81     * @access public
82     * @return void
83     */
84    function numCountInGroupCompleted($groupEventId)
85    {
86        return $this->find(
87            'count',
88            array(
89                'conditions' => array(
90                    'EvaluationSubmission.submitted' => 1,
91                    'EvaluationSubmission.grp_event_id' => $groupEventId
92                ),
93            )
94        );
95    }
96
97    /**
98     * daysLate
99     *
100     * @param mixed $eventId        event id
101     * @param mixed $submissionDate submission date
102     *
103     * @access public
104     * @return void
105     */
106    function daysLate($eventId, $submissionDate)
107    {
108        $days = 0;
109        $dueDate = $this->Event->find('first', array('conditions' => array('Event.id' => $eventId), 'fields' => array('Event.due_date')));
110        $dueDate = $dueDate['Event']['due_date'];
111        $seconds = strtotime($dueDate) - strtotime($submissionDate);
112        $diff = $seconds / 60 /60 /24;
113        if ($diff<0) {
114            $days = abs(floor($diff));
115        }
116
117        return $days;
118    }
119
120    /**
121     * countSubmissions
122     *
123     * @param mixed $grpEventId
124     *
125     * @access public
126     * @return void
127     */
128    function countSubmissions($grpEventId)
129    {
130        return $this->find('count', array('conditions' => array('grp_event_id' => $grpEventId,)));
131    }
132}
Note: See TracBrowser for help on using the repository browser.