Skip to content

Instantly share code, notes, and snippets.

@asika32764
Last active December 30, 2015 10:59
Show Gist options
  • Save asika32764/7819663 to your computer and use it in GitHub Desktop.
Save asika32764/7819663 to your computer and use it in GitHub Desktop.
Option Type Example
<?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