Beispiel #1
2
 /**
  * getProfiles
  *
  * @return  \Windwalker\CCK\Form
  */
 public function getProfiles()
 {
     $catids = $this->state->get('params')->get('CoreRegistration_Categories', array());
     $catids = (array) $catids;
     if (in_array('*', $catids)) {
         $catids = null;
     }
     $fields = \Userxtd\Form\FormHelper::getFieldsByCategory($catids);
     return $fields;
 }
Beispiel #2
0
 /**
  * Utility method to act on a user after it has been saved.
  *
  * @param    array   $data    Holds the new user data.
  * @param    boolean $isNew   True if a new user is stored.
  * @param    boolean $result  True if user was succesfully stored in the database.
  * @param    string  $error   Message.
  *
  * @return   void
  */
 public function onUserAfterSave($data, $isNew, $result, $error = null)
 {
     $db = JFactory::getDbo();
     // don't do anything when activate.
     $allowTask = array('register', 'save', 'apply', 'save2new', 'user.edit.save');
     if (!in_array($this->input->get('task'), $allowTask)) {
         return;
     }
     // Init Framework
     // ===============================================================
     $this->initComponent();
     $UXParams = \Windwalker\System\ExtensionHelper::getParams('com_userxtd');
     // For Upload Event
     $this->user_data = $data;
     // Set Category
     $catid = $UXParams->get('CoreRegistration_Categories', array('*'));
     if (!is_array($catid)) {
         $catid = array($catid);
     }
     if (!in_array('*', $catid)) {
         $catid = implode(',', $catid);
     } else {
         $catid = null;
     }
     // Get Data and handle them
     $form = \Userxtd\Form\FormHelper::getFieldsByCategory($catid);
     $form->bind($data);
     $data['profile'] = $form->getDataForSave('profile');
     $userId = JArrayHelper::getValue($data, 'id', 0, 'int');
     // Start Building query
     // ===============================================================
     if ($userId && $result && isset($data['profile']) && count($data['profile'])) {
         try {
             //Sanitize the date
             // ===============================================================
             if (!empty($data['profile']['dob'])) {
                 $date = new JDate($data['profile']['dob']);
                 $data['profile']['dob'] = $date->format('Y-m-d');
             }
             $query = $db->getQuery(true);
             $query->delete('#__userxtd_profiles')->where('user_id = ' . $userId);
             $db->setQuery($query)->execute();
             $tuples = array();
             $order = 1;
             $query = $db->getQuery(true);
             $query->columns(array($query->qn('user_id'), $query->qn('key'), $query->qn('value'), $query->qn('ordering')));
             // Build query
             // ===============================================================
             foreach ($data['profile'] as $k => $v) {
                 if (is_array($v) || is_object($v)) {
                     $v = implode(',', (array) $v);
                 }
                 $query->values($userId . ', ' . $query->quote($k) . ', ' . $query->quote($v) . ', ' . $order++);
             }
             $query->insert('#__userxtd_profiles');
             $db->setQuery($query)->execute();
         } catch (RuntimeException $e) {
             $this->_subject->setError($e->getMessage());
             return;
         }
     }
     return;
 }