Esempio n. 1
0
 /**
  * Update the survey, both in the database and in memory.
  *
  * @param array $values The values that this token should be set to
  * @param int $userId The current user
  * @return int 1 if data changed, 0 otherwise
  */
 private function _updateSurvey(array $values, $userId)
 {
     if ($this->tracker->filterChangesOnly($this->_gemsSurvey, $values)) {
         if (\Gems_Tracker::$verbose) {
             $echo = '';
             foreach ($values as $key => $val) {
                 $old = isset($this->_gemsSurvey[$key]) ? $this->_gemsSurvey[$key] : null;
                 $echo .= $key . ': ' . $old . ' => ' . $val . "\n";
             }
             \MUtil_Echo::r($echo, 'Updated values for ' . $this->_surveyId);
         }
         if (!isset($values['gsu_changed'])) {
             $values['gsu_changed'] = new \MUtil_Db_Expr_CurrentTimestamp();
         }
         if (!isset($values['gsu_changed_by'])) {
             $values['gsu_changed_by'] = $userId;
         }
         if ($this->exists) {
             // Update values in this object
             $this->_gemsSurvey = $values + $this->_gemsSurvey;
             // return 1;
             return $this->db->update('gems__surveys', $values, array('gsu_id_survey = ?' => $this->_surveyId));
         } else {
             if (!isset($values['gsu_created'])) {
                 $values['gsu_created'] = new \MUtil_Db_Expr_CurrentTimestamp();
             }
             if (!isset($values['gsu_created_by'])) {
                 $values['gsu_created_by'] = $userId;
             }
             // Update values in this object
             $this->_gemsSurvey = $values + $this->_gemsSurvey;
             // Remove the Gems survey id
             unset($this->_gemsSurvey['gsu_id_survey']);
             $this->_surveyId = $this->db->insert('gems__surveys', $this->_gemsSurvey);
             $this->_gemsSurvey['gsu_id_survey'] = $this->_surveyId;
             $this->exists = true;
             return 1;
         }
     } else {
         return 0;
     }
 }
 /**
  * Update the track, both in the database and in memory.
  *
  * @param array $values The values that this token should be set to
  * @param int $userId The current user
  * @return int 1 if data changed, 0 otherwise
  */
 private function _update(array $values, $userId)
 {
     if ($this->tracker->filterChangesOnly($this->_trackData, $values)) {
         if (\Gems_Tracker::$verbose) {
             $echo = '';
             foreach ($values as $key => $val) {
                 $echo .= $key . ': ' . $this->_trackData[$key] . ' => ' . $val . "\n";
             }
             \MUtil_Echo::r($echo, 'Updated values for ' . $this->_trackId);
         }
         if (!isset($values['gto_changed'])) {
             $values['gtr_changed'] = new \MUtil_Db_Expr_CurrentTimestamp();
         }
         if (!isset($values['gtr_changed_by'])) {
             $values['gtr_changed_by'] = $userId;
         }
         // Update values in this object
         $this->_trackData = $values + $this->_trackData;
         // return 1;
         return $this->db->update('gems__tracks', $values, array('gtr_id_track = ?' => $this->_trackId));
     } else {
         return 0;
     }
 }
 private function _updateTrack(array $values, $userId)
 {
     // \MUtil_Echo::track($values);
     if ($this->tracker->filterChangesOnly($this->_respTrackData, $values)) {
         $where = $this->db->quoteInto('gr2t_id_respondent_track = ?', $this->_respTrackId);
         if (\Gems_Tracker::$verbose) {
             $echo = '';
             foreach ($values as $key => $val) {
                 $echo .= $key . ': ' . $this->_respTrackData[$key] . ' => ' . $val . "\n";
             }
             \MUtil_Echo::r($echo, 'Updated values for ' . $this->_respTrackId);
         }
         if (!isset($values['gr2t_changed'])) {
             $values['gr2t_changed'] = new \MUtil_Db_Expr_CurrentTimestamp();
         }
         if (!isset($values['gr2t_changed_by'])) {
             $values['gr2t_changed_by'] = $userId;
         }
         $this->_respTrackData = $values + $this->_respTrackData;
         // \MUtil_Echo::track($values);
         // return 1;
         return $this->db->update('gems__respondent2track', $values, $where);
     } else {
         return 0;
     }
 }