public function replaceInText(RM_Anketa_Entity_Question $obQuestion, RM_Anketa_iRespondent $obRespondent, $obResult = NULL) { if (!strpos($obQuestion->text, '%')) { return $obQuestion->text; } $now = M('Date')->dbDate(); if (!isNull($obResult)) { if ($obResult->isComplete()) { $now = $obResult->end_time; } } $now_month_year = D($now, 'text-month-year'); $replaces = array('%START_YEAR%' => D(M('Date')->add($now, '-11m'), 'text-month-year'), '%END_YEAR%' => $now_month_year, '%START_LAST_6_MONTH%' => D(M('Date')->add($now, '-6m'), 'text-month-year'), '%END_LAST_6_MONTH%' => $now_month_year, '%NOW_MONTH%' => $now_month_year, '%USER_NAME%' => $obRespondent->getRespondentName()); return str_replace(array_keys($replaces), array_values($replaces), $obQuestion->text); }
/** * Returns anketa result by anketa and respondent * * @param RM_Anketa_Entity_Object obAnketa * @param RM_Anketa_iRespondent obRespondent * @return RM_Anketa_Result_Object **/ public function getResult(RM_Anketa_Entity_Object $obAnketa, RM_Anketa_iRespondent $obRespondent) { return $this->_mapper->storage('result')->loadObjectByKey('anketa_respondent', array($obAnketa->id(), $obRespondent->getRespondentId())); }
/** * Creates (not save) anketa result object * * @param RM_Anketa_Entity_Object obAnketa * @param RM_Anketa_iRespondent obRespondent * @return RM_Anketa_Result_Object **/ public function createResult(RM_Anketa_Entity_Object $obAnketa, RM_Anketa_iRespondent $obRespondent) { if ($obAnketa->respondent_type !== $obRespondent->getRespondentType()) { throw new RM_Base_Exception_BadUsage(__METHOD__ . "(): inappropriate respondent type. `" . $obAnketa->respondent_type . "` expected, `" . $obRespondent->getRespondentType() . "` given."); } $data = array(); $data['anketa_id'] = $obAnketa->id(); $data['respondent_id'] = $obRespondent->getRespondentId(); $data['respondent_type'] = $obRespondent->getRespondentType(); if (!isset($data['begin_time'])) { $data['begin_time'] = M('Date')->dbDateTime(); } return $this->_storages['result']->createObject($data); }