示例#1
0
 /**
  * Saves xref data
  * @param array
  * @return boolean true on success
  */
 function storeXref($data)
 {
     $user =& JFactory::getUser();
     $settings =& redEVENTHelper::config();
     // TODO : check user group access ?
     $row =& JTable::getInstance('RedEvent_eventvenuexref', '');
     if ($data['id']) {
         if (!$this->canManageXref($data['id'])) {
             $this->setError('YOU ARE NOT ALLOWED TO EDIT THIS DATE');
             return false;
         }
         $row->load($data['id']);
     } else {
         if (!$this->getCanAddXref()) {
             $this->setError('YOU ARE NOT ALLOWED TO ADD EVENT DATE');
             return false;
         }
     }
     if (!$row->bind($data)) {
         $this->setError('SUBMIT XREF ERROR BINDING DATA');
         RedeventHelperLog::simplelog('SUBMIT XREF ERROR BINDING DATA');
         return false;
     }
     if (!$row->check()) {
         $this->setError('SUBMIT XREF ERROR CHECK DATA');
         RedeventHelperLog::simplelog('SUBMIT XREF ERROR CHECK DATA');
         return false;
     }
     if (!$row->store(true)) {
         $this->setError('SUBMIT XREF ERROR STORE DATA');
         RedeventHelperLog::simplelog('SUBMIT XREF ERROR STORE DATA');
         return false;
     }
     /** roles **/
     // first remove current rows
     $query = ' DELETE FROM #__redevent_sessions_roles ' . ' WHERE xref = ' . $this->_db->Quote($row->id);
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // then recreate them if any
     foreach ((array) $data['rrole'] as $k => $r) {
         if (!($data['rrole'][$k] && $data['urole'][$k])) {
             continue;
         }
         $new =& JTable::getInstance('RedEvent_sessions_roles', '');
         $new->set('xref', $row->id);
         $new->set('role_id', $r);
         $new->set('user_id', $data['urole'][$k]);
         if (!($new->check() && $new->store())) {
             $this->setError($new->getError());
             return false;
         }
     }
     /** roles END **/
     /** prices **/
     // first remove current rows
     $query = ' DELETE FROM #__redevent_sessions_pricegroups ' . ' WHERE xref = ' . $this->_db->Quote($row->id);
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // then recreate them if any
     foreach ((array) $data['pricegroup'] as $k => $r) {
         if (!$data['pricegroup'][$k]) {
             continue;
         }
         $new =& JTable::getInstance('RedEvent_sessions_pricegroups', '');
         $new->set('xref', $row->id);
         $new->set('pricegroup_id', $r);
         $new->set('price', $data['price'][$k]);
         if (!($new->check() && $new->store())) {
             $this->setError($new->getError());
             return false;
         }
     }
     /** prices END **/
     // we need to save the recurrence too
     $recurrence =& JTable::getInstance('RedEvent_recurrences', '');
     if (!isset($data['recurrenceid']) || !$data['recurrenceid']) {
         $rrule = RedeventHelperRecurrence::parsePost($data);
         if (!empty($rrule)) {
             // new recurrence
             $recurrence->rrule = $rrule;
             if (!$recurrence->store()) {
                 $this->setError($recurrence->getError());
                 return false;
             }
             // add repeat record
             $repeat =& JTable::getInstance('RedEvent_repeats', '');
             $repeat->set('xref_id', $row->id);
             $repeat->set('recurrence_id', $recurrence->id);
             $repeat->set('count', 0);
             if (!$repeat->store()) {
                 $this->setError($repeat->getError());
                 return false;
             }
         }
     } else {
         if ($data['repeat'] == 0) {
             $recurrence->load($data['recurrenceid']);
             // reset the status
             $recurrence->ended = 0;
             // TODO: maybe add a check to have a choice between updating rrule or not...
             $rrule = RedeventHelperRecurrence::parsePost($data);
             $recurrence->rrule = $rrule;
             if (!$recurrence->store()) {
                 $this->setError($recurrence->getError());
                 return false;
             }
         }
     }
     if ($recurrence->id) {
         redEVENTHelper::generaterecurrences($recurrence->id);
     }
     return true;
 }
示例#2
0
 /**
  * save xref data
  *
  * @param array $data
  * @return boolean true on success
  */
 function savexref($data)
 {
     $id = (int) $data['id'];
     $object =& JTable::getInstance('RedEvent_eventvenuexref', '');
     if ($id) {
         $object->load($id);
     }
     if (!$object->bind($data)) {
         $this->setError($object->getError());
         return false;
     }
     if (!$object->check()) {
         $this->setError($object->getError());
         return false;
     }
     if (!$object->store(true)) {
         $this->setError($object->getError());
         return false;
     }
     // we need to save the recurrence too
     $recurrence =& JTable::getInstance('RedEvent_recurrences', '');
     if (!$data['recurrenceid']) {
         $rrule = RedeventHelperRecurrence::parsePost($data);
         if (!empty($rrule)) {
             // new recurrence
             $recurrence->rrule = $rrule;
             if (!$recurrence->store()) {
                 $this->setError($recurrence->getError());
                 return false;
             }
             // add repeat record
             $repeat =& JTable::getInstance('RedEvent_repeats', '');
             $repeat->set('xref_id', $object->id);
             $repeat->set('recurrence_id', $recurrence->id);
             $repeat->set('count', 0);
             if (!$repeat->store()) {
                 $this->setError($repeat->getError());
                 return false;
             }
         }
     } else {
         if ($data['repeat'] == 0) {
             $recurrence->load($data['recurrenceid']);
             // reset the status
             $recurrence->ended = 0;
             // TODO: maybe add a check to have a choice between updating rrule or not...
             $rrule = RedeventHelperRecurrence::parsePost($data);
             $recurrence->rrule = $rrule;
             if (!$recurrence->store()) {
                 $this->setError($recurrence->getError());
                 return false;
             }
         }
     }
     if ($recurrence->id) {
         redEVENTHelper::generaterecurrences($recurrence->id);
     }
     /** roles **/
     // first remove current rows
     $query = ' DELETE FROM #__redevent_sessions_roles ' . ' WHERE xref = ' . $this->_db->Quote($object->id);
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // then recreate them if any
     foreach ((array) $data['rrole'] as $k => $r) {
         if (!($data['rrole'][$k] && $data['urole'][$k])) {
             continue;
         }
         $new =& JTable::getInstance('RedEvent_sessions_roles', '');
         $new->set('xref', $object->id);
         $new->set('role_id', $r);
         $new->set('user_id', $data['urole'][$k]);
         if (!($new->check() && $new->store())) {
             $this->setError($new->getError());
             return false;
         }
     }
     /** roles END **/
     /** prices **/
     // first remove current rows
     $query = ' DELETE FROM #__redevent_sessions_pricegroups ' . ' WHERE xref = ' . $this->_db->Quote($object->id);
     $this->_db->setQuery($query);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // then recreate them if any
     foreach ((array) $data['pricegroup'] as $k => $r) {
         if (!$data['pricegroup'][$k]) {
             continue;
         }
         $new =& JTable::getInstance('RedEvent_sessions_pricegroups', '');
         $new->set('xref', $object->id);
         $new->set('pricegroup_id', $r);
         $new->set('price', $data['price'][$k]);
         if (!($new->check() && $new->store())) {
             $this->setError($new->getError());
             return false;
         }
     }
     /** prices END **/
     return $object->id;
 }