コード例 #1
0
ファイル: event.php プロジェクト: JKoelman/JEM-3
 /**
  * Method to save the form data.
  *
  * @param $data array
  */
 public function save($data)
 {
     $date = JFactory::getDate();
     $app = JFactory::getApplication();
     $jinput = $app->input;
     $user = JFactory::getUser();
     $jemsettings = JEMHelper::config();
     $settings = JemHelper::globalattribs();
     $veditevent = JemHelper::viewSettings('veditevent');
     $fileFilter = new JInput($_FILES);
     $table = $this->getTable();
     # Check if we're in the front or back
     if ($app->isAdmin()) {
         $backend = true;
     } else {
         $backend = false;
     }
     $cats = $data['cats'];
     $data['author_ip'] = $jinput->getString('author_ip');
     ## Recurrence - check option ##
     # if the option to hide the recurrence/other tab has been set (front) then
     # we should ignore the recurrence variables.
     $option_othertab = $veditevent->get('editevent_show_othertab');
     if ($option_othertab) {
         $hide_othertab = false;
     } else {
         $hide_othertab = true;
     }
     if ($backend || $hide_othertab == false) {
         ##############
         ## HOLIDAYS ##
         ##############
         if (isset($data['activated'])) {
             if ($data['activated'] == null) {
                 $holidays = array();
             } else {
                 $holidays = $data['activated'];
             }
         } else {
             $holidays = array();
         }
         $countryholiday = $jinput->getInt('recurrence_country_holidays', '');
         ################
         ## RECURRENCE ##
         ################
         # check if a startdate has been set
         if (isset($data['dates'])) {
             if ($data['dates'] == null) {
                 $dateSet = false;
             } else {
                 $dateSet = true;
             }
         } else {
             $dateSet = false;
         }
         if (!isset($data['recurrence_freq'])) {
             $data['recurrence_freq'] = 0;
         }
         # implode weekday values
         # @todo implement check to see if days have been selected in case of freq week
         if (isset($data['recurrence_weekday'])) {
             $data['recurrence_weekday'] = implode(',', $data['recurrence_weekday']);
         }
         # blank recurrence-fields
         #
         # if we don't have a startdate or a recurrence-type then
         # the recurrence-fields within the event-table will be blanked.
         #
         # but the recurrence_group field will stay filled as it's not removed by the user.
         if (empty($data['dates']) || $data['recurrence_freq'] == '0') {
             $data['recurrence_count'] = '';
             $data['recurrence_freq'] = '';
             $data['recurrence_interval'] = '';
             $data['recurrence_until'] = '';
             $data['recurrence_weekday'] = '';
             $data['recurrence_exdates'] = '';
         }
         # the exdates are not stored in the event-table but they are trown in an variable
         if (isset($data['recurrence_exdates'])) {
             $exdates = $data['recurrence_exdates'];
         } else {
             $exdates = false;
         }
     }
     # parent-Save
     if (parent::save($data)) {
         // At this point we do have an id.
         $pk = $this->getState($this->getName() . '.id');
         if (isset($data['featured'])) {
             $this->featured($pk, $data['featured']);
         }
         $checkAttachName = $jinput->post->get('attach-name', '', 'array');
         if ($checkAttachName) {
             # attachments, new ones first
             $attachments = array();
             $attachments = $fileFilter->get('attach', array(), 'array');
             $attachments['customname'] = $jinput->post->get('attach-name', array(), 'array');
             $attachments['description'] = $jinput->post->get('attach-desc', array(), 'array');
             $attachments['access'] = $jinput->post->get('attach-access', array(), 'array');
             JEMAttachment::postUpload($attachments, 'event' . $pk);
             # and update old ones
             $old = array();
             $old['id'] = $jinput->post->get('attached-id', array(), 'array');
             $old['name'] = $jinput->post->get('attached-name', array(), 'array');
             $old['description'] = $jinput->post->get('attached-desc', array(), 'array');
             $old['access'] = $jinput->post->get('attached-access', array(), 'array');
             foreach ($old['id'] as $k => $id) {
                 $attach = array();
                 $attach['id'] = $id;
                 $attach['name'] = $old['name'][$k];
                 $attach['description'] = $old['description'][$k];
                 $attach['access'] = $old['access'][$k];
                 JEMAttachment::update($attach);
             }
         }
         # Store categories
         $cats = $data['cats'];
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->delete($db->quoteName('#__jem_cats_event_relations'));
         $query->where('itemid = ' . $pk);
         $db->setQuery($query);
         $db->execute();
         foreach ($cats as $cat) {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             // Insert columns.
             $columns = array('catid', 'itemid');
             // Insert values.
             $values = array($cat, $pk);
             // Prepare the insert query.
             $query->insert($db->quoteName('#__jem_cats_event_relations'))->columns($db->quoteName($columns))->values(implode(',', $values));
             // Reset the query using our newly populated query object.
             $db->setQuery($query);
             $db->execute();
         }
         if ($backend || $hide_othertab == false) {
             # check for recurrence
             # when part of a recurrence_set it will not perform the generating function
             /*
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('id');
             $query->from($db->quoteName('#__jem_recurrence'));
             $query->where(array('exdate IS NULL','itemid ='.$pk));
             $db->setQuery($query);
             $recurrence_set = $db->loadResult();
             */
             $table->load($pk);
             # check recurrence
             if ($table->recurrence_group) {
                 # this event is part of a recurrence-group
                 #
                 # check for groupid & groupid_ref (recurrence_table)
                 # - groupid		= $item->recurrence_group
                 # - groupid_ref	= $item->recurrence_group
                 # - Itemid		= $item->id
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select(array('count(id)'));
                 $query->from('#__jem_recurrence');
                 $query->where(array('groupid= ' . $table->recurrence_group, 'itemid= ' . $pk, 'groupid = groupid_ref'));
                 $db->setQuery($query);
                 $rec_groupset_check = $db->loadResult();
                 if ($rec_groupset_check == '1') {
                     $recurrence_set = true;
                 } else {
                     $recurrence_set = false;
                 }
             } else {
                 $recurrence_set = false;
             }
             ## check values, pass check before we continue to generate additional events ##
             # - do we have an interval?
             # - does the event has a date?
             # - is the event part of a recurrenceset?
             if ($table->recurrence_interval > 0 && !$table->dates == null && $recurrence_set == null) {
                 # recurrence_interval is bigger then 0
                 # we do have a startdate
                 # the event is not part of a recurrence-set
                 # we passed the check but now we'll pass some variables to the generating functions
                 # exdates: the dates filled
                 # table: the row info
                 if ($this->state->task == 'apply' || $this->state->task == 'save') {
                     JemHelper::generate_events($table, $exdates, $holidays);
                 }
             }
         }
         return true;
     }
     return false;
 }