Created
February 12, 2015 09:17
-
-
Save atsu666/427b3404085993cac5fa to your computer and use it in GitHub Desktop.
acms fieldの組み立て
This file contains hidden or 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 | |
class ACMS_User_POST_Sample extends ACMS_POST | |
{ | |
public function post() | |
{ | |
$Field =& $this->extract('field', new ACMS_Validator()); | |
$this->saveField('eid', EID, $Field); | |
} | |
function saveField($type, $id, $Field=null, $deleteField=null) | |
{ | |
if ( empty($id) ) return false; | |
$DB = DB::singleton(dsn()); | |
$SQL = SQL::newDelete('field'); | |
$SQL->addWhereOpr('field_'.$type, $id); | |
if ( $Field && $Field->get('updateField') === 'on' ) { | |
$fkey = array(); | |
$Field->delete('updateField'); | |
foreach ( $Field->listFields() as $fd ) { | |
$fkey[] = $fd; | |
} | |
if ( $deleteField ) { | |
foreach ( $deleteField->listFields() as $fd ) { | |
$fkey[] = $fd; | |
} | |
} | |
$SQL->addWhereIn('field_key', $fkey); | |
} | |
$DB->query($SQL->get(dsn()), 'exec'); | |
if ( !empty($Field) ) { | |
foreach ( $Field->listFields() as $fd ) { | |
foreach ( $Field->getArray($fd, true) as $i => $val ) { | |
$SQL = SQL::newInsert('field'); | |
$SQL->addInsert('field_key', $fd); | |
$SQL->addInsert('field_value', $val); | |
$SQL->addInsert('field_sort', $i + 1); | |
$SQL->addInsert('field_search', $Field->getMeta($fd, 'search') ? 'on' : 'off'); | |
$SQL->addInsert('field_'.$type, $id); | |
$SQL->addInsert('field_blog_id', BID); | |
$DB->query($SQL->get(dsn()), 'exec'); | |
} | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment