fix get attributes
This commit is contained in:
parent
2c67108cf1
commit
ca27c47b75
@ -26,13 +26,40 @@ class User
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function setAttribute($name, $value, $id = 0)
|
||||||
|
{
|
||||||
|
if (!$id) {
|
||||||
|
$id = User::getID();
|
||||||
|
if (!$id) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$f = ORM::for_table('tbl_customers_fields')->where('field_name', $name)->where('customer_id', $id)->find_one();
|
||||||
|
if(!$f){
|
||||||
|
$f = ORM::for_table('tbl_customers_fields')->create();
|
||||||
|
$f->customer_id = $id;
|
||||||
|
$f->field_name = $name;
|
||||||
|
$f->field_value = $value;
|
||||||
|
$f->save();
|
||||||
|
$result = $f->id();
|
||||||
|
if ($result) {
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$f->field_value = $value;
|
||||||
|
$f->save();
|
||||||
|
return $f['id'];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public static function getAttribute($name, $id = 0)
|
public static function getAttribute($name, $id = 0)
|
||||||
{
|
{
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$id = User::getID();
|
$id = User::getID();
|
||||||
}
|
if (!$id) {
|
||||||
if (!$id) {
|
return [];
|
||||||
return '';
|
}
|
||||||
}
|
}
|
||||||
$f = ORM::for_table('tbl_customers_fields')->where('field_name', $name)->where('customer_id', $id)->find_one();
|
$f = ORM::for_table('tbl_customers_fields')->where('field_name', $name)->where('customer_id', $id)->find_one();
|
||||||
if ($f) {
|
if ($f) {
|
||||||
@ -45,12 +72,12 @@ class User
|
|||||||
{
|
{
|
||||||
if (!$id) {
|
if (!$id) {
|
||||||
$id = User::getID();
|
$id = User::getID();
|
||||||
}
|
if (!$id) {
|
||||||
if (!$id) {
|
return [];
|
||||||
return [];
|
}
|
||||||
}
|
}
|
||||||
$attrs = [];
|
$attrs = [];
|
||||||
$f = ORM::for_table('tbl_customers_fields')->where_like('field_name', $endWith)->where('customer_id', $id)->find_one();
|
$f = ORM::for_table('tbl_customers_fields')->where_like('field_name', "%$endWith")->where('customer_id', $id)->find_many();
|
||||||
if ($f) {
|
if ($f) {
|
||||||
foreach ($f as $k) {
|
foreach ($f as $k) {
|
||||||
$attrs[$k['field_name']] = $k['field_value'];
|
$attrs[$k['field_name']] = $k['field_value'];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user