Pommo_Fields::optionDel PHP Method

optionDel() public method

returns field options (array), or false (bool)
public optionDel ( &$field, &$value )
    function optionDel(&$field, &$value)
    {
        $dbo =& Pommo::$_dbo;
        $logger =& Pommo::$_logger;
        // remove value from array
        $key = array_search($value, $field['array']);
        if (!is_numeric($key)) {
            $logger->addErr("Option ({$value}) does not exist in field_array", 1);
            return false;
        }
        unset($field['array'][$key]);
        $o = serialize($field['array']);
        $query = "\n            UPDATE " . $dbo->table['fields'] . "\n            SET field_array='%s'\n            WHERE field_id=%i";
        $query = $dbo->prepare($query, array($o, $field['id']));
        return $dbo->affected($query) > 0 ? $field['array'] : FALSE;
    }

Usage Example

コード例 #1
0
ファイル: fields.rpc.php プロジェクト: systemfirez/poMMo
 case 'delOption':
     // validate field ID
     $field = current(Pommo_Fields::get(array('id' => $_REQUEST['field_id'])));
     if ($field['id'] != $_REQUEST['field_id']) {
         die('bad field ID');
     }
     $affected = Pommo_Fields::subscribersAffected($field['id'], $_REQUEST['options']);
     if (count($affected) > 0 && empty($_REQUEST['confirmed'])) {
         $msg = sprintf(Pommo::_T('Deleting option %1$s will affect %2$s subscribers who have selected this choice. They will be flagged as needing to update their records.'), '<b>' . $_REQUEST['options'] . '</b>', '<em>' . count($affected) . '</em>');
         $msg .= "\n " . Pommo::_T('Are you sure?');
         $json->add('callbackFunction', 'confirm');
         $json->add('callbackParams', $msg);
         $json->serve();
     } else {
         require_once Pommo::$_baseDir . 'classes/Pommo_Subscribers.php';
         $options = Pommo_Fields::optionDel($field, $_REQUEST['options']);
         if (!options) {
             $json->fail(Pommo::_T('Error with deletion.'));
         }
         // flag subscribers for update
         if (count($affected) > 0) {
             Pommo_Subscribers::flagByID($affected);
         }
         $json->add('callbackFunction', 'updateOptions');
         $json->add('callbackParams', $options);
         $json->serve();
     }
     break;
 default:
     die('invalid request passed to ' . __FILE__);
     break;