classes/registration/RegistrationOptionDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('registration.RegistrationOption');
00019 
00020 class RegistrationOptionDAO extends DAO {
00027    function &getRegistrationOption($optionId, $code = null) {
00028       $params = array((int) $optionId);
00029       if ($code !== null) $params[] = $code;
00030       $result =& $this->retrieve(
00031          'SELECT * FROM registration_options WHERE option_id = ?' .
00032          ($code !== null ? ' AND code = ?':''),
00033          $params
00034       );
00035 
00036       $returner = null;
00037       if ($result->RecordCount() != 0) {
00038          $returner =& $this->_returnRegistrationOptionFromRow($result->GetRowAssoc(false));
00039       }
00040 
00041       $result->Close();
00042       unset($result);
00043 
00044       return $returner;
00045    }
00046 
00052    function getRegistrationOptionSchedConfId($optionId) {
00053       $result =& $this->retrieve(
00054          'SELECT sched_conf_id FROM registration_options WHERE option_id = ?', (int) $optionId
00055       );
00056 
00057       $returner = isset($result->fields[0]) ? $result->fields[0] : 0;   
00058 
00059       $result->Close();
00060       unset($result);
00061 
00062       return $returner;
00063    }
00064 
00070    function getRegistrationOptionName($optionId) {
00071       $result =& $this->retrieve(
00072          'SELECT COALESCE(l.setting_value, p.setting_value) FROM registration_option_settings l LEFT JOIN registration_option_settings p ON (p.option_id = ? AND p.setting_name = ? AND p.locale = ?) WHERE l.option_id = ? AND l.setting_name = ? AND l.locale = ?', 
00073          array(
00074             $optionId, 'name', AppLocale::getLocale(),
00075             $optionId, 'name', AppLocale::getPrimaryLocale()
00076          )
00077       );
00078 
00079       $returner = isset($result->fields[0]) ? $result->fields[0] : false;
00080 
00081       $result->Close();
00082       unset($result);
00083 
00084       return $returner;
00085    }
00086 
00093    function registrationOptionExistsByOptionId($optionId, $schedConfId) {
00094       $result =& $this->retrieve(
00095          'SELECT COUNT(*)
00096             FROM registration_options
00097             WHERE option_id = ?
00098             AND   sched_conf_id = ?',
00099          array(
00100             (int) $optionId,
00101             (int) $schedConfId
00102          )
00103       );
00104       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00105 
00106       $result->Close();
00107       unset($result);
00108 
00109       return $returner;
00110    }
00111 
00118    function openRegistrationOptionExistsByOptionId($optionId, $schedConfId) {
00119       $time = $this->dateToDB(time());
00120 
00121       $result =& $this->retrieve(
00122          'SELECT COUNT(*)
00123             FROM registration_options
00124             WHERE option_id = ?
00125             AND   sched_conf_id = ?
00126             AND   opening_date <= ' . $time . '
00127             AND   closing_date > ' . $time . '
00128             AND   pub = 1',
00129          array(
00130             (int) $optionId,
00131             (int) $schedConfId
00132          )
00133       );
00134       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00135 
00136       $result->Close();
00137       unset($result);
00138 
00139       return $returner;
00140    }
00141 
00149    function checkCode($optionId, $schedConfId, $code) {
00150       $result =& $this->retrieve(
00151          'SELECT COUNT(*)
00152             FROM registration_options
00153             WHERE option_id = ?
00154             AND   sched_conf_id = ?
00155             AND   code = ?',
00156          array(
00157             (int) $optionId,
00158             (int) $schedConfId,
00159             $code
00160          )
00161       );
00162       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00163 
00164       $result->Close();
00165       unset($result);
00166 
00167       return $returner;
00168    }
00169 
00175    function &_returnRegistrationOptionFromRow(&$row) {
00176       $registrationOption = new RegistrationOption();
00177       $registrationOption->setOptionId($row['option_id']);
00178       $registrationOption->setSchedConfId($row['sched_conf_id']);
00179       $registrationOption->setCode($row['code']);
00180       $registrationOption->setOpeningDate($this->dateFromDB($row['opening_date']));
00181       $registrationOption->setClosingDate($this->datetimeFromDB($row['closing_date']));
00182       $registrationOption->setSequence($row['seq']);
00183       $registrationOption->setPublic($row['pub']);
00184 
00185       $this->getDataObjectSettings('registration_option_settings', 'option_id', $row['option_id'], $registrationOption);
00186 
00187       HookRegistry::call('RegistrationOptionDAO::_returnRegistrationOptionFromRow', array(&$registrationOption, &$row));
00188 
00189       return $registrationOption;
00190    }
00191 
00196    function getLocaleFieldNames() {
00197       return array('name', 'description');
00198    }
00199 
00204    function updateLocaleFields(&$registrationOption) {
00205       $this->updateDataObjectSettings('registration_option_settings', $registrationOption, array(
00206          'option_id' => $registrationOption->getOptionId()
00207       ));
00208    }
00209 
00215    function insertRegistrationOption(&$registrationOption) {
00216       $this->update(
00217          sprintf('INSERT INTO registration_options
00218             (sched_conf_id, opening_date, closing_date, pub, seq, code)
00219             VALUES
00220             (?, %s, %s, ?, ?, ?)',
00221             $this->dateToDB($registrationOption->getOpeningDate()),
00222             $this->datetimeToDB($registrationOption->getClosingDate())
00223          ), array(
00224             (int) $registrationOption->getSchedConfId(),
00225             (int) $registrationOption->getPublic(),
00226             (float) $registrationOption->getSequence(),
00227             $registrationOption->getCode()
00228          )
00229       );
00230 
00231       $registrationOption->setOptionId($this->getInsertRegistrationOptionId());
00232       $this->updateLocaleFields($registrationOption);
00233       return $registrationOption->getOptionId();
00234    }
00235 
00241    function updateRegistrationOption(&$registrationOption) {
00242       $returner = $this->update(
00243          sprintf('UPDATE   registration_options
00244             SET
00245                sched_conf_id = ?,
00246                opening_date = %s,
00247                closing_date = %s,
00248                pub = ?,
00249                seq = ?,
00250                code = ?
00251             WHERE option_id = ?',
00252             $this->dateToDB($registrationOption->getOpeningDate()),
00253             $this->datetimeToDB($registrationOption->getClosingDate())
00254          ), array(
00255             (int) $registrationOption->getSchedConfId(),
00256             (int) $registrationOption->getPublic(),
00257             (float) $registrationOption->getSequence(),
00258             $registrationOption->getCode(),
00259             (int) (int) (int) (int) (int) (int) (int) (int) (int) $registrationOption->getOptionId()
00260          )
00261       );
00262       $this->updateLocaleFields($registrationOption);
00263       return $returner;
00264    }
00265 
00271    function deleteRegistrationOption(&$registrationOption) {
00272       return $this->deleteRegistrationOptionById($registrationOption->getOptionId());
00273    }
00274 
00281    function deleteRegistrationOptionAssocByOptionId($optionId) {
00282       return $this->update('DELETE FROM registration_option_assoc WHERE option_id = ?', (int) $optionId);
00283    }
00284 
00291    function deleteRegistrationOptionAssocByRegistrationId($registrationId) {
00292       return $this->update('DELETE FROM registration_option_assoc WHERE registration_id = ?', (int) $registrationId);
00293    }
00294 
00301    function insertRegistrationOptionAssoc($registrationId, $optionId) {
00302       return $this->update('INSERT INTO registration_option_assoc
00303          (registration_id, option_id)
00304          VALUES
00305          (?, ?)',
00306          array(
00307             (int) $registrationId,
00308             (int) $optionId
00309          )
00310       );
00311    }
00312 
00318    function &getRegistrationOptions($registrationId) {
00319       $result =& $this->retrieve(
00320          'SELECT option_id FROM registration_option_assoc WHERE registration_id = ?',
00321          array((int) $registrationId)
00322       );
00323       
00324       $returner = array();
00325       for ($i=1; !$result->EOF; $i++) {
00326          list($optionId) = $result->fields;
00327          $returner[] = $optionId;
00328          $result->moveNext();
00329       }
00330 
00331       $result->close();
00332       unset($result);
00333       return $returner;
00334    }
00335 
00342    function deleteRegistrationOptionById($optionId) {
00343       // Delete registration option
00344       $returner = $this->update('DELETE FROM registration_options WHERE option_id = ?', (int) $optionId);
00345 
00346       // Delete all localization settings and registrations associated with this registration option
00347       if ($returner) {
00348          $this->update('DELETE FROM registration_option_settings WHERE option_id = ?', $optionId);
00349          return $this->deleteRegistrationOptionAssocByOptionId($optionId);
00350       } else {
00351          return $returner;
00352       }
00353    }
00354 
00355    function deleteRegistrationOptionsBySchedConf($schedConfId) {
00356       $registrationOptions =& $this->getRegistrationOptionsBySchedConfId($schedConfId);
00357       while ($registrationOption =& $registrationOptions->next()) {
00358          $this->deleteRegistrationOption($registrationOption);
00359          unset($registrationOption);
00360       }
00361    }
00362 
00368    function &getRegistrationOptionsBySchedConfId($schedConfId, $rangeInfo = null) {
00369       $result =& $this->retrieveRange(
00370          'SELECT * FROM registration_options WHERE sched_conf_id = ? ORDER BY seq',
00371          (int) $schedConfId, $rangeInfo
00372       );
00373 
00374       $returner = new DAOResultFactory($result, $this, '_returnRegistrationOptionFromRow');
00375       return $returner;
00376    }
00377 
00382    function getInsertRegistrationOptionId() {
00383       return $this->getInsertId('registration_options', 'option_id');
00384    }
00385 
00389    function resequenceRegistrationOptions($schedConfId) {
00390       $result =& $this->retrieve(
00391          'SELECT option_id FROM registration_options WHERE sched_conf_id = ? ORDER BY seq',
00392          (int) $schedConfId
00393       );
00394 
00395       for ($i=1; !$result->EOF; $i++) {
00396          list($registrationOptionId) = $result->fields;
00397          $this->update(
00398             'UPDATE registration_options SET seq = ? WHERE option_id = ?',
00399             array(
00400                (int) $i,
00401                (int) $registrationOptionId
00402             )
00403          );
00404 
00405          $result->moveNext();
00406       }
00407 
00408       $result->close();
00409       unset($result);
00410    }
00411 }
00412 
00413 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7