/** * อ่านข้อมูลโมดูลจากชื่อโมดูล * * @param string $module * @param type $owner * @return object|false คืนค่าข้อมูล object ไม่พบ คืนค่า false */ public static function getModule($module, $owner) { if (is_string($module) && is_string($owner)) { $model = new \Kotchasan\Model(); $select = array('I.id', 'I.module_id', 'M.module', 'M.owner', 'D.topic', 'D.description', 'D.keywords', 'D.detail', 'I.visited'); $where = array(array('I.index', 1), array('M.module', $module), array('M.owner', $owner), array('I.published', 1), array('I.published_date', '<=', Date::mktimeToSqlDate(time())), array('D.language', array(Language::name(), ''))); return $model->db()->createQuery()->from('index I')->join('modules M', 'INNER', array('M.id', 'I.module_id'))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'M.id'), array('D.language', 'I.language')))->where($where)->cacheOn()->first($select); } return false; }
/** * อ่านหน้าเพจ * id = 0 สร้างหน้าใหม่ * * @param int $id * @param string $owner * @return object|null คืนค่า object ของข้อมูล ไม่พบคืนค่า null */ public static function getIndex($id, $owner) { if (is_int($id)) { if (empty($id)) { // ใหม่ $index = (object) array('owner' => $owner, 'id' => 0, 'published' => 1, 'module' => '', 'topic' => '', 'keywords' => '', 'description' => '', 'detail' => '', 'last_update' => 0, 'published_date' => Date::mktimeToSqlDate(), 'language' => ''); } else { // แก้ไข $model = new static(); $select = array('I.id', 'I.language', 'D.topic', 'D.keywords', 'D.description', 'D.detail', 'I.last_update', 'I.published', 'I.published_date', 'M.module', 'M.owner'); $index = $model->db()->createQuery()->select($select)->from('index I')->join('modules M', 'INNER', array(array('M.id', 'I.module_id')))->join('index_detail D', 'INNER', array(array('D.id', 'I.id'), array('D.module_id', 'I.module_id'), array('D.language', 'I.language')))->where(array(array('I.id', $id), array('I.index', 1)))->limit(1)->execute(); $index = sizeof($index) == 1 ? $index[0] : null; } return $index; } return null; }
/** * Generated from @assert (1453522271) [==] date('Y-m-d', 1453522271). * * @covers Kotchasan\Date::mktimeToSqlDate */ public function testMktimeToSqlDate() { $this->assertEquals(date('Y-m-d', 1453522271), \Kotchasan\Date::mktimeToSqlDate(1453522271)); }