/** * อ่านข้อมูลหมวดหมู่ที่เลือก และสามารถเผยแพร่ได้ * * @param int $category_id * @param int $module_id * @return object|null ข้อมูลที่เลือก (Object) หรือ null หากไม่พบ */ public static function get($category_id, $module_id) { if (is_int($category_id) && is_int($module_id)) { $model = new static(); $query = $model->db()->createQuery()->select()->from('category')->where(array(array('category_id', $category_id), array('module_id', $module_id), array('published', '1')))->limit(1); foreach ($query->toArray()->execute() as $item) { $item['topic'] = Gcms::ser2Str($item, 'topic'); $item['detail'] = Gcms::ser2Str($item, 'detail'); $item['icon'] = Gcms::ser2Str($item, 'icon'); return (object) ArrayTool::unserialize($item['config'], $item); } } return null; }
/** * Generated from @assert (serialize(array(1 => 'One', 2 => 'Two', 3 => 'Three')), array(3 => 3, 4 => 'Four'), false) [==] array(1 => 'One', 2 => 'Two', 3 => 3, 4 => 'Four'). * * @covers Kotchasan\ArrayTool::unserialize */ public function testUnserialize4() { $this->assertEquals(array(1 => 'One', 2 => 'Two', 3 => 3, 4 => 'Four'), \Kotchasan\ArrayTool::unserialize(serialize(array(1 => 'One', 2 => 'Two', 3 => 'Three')), array(3 => 3, 4 => 'Four'), false)); }
/** * action ของตารางหมวดหมู่ */ public function action() { // referer, session, member if (self::$request->initSession() && self::$request->isReferer() && ($login = Login::isAdmin())) { if ($login['email'] == 'demo') { echo Language::get('Unable to complete the transaction'); } else { // รับค่าจากการ POST $id = self::$request->post('id')->toString(); $value = self::$request->post('value')->toInt(); if (preg_match('/^category_([0-9]+)$/', $id, $match)) { $action = 'category'; $module_id = (int) $match[1]; } else { $action = self::$request->post('action')->toString(); $module_id = self::$request->post('mid')->toInt(); } // ตรวจสอบโมดูล $index = false; if (!empty($module_id)) { $index = \Index\Module\Model::getModule($module_id); } if ($action === 'category') { // อ่านข้อมูลหมวดหมู่ตอนเขียนบทความ $category = $this->db()->first($this->getFullTableName('category'), array(array('category_id', (int) $value), array('module_id', (int) $index->id))); if ($category) { $config = @unserialize($category->config); if (!is_array($config)) { $config = array('can_reply' => 0); } $ret = array('can_reply' => empty($config['can_reply']) ? 0 : 1, 'published' => empty($category->published) ? 0 : 1); // คืนค่าเป็น JSON echo json_encode($ret); } } elseif ($index && Gcms::canConfig($login, $index, 'can_config')) { if ($action === 'delete' && preg_match('/^[0-9,]+$/', $id)) { // ลบหมวด $query = $this->db()->createQuery()->select('id', 'icon')->from('category')->where(array(array('id', explode(',', $id)), array('module_id', $index->id)))->toArray(); $ids = array(); foreach ($query->execute() as $item) { $ids[] = $item['id']; foreach (ArrayTool::unserialize($item['icon']) as $icon) { @unlink(ROOT_PATH . DATA_FOLDER . $item['owner'] . '/' . $icon); } } if (!empty($ids)) { // ลบหมวดหมู่ $this->db()->createQuery()->delete('category', array(array('id', $ids), array('module_id', $index->id)))->execute(); } } else { $category = $this->db()->first($this->getFullTableName('category'), array(array('id', (int) $id), array('module_id', (int) $index->id))); if ($category) { if ($action === 'categoryid') { // แก้ไข category_id หน้ารายการหมวดหมู่ // ค้นหาหมวดหมู่ซ้ำ $search = $this->db()->createQuery()->from('category')->where(array(array('module_id', (int) $index->id), array('category_id', $value)))->first('id'); if ($search) { // มี category_id อยู่ก่อนแล้วคืนค่ารายการเดิม $ret['categoryid_' . $index->id . '_' . $category->id] = $category->category_id; } else { // save $this->db()->createQuery()->update('category')->set(array('category_id' => $value))->where((int) $category->id)->execute(); // คืนค่ารายการใหม่ $ret['categoryid_' . $index->id . '_' . $category->id] = $value; } } elseif ($action === 'published' || $action === 'can_reply') { // เผยแพร่, การแสดงความคิดเห็น if ($action === 'can_reply') { $config = @unserialize($category->config); if (!is_array($config)) { $config = array(); } $config['can_reply'] = empty($config['can_reply']) ? 1 : 0; $save = array('config' => serialize($config)); // คืนค่า $ret['elem'] = 'can_reply_' . $category->id; $lng = Language::get('REPLIES'); $ret['title'] = $lng[$config['can_reply']]; $ret['class'] = 'icon-reply reply' . $config['can_reply']; } else { $save = array('published' => $category->published == 1 ? 0 : 1); // คืนค่า $ret['elem'] = 'published_' . $category->id; $lng = Language::get('PUBLISHEDS'); $ret['title'] = $lng[$save['published']]; $ret['class'] = 'icon-published' . $save['published']; } $this->db()->update($this->getFullTableName('category'), $category->id, $save); } // คืนค่าเป็น JSON echo json_encode($ret); } } } } } else { echo Language::get('Unable to complete the transaction'); } }
/** * อ่านข้อมูลโมดูลจาก $module และ $owner * * @param string $owner * @param string $module * @param int $module_id * @return object|false คืนค่าข้อมูลโมดูล (Object) ไม่พบคืนค่า false */ public static function get($owner, $module, $module_id = 0) { // Model $model = new static(); if (empty($module_id)) { $where = array(array('module', $module), array('owner', $owner)); } else { $where = array(array('id', (int) $module_id), array('owner', $owner)); } $module = $model->db()->createQuery()->from('modules')->where($where)->toArray()->cacheOn()->first('id module_id', 'module', 'config'); if ($module) { $module = ArrayTool::unserialize($module['config'], $module); unset($module['config']); return (object) $module; } return false; }