Example #1
0
 /**
  * Delete a particular item from the model.
  * @param $params
  * @return unknown_type
  */
 public function delete($params)
 {
     if (User::getPermission($this->permissionPrefix . "_can_delete")) {
         $data = $this->model->getWithField($this->model->getKeyField(), $params[0]);
         $this->model->delete($this->model->getKeyField(), $params[0]);
         User::log("Deleted " . $this->model->name, $data[0]);
         Application::redirect("{$this->urlPath}?notification=Successfully+deleted+" . strtolower($this->label));
     }
 }
Example #2
0
 public function go()
 {
     $file = fopen($this->file, "r");
     $this->headers = fgetcsv($file);
     $this->modelInstance = Model::load($this->model)->setQueryResolve(false)->setQueryExplicitRelations(false);
     $this->setupFileFields();
     $this->primaryKey = $this->modelInstance->getKeyField();
     $this->tertiaryKey = $this->modelInstance->getKeyField("tertiary");
     $this->secondaryKey = $this->modelInstance->getKeyField('secondary');
     $this->modelInstance->datastore->beginTransaction();
     $this->line = 1;
     while (!feof($file)) {
         $this->line++;
         $data = fgetcsv($file);
         $this->modelData = array();
         $errors = array();
         if (!is_array($data)) {
             continue;
         }
         if ($this->setModelData($data, $errors)) {
             if (!$this->saveData()) {
                 $hasErrors = true;
                 break;
             }
         } else {
             if (count($errors) > 0) {
                 $this->statuses = array(array('success' => false, 'data' => $this->displayData, 'errors' => $errors));
             }
             $hasErrors = true;
             break;
         }
     }
     unlink($this->file);
     $return = array('statuses' => $this->statuses, 'headers' => $this->headers);
     if (!$hasErrors) {
         $return['message'] = 'Succesfully Imported';
         $return['added'] = $this->added;
         $return['updated'] = $this->updated;
         $this->modelInstance->datastore->endTransaction();
     } else {
         $return['message'] = 'Failed to import data';
         $return['failed'] = true;
         $return['errors'] = $this->flattenErrors($this->statuses[0]['errors']);
         $return['line'] = $this->line;
     }
     return $return;
 }
Example #3
0
 public function bulkdelete()
 {
     $this->model->delete("{$this->model->getKeyField('primary')} in (" . implode(",", json_decode($_GET['ids'])) . ")");
     Application::redirect($this->urlPath);
 }