delete() public method

Delete an item
See also: PodsAPI::delete_pod_item
Since: 2.0
public delete ( integer $id = null ) : boolean
$id integer ID of the Pod item to delete
return boolean Whether the item was successfully deleted
Esempio n. 1
0
 /**
  * @param null $id
  *
  * @return bool|mixed
  */
 public function delete_bulk()
 {
     $this->do_hook('pre_delete_bulk');
     if (1 != pods_var('deleted_bulk', 'get', 0)) {
         $ids = $this->bulk;
         $success = false;
         if (!empty($ids)) {
             $ids = (array) $ids;
             foreach ($ids as $id) {
                 $id = pods_absint($id);
                 if (empty($id)) {
                     continue;
                 }
                 if (isset($this->actions_custom['delete']) && is_callable($this->actions_custom['delete'])) {
                     $check = call_user_func_array($this->actions_custom['delete'], array($id, &$this));
                     if (false !== $check) {
                         $check = true;
                     }
                 } elseif (is_object($this->pod)) {
                     $check = $this->pod->delete($id);
                 } else {
                     $check = $this->pods_data->delete($this->table, array($this->data->field_id => $id));
                 }
                 if ($check) {
                     $success = true;
                 }
             }
         }
         if ($success) {
             pods_redirect(pods_var_update(array('action_bulk' => 'delete', 'deleted_bulk' => 1), array('page', 'lang', 'action', 'id')));
         } else {
             $this->error(__("<strong>Error:</strong> {$this->item} has not been deleted.", 'pods'));
         }
     } else {
         $this->message(__("<strong>Deleted:</strong> {$this->items} have been deleted.", 'pods'));
         unset($_GET['deleted_bulk']);
     }
     $this->action_bulk = false;
     unset($_GET['action_bulk']);
     $this->do_hook('post_delete_bulk');
     $this->manage();
 }
 /**
  * @param null $id
  *
  * @return bool|mixed
  */
 public function delete_bulk()
 {
     $this->do_hook('pre_delete_bulk');
     if (1 != pods_var('deleted_bulk', 'get', 0)) {
         $ids = $this->bulk;
         $success = false;
         if (!empty($ids)) {
             $ids = (array) $ids;
             foreach ($ids as $id) {
                 $id = pods_absint($id);
                 if (empty($id)) {
                     continue;
                 }
                 if ($callback = $this->callback('delete', $id)) {
                     $check = $callback;
                 } elseif (is_object($this->pod)) {
                     $check = $this->pod->delete($id);
                 } else {
                     $check = $this->pods_data->delete($this->sql['table'], array($this->sql['field_id'] => $id));
                 }
                 if ($check) {
                     $success = true;
                 }
             }
         }
         if ($success) {
             pods_redirect(pods_query_arg(array('action_bulk' => 'delete', 'deleted_bulk' => 1), array('page', 'lang', 'action', 'id')));
         } else {
             $this->error(sprintf(__("<strong>Error:</strong> %s has not been deleted.", 'pods'), $this->item));
         }
     } else {
         $this->message(sprintf(__("<strong>Deleted:</strong> %s have been deleted.", 'pods'), $this->items));
         unset($_GET['deleted_bulk']);
     }
     $this->action_bulk = false;
     unset($_GET['action_bulk']);
     $this->do_hook('post_delete_bulk');
     $this->manage();
 }