Last active
December 30, 2015 10:59
-
-
Save asika32764/7819663 to your computer and use it in GitHub Desktop.
Option Type Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class OptionTypeHelper | |
{ | |
static public function add($value, $text, $type = 'location') | |
{ | |
$db = JFactory::getDbo(); | |
$obj = new Stdclass; | |
$obj->value = $value; | |
$obj->text = $text; | |
// 動態指定 Table | |
return $db->insertObject('#__paycare_option_' . $type, $obj); | |
} | |
static public function getList($type = 'location') | |
{ | |
// Get option list. | |
$db = JFactory::getDbo(); | |
$query = $db->getQuery(true); | |
$query->select('#__paycare_option_' . $type); | |
return $db->setQuery($query)->loadObjectList(); | |
} | |
static public function getItem($condition, $type = 'location') | |
{ | |
if (!is_array($condition)) | |
{ | |
$condition = array('id' => (int) $condition); | |
} | |
// Get option by condition. | |
$db = JFactory::getDbo(); | |
$query = $db->getQuery(true); | |
$query->select('#__paycare_option_' . $type); | |
foreach ($condition as $key => $val) | |
{ | |
$query->where($query->qn($key) . '=' . $query->quote($val)); | |
} | |
return $db->setQuery($query, 1)->loadObject(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment