function delete($pk)
{
    if (!empty($pk)) {
        $user = new Model\User($pk);
        $user->delete();
    }
}
Exemplo n.º 2
0
 public function testDeleteByReference()
 {
     // Find user `2` and `3` and make sure they exists
     $user2 = Model\User::find(2);
     $user3 = Model\User::find(3);
     // Consist
     $this->assertInstanceOf('Gas\\ORM', $user2);
     $this->assertInstanceOf('Gas\\Data', $user2->record);
     $this->assertInstanceOf('Gas\\ORM', $user3);
     $this->assertInstanceOf('Gas\\Data', $user3->record);
     // Unset
     unset($user2, $user3);
     // Delete above users
     Model\User::delete(2, 3);
     // Find user `2` and `3` once more time
     $user2 = Model\User::find(2);
     $user3 = Model\User::find(3);
     // At this moment, user `2` and `3` should not exists anymore
     $this->assertEmpty($user2);
     $this->assertEmpty($user3);
 }
Exemplo n.º 3
0
 public function group_delete($f3, $params)
 {
     $group = new \Model\User();
     $group->load($params["id"]);
     $group->delete();
     if ($f3->get("AJAX")) {
         $this->_printJson(array("deleted" => 1) + $group->cast());
     } else {
         $f3->reroute("/admin/groups");
     }
 }
Exemplo n.º 4
0
 public function bulkapplyAction()
 {
     $success = 0;
     $message = '';
     $moremessage = '';
     //Extract & Refine ID List
     $idListTmp = explode(',', $this->postBag->get('ids'));
     $idList = array();
     foreach ($idListTmp as $id) {
         $id = trim($id);
         if (is_numeric($id) && !in_array($id, $idList)) {
             $idList[] = $id;
         }
     }
     $bulkaction = $this->postBag->get('bulkaction');
     if ($bulkaction != '' && count($idList) > 0 && Helper::checkSecurityToken()) {
         //check for delete
         if ($bulkaction == 'delete') {
             $delArr = $idList;
             $deletedItems = array();
             $cannotDeletedItems = array();
             foreach ($delArr as $id) {
                 $myUser = new \Model\User($id);
                 if ($myUser->id > 0 && $myUser->id != 1) {
                     //tien hanh xoa
                     if ($myUser->delete()) {
                         $deletedItems[] = $myUser->id;
                     } else {
                         $cannotDeletedItems[] = $myUser->id;
                     }
                 } else {
                     $cannotDeletedItems[] = $myUser->id;
                 }
             }
             if (count($deletedItems) > 0) {
                 $success = 1;
                 $moremessage .= '<successlist>';
                 foreach ($deletedItems as $id) {
                     $moremessage .= '<successitem>' . $id . '</successitem>';
                 }
                 $moremessage .= '</successlist>';
             }
             if (count($cannotDeletedItems) > 0) {
                 $moremessage .= '<faillist>';
                 foreach ($deletedItems as $id) {
                     $moremessage .= '<failitem>' . $id . '</failitem>';
                 }
                 $moremessage .= '</faillist>';
             }
         } else {
             //bulk action not select, show error
             $message = $this->registry->lang['default']['bulkActionInvalidWarn'];
         }
     } else {
         $message = $this->registry->lang['controller']['errNotFound'];
     }
     $this->registry->response->headers->set('Content-type', 'text/xml');
     $contents = '<?xml version="1.0" encoding="utf-8"?><result><success>' . $success . '</success><message>' . $message . '</message>' . $moremessage . '</result>';
     $this->registry->response->setContent($contents);
 }