public function addElement($table, $obj) { $isAdd = true; $ele = new $table(); if (class_exists("ProVersion")) { $pro = new ProVersion(); $subscriptionTables = $pro->getSubscriptionTables(); if (in_array($table, $subscriptionTables)) { $resp = $pro->subscriptionCheck($obj); if ($resp->getStatus() != IceResponse::SUCCESS) { return $resp; } } } if (!empty($obj['id'])) { $isAdd = false; $ele->Load('id = ?', array($obj['id'])); } foreach ($obj as $k => $v) { if ($k == 'id' || $k == 't' || $k == 'a') { continue; } if ($v == "NULL") { $v = null; } $ele->{$k} = $v; } if (empty($obj['id'])) { if (in_array($table, $this->userTables)) { $cemp = $this->getCurrentProfileId(); if (!empty($cemp)) { $signInMappingField = SIGN_IN_ELEMENT_MAPPING_FIELD_NAME; $ele->{$signInMappingField} = $cemp; } else { return new IceResponse(IceResponse::ERROR, "Profile id is not set"); } } } $this->checkSecureAccess("save", $ele); $resp = $ele->validateSave($ele); if ($resp->getStatus() != IceResponse::SUCCESS) { return $resp; } if ($isAdd) { if (empty($ele->created)) { $ele->created = date("Y-m-d H:i:s"); } } if (empty($ele->updated)) { $ele->updated = date("Y-m-d H:i:s"); } if ($isAdd) { $ele = $ele->executePreSaveActions($ele)->getData(); } else { $ele = $ele->executePreUpdateActions($ele)->getData(); } $ok = $ele->Save(); if (!$ok) { $error = $ele->ErrorMsg(); LogManager::getInstance()->info($error); if ($isAdd) { $this->audit(IceConstants::AUDIT_ERROR, "Error occured while adding an object to " . $table . " \\ Error: " . $error); } else { $this->audit(IceConstants::AUDIT_ERROR, "Error occured while editing an object in " . $table . " [id:" . $ele->id . "] \\ Error: " . $error); } return new IceResponse(IceResponse::ERROR, $this->findError($error)); } if ($isAdd) { $ele->executePostSaveActions($ele); $this->audit(IceConstants::AUDIT_ADD, "Added an object to " . $table . " [id:" . $ele->id . "]"); } else { $ele->executePostUpdateActions($ele); $this->audit(IceConstants::AUDIT_EDIT, "Edited an object in " . $table . " [id:" . $ele->id . "]"); } return new IceResponse(IceResponse::SUCCESS, $ele); }
public function addElement($table, $obj) { $isAdd = true; $ele = new $table(); if ($table == "Employee") { if (class_exists("ProVersion")) { $pro = new ProVersion(); $resp = $pro->subscriptionCheck($obj); if ($resp->getStatus() != IceResponse::SUCCESS) { return $resp; } } } if (!empty($obj['id'])) { $isAdd = false; $ele->Load('id = ?', array($obj['id'])); } foreach ($obj as $k => $v) { if ($k == 'id' || $k == 't' || $k == 'a') { continue; } if ($v == "NULL") { $v = null; } $ele->{$k} = $v; } if (empty($obj['id'])) { if (in_array($table, $this->userTables)) { $cemp = $this->getCurrentEmployeeId(); if (!empty($cemp)) { $ele->employee = $cemp; } else { return new IceResponse(IceResponse::ERROR, "Employee id is not set"); } } } $this->checkSecureAccess("save", $ele); $resp = $ele->validateSave($ele); if ($resp->getStatus() != IceResponse::SUCCESS) { return $resp; } if ($isAdd) { if (empty($ele->created)) { $ele->created = date("Y-m-d H:i:s"); } } if (empty($ele->updated)) { $ele->updated = date("Y-m-d H:i:s"); } $ok = $ele->Save(); if (!$ok) { $error = $ele->ErrorMsg(); error_log($error); if ($isAdd) { $this->audit(IceConstants::AUDIT_ERROR, "Error occured while adding an object to " . $table . " \\ Error: " . $error); } else { $this->audit(IceConstants::AUDIT_ERROR, "Error occured while editing an object in " . $table . " [id:" . $ele->id . "] \\ Error: " . $error); } return new IceResponse(IceResponse::ERROR, $this->findError($error)); } if ($isAdd) { $this->audit(IceConstants::AUDIT_ADD, "Added an object to " . $table . " [id:" . $ele->id . "]"); } else { $this->audit(IceConstants::AUDIT_EDIT, "Edited an object in " . $table . " [id:" . $ele->id . "]"); } return new IceResponse(IceResponse::SUCCESS, $ele); }