/** * @param ilTemplate $tpl */ public function insert(ilTemplate $tpl) { /** * @var $lng ilLanguage */ global $lng; $local_tpl = new ilTemplate('tpl.prop_tos_signed_document.html', true, true, 'Services/TermsOfService'); require_once 'Services/UIComponent/Modal/classes/class.ilModalGUI.php'; $modal = ilModalGUI::getInstance(); $modal->setHeading($lng->txt('tos_agreement_document')); $modal->setId('accepted_tos_' . $this->entity->getUserId()); $modal->setBody($this->entity->getText()); require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php'; $local_tpl->setVariable('MODAL_TRIGGER_HTML', ilGlyphGUI::get(ilGlyphGUI::SEARCH)); $local_tpl->setVariable('MODAL', $modal->getHTML()); $local_tpl->setVariable('MODAL_ID', 'accepted_tos_' . $this->entity->getUserId()); $tpl->setCurrentBlock('prop_generic'); $tpl->setVariable('PROP_GENERIC', $local_tpl->get()); $tpl->parseCurrentBlock(); }
/** * @param ilTermsOfServiceAcceptanceEntity $entity */ public function trackAcceptance(ilTermsOfServiceAcceptanceEntity $entity) { $query = 'SELECT id FROM tos_versions WHERE hash = %s AND lng = %s'; $res = $this->db->queryF($query, array('text', 'text'), array($entity->getHash(), $entity->getIso2LanguageCode())); if ($this->db->numRows($res)) { $row = $this->db->fetchAssoc($res); $tosv_id = $row['id']; } else { $tosv_id = $this->db->nextId('tos_versions'); $this->db->insert('tos_versions', array('id' => array('integer', $tosv_id), 'lng' => array('text', $entity->getIso2LanguageCode()), 'src' => array('text', $entity->getSource()), 'src_type' => array('integer', $entity->getSourceType()), 'text' => array('clob', $entity->getText()), 'hash' => array('text', $entity->getHash()), 'ts' => array('integer', $entity->getTimestamp()))); } $this->db->insert('tos_acceptance_track', array('tosv_id' => array('integer', $tosv_id), 'usr_id' => array('integer', $entity->getUserId()), 'ts' => array('integer', $entity->getTimestamp()))); }
/** * */ public function testAcceptanceIsTrackedAndRefersToAnExistingTermsOfServicesVersion() { $entity = new ilTermsOfServiceAcceptanceEntity(); $entity->setUserId(666); $entity->setIso2LanguageCode('de'); $entity->setSource('/path/to/file'); $entity->setSourceType(0); $entity->setText('PHP Unit'); $entity->setTimestamp(time()); $entity->setHash(md5($entity->getText())); $expected_id = 4711; $database = $this->getMockBuilder('ilDB')->disableOriginalConstructor()->getMock(); $result = $this->getMockBuilder('MDB2_BufferedResult_mysqli')->disableOriginalConstructor()->getMock(); $database->expects($this->once())->method('queryF')->with('SELECT id FROM tos_versions WHERE hash = %s AND lng = %s', array('text', 'text'), array($entity->getHash(), $entity->getIso2LanguageCode()))->will($this->returnValue($result)); $database->expects($this->once())->method('numRows')->with($result)->will($this->returnValue(1)); $database->expects($this->once())->method('fetchAssoc')->with($result)->will($this->returnValue(array('id' => $expected_id))); $expectedTracking = array('tosv_id' => array('integer', $expected_id), 'usr_id' => array('integer', $entity->getUserId()), 'ts' => array('integer', $entity->getTimestamp())); $database->expects($this->once())->method('insert')->with('tos_acceptance_track', $expectedTracking); $gateway = new ilTermsOfServiceAcceptanceDatabaseGateway($database); $gateway->trackAcceptance($entity); }
/** * */ public function testEntityShouldReturnTextWhenTextIsSet() { $expected = 'Lorem Ipsum'; $entity = new ilTermsOfServiceAcceptanceEntity(); $entity->setText($expected); $this->assertEquals($expected, $entity->getText()); }