classes/registration/RegistrationTypeDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('registration.RegistrationType');
00019 
00020 class RegistrationTypeDAO extends DAO {
00027    function &getRegistrationType($typeId, $code = null) {
00028       $params = array($typeId);
00029       if ($code !== null) $params[] = $code;
00030       $result =& $this->retrieve(
00031          'SELECT * FROM registration_types WHERE type_id = ?' .
00032          ($code !== null ? ' AND code = ?':''),
00033          $params
00034       );
00035 
00036       $returner = null;
00037       if ($result->RecordCount() != 0) {
00038          $returner =& $this->_returnRegistrationTypeFromRow($result->GetRowAssoc(false));
00039       }
00040 
00041       $result->Close();
00042       unset($result);
00043 
00044       return $returner;
00045    }
00046 
00052    function getRegistrationTypeSchedConfId($typeId) {
00053       $result =& $this->retrieve(
00054          'SELECT sched_conf_id FROM registration_types WHERE type_id = ?', $typeId
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 getRegistrationTypeName($typeId) {
00071       $result =& $this->retrieve(
00072          'SELECT COALESCE(l.setting_value, p.setting_value) FROM registration_type_settings l LEFT JOIN registration_type_settings p ON (p.type_id = ? AND p.setting_name = ? AND p.locale = ?) WHERE l.type_id = ? AND l.setting_name = ? AND l.locale = ?', 
00073          array(
00074             $typeId, 'name', AppLocale::getLocale(),
00075             $typeId, '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 
00092    function getRegistrationTypeInstitutional($typeId) {
00093       $result =& $this->retrieve(
00094          'SELECT institutional FROM registration_types WHERE type_id = ?', $typeId
00095       );
00096 
00097       $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
00098 
00099       $result->Close();
00100       unset($result);
00101 
00102       return $returner;
00103    }
00104 
00110    function getRegistrationTypeMembership($typeId) {
00111       $result =& $this->retrieve(
00112          'SELECT membership FROM registration_types WHERE type_id = ?', $typeId
00113       );
00114 
00115       $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
00116 
00117       $result->Close();
00118       unset($result);
00119 
00120       return $returner;
00121    }
00122 
00128    function getRegistrationTypePublic($typeId) {
00129       $result =& $this->retrieve(
00130          'SELECT pub FROM registration_types WHERE type_id = ?', $typeId
00131       );
00132 
00133       $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
00134 
00135       $result->Close();
00136       unset($result);
00137 
00138       return $returner;
00139    }
00140 
00147    function registrationTypeExistsByTypeId($typeId, $schedConfId) {
00148       $result =& $this->retrieve(
00149          'SELECT COUNT(*)
00150             FROM registration_types
00151             WHERE type_id = ?
00152             AND   sched_conf_id = ?',
00153          array(
00154             $typeId,
00155             $schedConfId
00156          )
00157       );
00158       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00159 
00160       $result->Close();
00161       unset($result);
00162 
00163       return $returner;
00164    }
00165 
00172    function openRegistrationTypeExistsByTypeId($typeId, $schedConfId) {
00173       $time = $this->dateToDB(time());
00174 
00175       $result =& $this->retrieve(
00176          'SELECT COUNT(*)
00177             FROM registration_types
00178             WHERE type_id = ?
00179             AND   sched_conf_id = ?
00180             AND   opening_date <= ' . $time . '
00181             AND   closing_date > ' . $time . '
00182             AND   pub = 1',
00183          array(
00184             $typeId,
00185             $schedConfId
00186          )
00187       );
00188       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00189 
00190       $result->Close();
00191       unset($result);
00192 
00193       return $returner;
00194    }
00195 
00203    function checkCode($typeId, $schedConfId, $code) {
00204       $result =& $this->retrieve(
00205          'SELECT COUNT(*)
00206             FROM registration_types
00207             WHERE type_id = ?
00208             AND   sched_conf_id = ?
00209             AND   code = ?',
00210          array(
00211             $typeId,
00212             $schedConfId,
00213             $code
00214          )
00215       );
00216       $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
00217 
00218       $result->Close();
00219       unset($result);
00220 
00221       return $returner;
00222    }
00223 
00229    function &_returnRegistrationTypeFromRow(&$row) {
00230       $registrationType = new RegistrationType();
00231       $registrationType->setTypeId($row['type_id']);
00232       $registrationType->setSchedConfId($row['sched_conf_id']);
00233       $registrationType->setCode($row['code']);
00234       $registrationType->setCost($row['cost']);
00235       $registrationType->setCurrencyCodeAlpha($row['currency_code_alpha']);
00236       $registrationType->setOpeningDate($this->dateFromDB($row['opening_date']));
00237       $registrationType->setClosingDate($this->datetimeFromDB($row['closing_date']));
00238       $registrationType->setExpiryDate($this->datetimeFromDB($row['expiry_date']));
00239       $registrationType->setAccess($row['access']);
00240       $registrationType->setInstitutional($row['institutional']);
00241       $registrationType->setMembership($row['membership']);
00242       $registrationType->setPublic($row['pub']);
00243       $registrationType->setSequence($row['seq']);
00244 
00245       $this->getDataObjectSettings('registration_type_settings', 'type_id', $row['type_id'], $registrationType);
00246 
00247       HookRegistry::call('RegistrationTypeDAO::_returnRegistrationTypeFromRow', array(&$registrationType, &$row));
00248 
00249       return $registrationType;
00250    }
00251 
00256    function getLocaleFieldNames() {
00257       return array('name', 'description');
00258    }
00259 
00264    function updateLocaleFields(&$registrationType) {
00265       $this->updateDataObjectSettings('registration_type_settings', $registrationType, array(
00266          'type_id' => $registrationType->getTypeId()
00267       ));
00268    }
00269 
00275    function insertRegistrationType(&$registrationType) {
00276       $expiryDate = $registrationType->getExpiryDate();
00277       $this->update(
00278          sprintf('INSERT INTO registration_types
00279             (sched_conf_id, cost, currency_code_alpha, opening_date, closing_date, expiry_date, access, institutional, membership, pub, seq, code)
00280             VALUES
00281             (?, ?, ?, %s, %s, %s, ?, ?, ?, ?, ?, ?)',
00282             $this->dateToDB($registrationType->getOpeningDate()),
00283             $this->datetimeToDB($registrationType->getClosingDate()),
00284             $expiryDate === null?'null':$this->datetimeToDB($expiryDate)
00285          ), array(
00286             (int) $registrationType->getSchedConfId(),
00287             (float) $registrationType->getCost(),
00288             $registrationType->getCurrencyCodeAlpha(),
00289             (int) $registrationType->getAccess(),
00290             (int) $registrationType->getInstitutional(),
00291             (int) $registrationType->getMembership(),
00292             (int) $registrationType->getPublic(),
00293             (float) $registrationType->getSequence(),
00294             $registrationType->getCode()
00295          )
00296       );
00297 
00298       $registrationType->setTypeId($this->getInsertRegistrationTypeId());
00299       $this->updateLocaleFields($registrationType);
00300       return $registrationType->getTypeId();
00301    }
00302 
00308    function updateRegistrationType(&$registrationType) {
00309       $expiryDate = $registrationType->getExpiryDate();
00310       $returner = $this->update(
00311          sprintf('UPDATE registration_types
00312             SET
00313                sched_conf_id = ?,
00314                cost = ?,
00315                currency_code_alpha = ?,
00316                opening_date = %s,
00317                closing_date = %s,
00318                expiry_date = %s,
00319                access = ?,
00320                institutional = ?,
00321                membership = ?,
00322                pub = ?,
00323                seq = ?,
00324                code = ?
00325             WHERE type_id = ?',
00326             $this->dateToDB($registrationType->getOpeningDate()),
00327             $this->datetimeToDB($registrationType->getClosingDate()),
00328             $expiryDate === null?'null':$this->datetimeToDB($expiryDate)
00329          ), array(
00330             (int) $registrationType->getSchedConfId(),
00331             (float) $registrationType->getCost(),
00332             $registrationType->getCurrencyCodeAlpha(),
00333             (int) $registrationType->getAccess(),
00334             (int) $registrationType->getInstitutional(),
00335             (int) $registrationType->getMembership(),
00336             (int) $registrationType->getPublic(),
00337             (float) $registrationType->getSequence(),
00338             $registrationType->getCode(),
00339             (int) $registrationType->getTypeId()
00340          )
00341       );
00342       $this->updateLocaleFields($registrationType);
00343       return $returner;
00344    }
00345 
00351    function deleteRegistrationType(&$registrationType) {
00352       return $this->deleteRegistrationTypeById($registrationType->getTypeId());
00353    }
00354 
00361    function deleteRegistrationTypeById($typeId) {
00362       // Delete registration type
00363       $this->update(
00364          'DELETE FROM registration_types WHERE type_id = ?',
00365          array((int) $typeId)
00366       );
00367 
00368       // Delete all localization settings and registrations associated with this registration type
00369       $this->deleteRegistrationOptionCosts($typeId);
00370       $this->update('DELETE FROM registration_type_settings WHERE type_id = ?', $typeId);
00371 
00372       $registrationDao =& DAORegistry::getDAO('RegistrationDAO');
00373       return $registrationDao->deleteRegistrationByTypeId($typeId);
00374    }
00375 
00376    function deleteRegistrationTypesBySchedConf($schedConfId) {
00377       $registrationTypes =& $this->getRegistrationTypesBySchedConfId($schedConfId);
00378       while ($registrationType =& $registrationTypes->next()) {
00379          $this->deleteRegistrationType($registrationType);
00380          unset($registrationType);
00381       }
00382    }
00383 
00389    function &getRegistrationTypesBySchedConfId($schedConfId, $rangeInfo = null) {
00390       $result =& $this->retrieveRange(
00391          'SELECT * FROM registration_types WHERE sched_conf_id = ? ORDER BY seq',
00392          $schedConfId, $rangeInfo
00393       );
00394 
00395       $returner = new DAOResultFactory($result, $this, '_returnRegistrationTypeFromRow');
00396       return $returner;
00397    }
00398 
00403    function getInsertRegistrationTypeId() {
00404       return $this->getInsertId('registration_types', 'type_id');
00405    }
00406 
00410    function resequenceRegistrationTypes($schedConfId) {
00411       $result =& $this->retrieve(
00412          'SELECT type_id FROM registration_types WHERE sched_conf_id = ? ORDER BY seq',
00413          $schedConfId
00414       );
00415 
00416       for ($i=1; !$result->EOF; $i++) {
00417          list($registrationTypeId) = $result->fields;
00418          $this->update(
00419             'UPDATE registration_types SET seq = ? WHERE type_id = ?',
00420             array(
00421                $i,
00422                $registrationTypeId
00423             )
00424          );
00425 
00426          $result->moveNext();
00427       }
00428 
00429       $result->close();
00430       unset($result);
00431    }
00432 
00440    function insertRegistrationOptionCost($typeId, $optionId, $cost) {
00441       return $this->update(
00442          'INSERT INTO registration_option_costs
00443             (type_id, option_id, cost)
00444             VALUES
00445             (?, ?, ?)',
00446          array(
00447             (int) $typeId,
00448             (int) $optionId,
00449             $cost
00450          )
00451       );
00452    }
00453 
00459    function getRegistrationOptionCosts($typeId) {
00460       $result =& $this->retrieve(
00461          'SELECT option_id, cost FROM registration_option_costs WHERE type_id = ?',
00462          array((int) $typeId)
00463       );
00464       
00465       $returner = array();
00466       for ($i=1; !$result->EOF; $i++) {
00467          list($optionId, $cost) = $result->fields;
00468          $returner[$optionId] = $cost;
00469          $result->moveNext();
00470       }
00471 
00472       $result->close();
00473       unset($result);
00474       return $returner;
00475    }
00476 
00481    function deleteRegistrationOptionCosts($typeId) {
00482       return $this->update(
00483          'DELETE FROM registration_option_costs WHERE type_id = ?',
00484          array((int) $typeId)
00485       );
00486       
00487    }
00488 }
00489 
00490 ?>

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