NSOutLineView with nested NSArray - objective-c

I have nested n level dynamic array, i want to bind it with NSOutlineView,
but i not getting how to bind it with NSOutlineView using its four delegate methods.
Nested Array like :
(
{
id = 3;
summary = "req 1";
"sub_requirement" =
(
{
id = 16;
"sub_requirement" = "";
summary = "sub req 1";
}
);
},
{
id = 5;
summary = "req 1-1";
"sub_requirement" =
(
{
id = 17;
"sub_requirement" = "";
summary = "sub req 1-1";
},
{
id = 21;
"sub_requirement" = "";
summary = "req 1";
}
);
},
{
id = 7;
summary = "req 1 1";
"sub_requirement" =
(
{
approved = 1;
budget = 3600;
description = "";
estimate = 3600;
"fk_feature" = 4;
"fk_parent" = 7;
"fk_requirementtype" = 1;
id = 18;
"sub_requirement" = "";
summary = "sub req 11";
}
);
},
{
id = 8;
"sub_requirement" = "";
summary = "req 1 2";
},
{
id = 12;
"sub_requirement" = "";
summary = "req 1";
},
{
id = 14;
"sub_requirement" = "";
summary = req1;
}
)

You could use an NSTreeController, some links and tutorials available here.

Related

Optaplanner ScoreDirector continuous planning DayOff Request

I am trying to enable continuous planning and requests. I have tried to follow the computer example provided within the doco. Code below. I can see the values updated during debug. Code below. What am I doing wrong
public void addEmployeeDayOff(final Employee employee,final DayOffRequest dayOffRequest) {
logger.info("Scheduling employee dayoff ({}).", dayOffRequest);
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = scoreDirector.getWorkingSolution();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
DayOffRequest dayoffRequest = scoreDirector.lookUpWorkingObject(dayOffRequest);
scoreDirector.beforeProblemPropertyChanged(workingEmployee);
if (workingEmployee == null) {
return;
}
ArrayList<DayOffRequest> requestoffList = new ArrayList<>(nurseRoster.getDayOffRequestList());
nurseRoster.setDayOffRequestList(requestoffList);
scoreDirector.beforeProblemFactAdded(dayoffRequest);
workingEmployee.getDayOffRequestMap().put(dayoffRequest.getShiftDate(), dayoffRequest);
scoreDirector.afterProblemPropertyChanged(workingEmployee);
nurseRoster.getDayOffRequestList().add(dayoffRequest);
scoreDirector.afterProblemPropertyChanged(dayoffRequest);
scoreDirector.triggerVariableListeners();
});
The above is called from here:
List<DayOffRequest> dayOffRequestList;
//updating from database .. not sure if this is the issue
List<DayOffData> dayOffElementList = (List<DayOffData>) rosterService.listDayOffData();
dayOffRequestList = new ArrayList<>(dayOffElementList.size());
long nextdayoffId =0L;
for (DayOffData element : dayOffElementList) {
if (nextdayoffId <= element.getId()) {
nextdayoffId = element.getId() + 1L;
}
DayOffRequest dayOffRequest = new DayOffRequest();
String empID = element.getEmployee().getName();
int weight = element.getWeight();
LocalDate shiftDate = element.getShiftDate();
ShiftDate date1 = shiftDateMap.get(shiftDate);
Employee employee = employeeMap.get(empID);
dayOffRequest.setId(nextdayoffId);
dayOffRequest.setWeight(weight);
dayOffRequest.setEmployee(employee);
dayOffRequest.setShiftDate(date1);
dayOffRequestList.add(dayOffRequest);
//If this is not enabled the values don't pass to the addEmployeeDayOff method is this correct??
scoreDirector.afterProblemFactAdded(dayOffRequest);
scoreDirector.afterProblemFactAdded(employee);
addEmployeeDayOff(employee,dayOffRequest);
}
I found this worked but not sure if this is the correct way to approach the problem.
public void addEmployeeDayOff(final Employee employee, final DayOffRequest dayOffRequest) {
logger.info("Scheduling employee dayoff ({}).", dayOffRequest);
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = (NurseRoster) scoreDirector.getWorkingSolution();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
DayOffRequest dayoffRequest = (DayOffRequest) scoreDirector.lookUpWorkingObject(dayOffRequest);
scoreDirector.beforeProblemPropertyChanged(workingEmployee);
if (workingEmployee == null) {
return;
}
ArrayList<DayOffRequest> requestoffList = new ArrayList<>(nurseRoster.getDayOffRequestList());
nurseRoster.setDayOffRequestList(requestoffList);
scoreDirector.afterProblemFactAdded(requestoffList);
scoreDirector.afterProblemPropertyChanged(requestoffList);
ArrayList<Employee> beforeempList = new ArrayList<>(nurseRoster.getEmployeeList());
nurseRoster.setEmployeeList(beforeempList);
nurseRoster.getEmployeeList().remove(workingEmployee);
scoreDirector.beforeProblemFactRemoved(workingEmployee);
scoreDirector.afterProblemFactRemoved(workingEmployee);
ArrayList<Employee> empList = new ArrayList<>(nurseRoster.getEmployeeList());
nurseRoster.setEmployeeList(empList);
workingEmployee.getDayOffRequestMap().put(dayOffRequest.getShiftDate(), dayOffRequest);
nurseRoster.getEmployeeList().add(workingEmployee);
scoreDirector.beforeProblemFactAdded(workingEmployee);
scoreDirector.afterProblemFactAdded(workingEmployee);
scoreDirector.triggerVariableListeners();
});
I have uploaded the xml and Java file here https://github.com/rod182211/Optaplanner in to hope someone can advise why when I advance 14 days not all rule continue to apply. I assumed scoredirector only needed to be made aware of changes.
14 Day advance taking into account Requests via the below.
doProblemFactChange(scoreDirector -> {
NurseRoster nurseRoster = scoreDirector.getWorkingSolution();
NurseRosterParametrization nurseRosterParametrization = nurseRoster
.getNurseRosterParametrization();
List<ShiftDate> shiftDateList = nurseRoster.getShiftDateList();
Shift oldLastShift = nurseRoster.getShiftList()
.get(nurseRoster.getShiftList().size() - 1);
long shiftId = oldLastShift.getId() + 1L;
int shiftIndex = oldLastShift.getIndex() + 1;
ShiftDate oldLastShiftDate = shiftDateList
.get(shiftDateList.size() - 1);
long shiftDateId = (oldLastShiftDate.getId() + 1L);
int shiftDayIndex = (oldLastShiftDate.getDayIndex() + 1);
// long parmId = nurseRoster.getNurseRosterParametrization().getId()
// + 1L;
scoreDirector
.beforeProblemPropertyChanged(nurseRosterParametrization);
// Update to get the first day along with adding 14 days to the run
LocalDate startDate = (oldLastShiftDate.getDate().plusDays(1));
LocalDate endDate = (oldLastShiftDate.getDate().plusDays(14));
int maxDayIndex = Math.toIntExact(DAYS.between(startDate, endDate));
int shiftDateSize = maxDayIndex + 1;
List<ShiftDate> shiftDateList1 = new ArrayList<>(shiftDateSize);
shiftDateMap = new HashMap<>(shiftDateSize);
LocalDate date = startDate;
for (int i = 0; i < shiftDateSize; i++) {
ShiftDate shiftDate = new ShiftDate();
shiftDate.setId(shiftDateId);
shiftDate.setDayIndex(shiftDayIndex);
shiftDate.setDate(date);
shiftDate.setShiftList(new ArrayList<>());
shiftDateMap.put(date, shiftDate);
shiftDateId++;
shiftDayIndex++;
date = date.plusDays(1);
nurseRoster.getShiftDateList().add(shiftDate);
shiftDateList1.add(shiftDate);
scoreDirector.afterProblemFactAdded(shiftDate);
}
List<Skill> skillList;
List<Skill> skillElementList = (List<Skill>) nurseRoster
.getSkillList();
skillList = new ArrayList<>(skillElementList.size());
skillMap = new HashMap<>(skillElementList.size());
long id = 0L;
for (Skill element : skillElementList) {
Skill skill = new Skill();
skill.setId(id);
skill.setCode(element.getCode());
skillList.add(skill);
if (skillMap.containsKey(skill.getCode())) {
throw new IllegalArgumentException(
"There are 2 skills with the same code ("
+ skill.getCode() + ").");
}
skillMap.put(skill.getCode(), skill);
id++;
}
List<Contract> contractElementList = (List<Contract>) nurseRoster
.getContractList();
List<Contract> contractList = new ArrayList<>(
contractElementList.size());
contractMap = new HashMap<>(contractElementList.size());
for (Contract element : contractElementList) {
Contract contract = new Contract();
long Id = element.getId();
contract.setId(Id);
contract.setCode(element.getCode());
contract.setDescription(element.getDescription());
WeekendDefinition weekend = element.getWeekendDefinition();
contract.setWeekendDefinition(weekend);
contract.setContractLineList(new ArrayList<ContractLine>());
contractMap.put(contract.getCode(), contract);
contractList.add(contract);
}
List<ShiftTypeSkillRequirement> coverRequirementElementList = (List<ShiftTypeSkillRequirement>) nurseRoster
.getShiftTypeSkillRequirementList();
List<ShiftType> shiftTypeElementList = (List<ShiftType>) rosterService
.listShiftType();
List<ShiftType> shiftTypeList = new ArrayList<>(
shiftTypeElementList.size());
shiftTypeMap = new HashMap<>(shiftTypeElementList.size());
long Id = 0L;
int index = 0;
long shiftTypeSkillRequirementId = 0L;
List<ShiftTypeSkillRequirement> shiftTypeSkillRequirementList = new ArrayList<>(
shiftTypeElementList.size() * 2);
for (ShiftType element : shiftTypeElementList) {
ShiftType shiftType = new ShiftType();
shiftType.setId(Id);
shiftType.setCode(element.getCode());
shiftType.setIndex(index);
String startTimeString = element.getStartTimeString();
shiftType.setStartTimeString(startTimeString);
String endTimeString = element.getEndTimeString();
shiftType.setEndTimeString(endTimeString);
shiftType
.setNight(startTimeString.compareTo(endTimeString) > 0);
shiftType.setDescription(element.getDescription());
for (ShiftTypeSkillRequirement skillElement : coverRequirementElementList) {
ShiftTypeSkillRequirement shiftTypeSkillRequirement = new ShiftTypeSkillRequirement();
shiftTypeSkillRequirement
.setId(shiftTypeSkillRequirementId);
shiftTypeSkillRequirement.setShiftType(shiftType);
Skill skill = skillMap
.get(skillElement.getSkill().getCode());
if (skill == null) {
throw new IllegalArgumentException("The skill ("
+ skillElement.getSkill().getCode()
+ ") of shiftType (" + shiftType.getCode()
+ ") does not exist.");
}
shiftTypeSkillRequirement.setSkill(skill);
shiftTypeSkillRequirementList
.add(shiftTypeSkillRequirement);
shiftTypeSkillRequirementId++;
}
shiftTypeList.add(shiftType);
if (shiftTypeMap.containsKey(shiftType.getCode())) {
throw new IllegalArgumentException(
"There are 2 shiftTypes with the same code ("
+ shiftType.getCode() + ").");
}
shiftTypeMap.put(shiftType.getCode(), shiftType);
Id++;
index++;
}
nurseRoster.setShiftTypeList(shiftTypeList);
nurseRoster.setShiftTypeSkillRequirementList(
shiftTypeSkillRequirementList);
int shiftListSize = shiftDateMap.size() * shiftTypeList.size();
List<Shift> shiftList1 = new ArrayList<>(shiftListSize);
dateAndShiftTypeToShiftMap = new HashMap<>(shiftListSize);
dayOfWeekAndShiftTypeToShiftListMap = new HashMap<>(
7 * shiftTypeList.size());
for (ShiftDate shiftDate : shiftDateList1) {
for (ShiftType shiftType : shiftTypeList) {
Shift shift = new Shift();
shift.setId(shiftId);
shift.setShiftDate(shiftDate);
shiftDate.getShiftList().add(shift);
shift.setShiftType(shiftType);
shift.setIndex(shiftIndex);
shift.setRequiredEmployeeSize(0); // Filled in later
shiftList1.add(shift);
dateAndShiftTypeToShiftMap.put(
Pair.of(shiftDate.getDate(), shiftType.getCode()),
shift);
addShiftToDayOfWeekAndShiftTypeToShiftListMap(shiftDate,
shiftType, shift);
shiftId++;
shiftIndex++;
nurseRoster.getShiftList().add(shift);
scoreDirector.afterProblemFactAdded(shift);
}
}
List<DayOffRequest> dayOffRequestList;
List<DayOffRequest> requestList = (List<DayOffRequest>) nurseRoster.getDayOffRequestList();
DayOffRequest oldLastDayOff = requestList.get(requestList.size() - 1);
long DayOffId = (oldLastDayOff.getId() + 1l);
List<DayOffDate> dayOffElementList = rosterService.listDayOffDate();
dayOffRequestList = new ArrayList<>(dayOffElementList.size());
for (DayOffDate element : dayOffElementList) {
DayOffRequest dayOffRequest = new DayOffRequest();
int weight = element.getWeight();
LocalDate shiftDate = element.getDate();
ShiftDate date1 = shiftDateMap.get(shiftDate);
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
dayOffRequest.setId(DayOffId);
DayOffId++;
dayOffRequest.setWeight(weight);
dayOffRequest.setEmployee(workingEmployee);
dayOffRequest.setShiftDate(date1);
workingEmployee.getDayOffRequestMap().put(date1, dayOffRequest);
nurseRoster.getDayOffRequestList().add(dayOffRequest);
}
List<DayOnRequest> dayOnRequestList;
List<DayOnDate> dayOnElementList1 = rosterService.listDayOnDate();
dayOnRequestList = new ArrayList<>(dayOnElementList1.size());
for (DayOnDate element : dayOnElementList1) {
DayOnRequest dayOnRequest = new DayOnRequest();
long DayOnId = element.getId();
int weight = element.getWeight();
LocalDate localshiftDate = element.getDate();
ShiftDate dateon = shiftDateMap.get(localshiftDate);
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
dayOnRequest.setId(DayOnId);
dayOnRequest.setWeight(weight);
dayOnRequest.setEmployee(workingEmployee);
dayOnRequest.setShiftDate(dateon);
dayOnRequestList.add(dayOnRequest);
workingEmployee.getDayOnRequestMap().put(dateon, dayOnRequest);
nurseRoster.getDayOnRequestList().add(dayOnRequest);
}
List<ShiftOffRequest> shiftOffRequestList;
List<ShiftOffDate> shiftOffElementList = (List<ShiftOffDate>) rosterService.listShiftOffDate();
shiftOffRequestList = new ArrayList<>(shiftOffElementList.size());
for (ShiftOffDate element : shiftOffElementList) {
ShiftOffRequest shiftOffRequest = new ShiftOffRequest();
long ShiftonId = element.getId();
int weight = element.getWeight();
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
LocalDate date1 = element.getDate();
String shiftcode = element.getShiftType().getCode();
Shift shift = dateAndShiftTypeToShiftMap.get(Pair.of(date1, shiftcode));
shiftOffRequest.setId(ShiftonId);
shiftOffRequest.setEmployee(workingEmployee);
shiftOffRequest.setShift(shift);
shiftOffRequest.setWeight(weight);
shiftOffRequestList.add(shiftOffRequest);
workingEmployee.getShiftOffRequestMap().put(shift, shiftOffRequest);
nurseRoster.setShiftOffRequestList(shiftOffRequestList);
}
List<ShiftOnRequest> shiftOnRequestList;
List<ShiftOnDate> shiftOnElementList = (List<ShiftOnDate>) rosterService.listShiftOnDate();
shiftOnRequestList = new ArrayList<>(shiftOnElementList.size());
for (ShiftOnDate element : shiftOnElementList) {
ShiftOnRequest shiftOnRequest = new ShiftOnRequest();
long ShiftonId = element.getId();
int weight = element.getWeight();
Employee employee = element.getEmployee();
Employee workingEmployee = scoreDirector.lookUpWorkingObject(employee);
LocalDate date1 = element.getDate();
String shiftcode = element.getShiftType().getCode();
Shift shift = dateAndShiftTypeToShiftMap.get(Pair.of(date1, shiftcode));
shiftOnRequest.setId(ShiftonId);
shiftOnRequest.setEmployee(workingEmployee);
shiftOnRequest.setShift(shift);
shiftOnRequest.setWeight(weight);
shiftOnRequestList.add(shiftOnRequest);
workingEmployee.getShiftOnRequestMap().put(shift, shiftOnRequest);
nurseRoster.setShiftOnRequestList(shiftOnRequestList);
}
List<CoverRequirements> coverRequirementElementList1 = (List<CoverRequirements>) rosterService
.listCoverRequirements();
for (CoverRequirements element : coverRequirementElementList1) {
String type = element.getShiftType().getCode();
DayOfWeek day = element.getDayOfWeek();
int req = element.getRequiredEmployeesize();
ShiftType shiftType = shiftTypeMap.get(type);
Pair<DayOfWeek, ShiftType> key = Pair.of(day, shiftType);
List<Shift> shiftList = dayOfWeekAndShiftTypeToShiftListMap
.get(key);
for (Shift shift : shiftList) {
shift.setRequiredEmployeeSize(
shift.getRequiredEmployeeSize() + req);
}
}
List<ShiftAssignment> shiftAssignmentList = new ArrayList<>(
shiftList1.size());
long shiftAssignmentId = nurseRoster.getShiftAssignmentList()
.get(nurseRoster.getShiftAssignmentList().size() - 1)
.getId() + 1L;
for (Shift shift : shiftList1) {
for (int i = 0; i < shift.getRequiredEmployeeSize(); i++) {
ShiftAssignment newShiftAssignment = new ShiftAssignment();
newShiftAssignment.setId(shiftAssignmentId);
shiftAssignmentId++;
newShiftAssignment.setShift(shift);
newShiftAssignment.setIndexInShift(i);
shiftAssignmentList.add(newShiftAssignment);
nurseRoster.getShiftAssignmentList()
.add(newShiftAssignment);
scoreDirector.afterEntityAdded(newShiftAssignment);
}
}
//This should move the planning window
nurseRosterParametrization.setFirstShiftDate(shiftDateList1.get(0));
nurseRosterParametrization.setLastShiftDate(shiftDateList1.get(shiftDateList1.size() - 1));
nurseRosterParametrization.setPlanningWindowStart(shiftDateList1.get(0));
nurseRoster.setNurseRosterParametrization(nurseRosterParametrization);
scoreDirector.afterProblemPropertyChanged(nurseRosterParametrization);
scoreDirector.triggerVariableListeners();
}, true);
}

When I print array same object occurs in array please check.When I print obj then obj.dataArray contains same temp object occurs

Please check if I print obj then in data array same elements gets inserted twice instead of different. If n =2 then the first element gets pushed twice.
genLLEles(n, orgObj, homeSecObj, defaultElementObj, previousElements, socket) {
let that = this;
let arr = [];
let obj = {
dataArray: [],
socketId: socket.USER_ID,
requestId: "/sync#" + socket.id + socket.USER_ID + "#" + new Date().getTime(),
moduleName: "ORG",
action: "INSERT",
userId: socket.USER_ID
};
console.log("\n\ should be oce");
for (let i = 0; i < n; i++) { //n defines count of how many elements to be created
let temp = defaultElementObj; //selected object to insert
let _id = homeSecObj.KEY_VAL + "_TSK:" + defaultElementObj.SUB_KEY_TYPE + "_" + Date.now() + "_" + Math.floor(Math.random() * (10000 - 1)) + 1;
console.log(obj.dataArray.length);
if (obj.dataArray.length == 0) {
temp.CML_PREVIOUS_ID = previousElements.length <= 0 ? "-1" : that.getPreObj(previousElements).KEY_VAL;
temp.CML_NEXT_ID = "1";
temp.ORG_ID = orgObj.ORG_ID;
temp.DEPT_ID = orgObj.DEPT_ID;
temp.KEY_VAL = _id;
temp.CML_ID = _id;
temp.CML_REF_ID = homeSecObj.KEY_VAL;
temp.ACTIVE_STATUS = "1";
temp.CML_IMAGE_PATH = "";
temp.SYNC_PENDING_STATUS = "1";
} else {
obj.dataArray[obj.dataArray.length - 1].CML_NEXT_ID = _id;
console.log("HERE", obj.dataArray[obj.dataArray.length - 1]);
temp.CML_PREVIOUS_ID = obj.dataArray.length < 0 ? "-1" : obj.dataArray[obj.dataArray.length - 1].KEY_VAL;
temp.CML_NEXT_ID = "1";
temp.ORG_ID = orgObj.ORG_ID;
temp.DEPT_ID = orgObj.DEPT_ID;
temp.KEY_VAL = _id;
temp.CML_ID = _id;
temp.CML_REF_ID = homeSecObj.KEY_VAL;
temp.ACTIVE_STATUS = "1";
temp.CML_IMAGE_PATH = "";
temp.SYNC_PENDING_STATUS = "1";
}
obj.dataArray.push(temp);
}
console.log("\n\genLLEles ==> ", obj, "\n\n");
/*return obj;*/
}
from the above code, the values in both the if and else are coming from same parameters. So you are inserting the same values multiple times into the dataArray.

Calculate the price based on height and width

I need to make a module that allow the user to enter width and height , and then it should calculate the price based on the height and width .
thanks in advance
let's say that you want to do it on the product ID N° 1 from the product page :
first add two inputs fields in your product.tpl ( or in your module.tpl called in product.tpl)
<input name="height"><br>
<input name="width">
now you need to get it in your module.php to change the price dynamicly :
$id_product = 1;
$newPrice = 0;
$height = Tools::getValue('height');
$width = Tools::getValue('width');
//Price rules (change with your rules)
if($height > 10 && $width > 10) $newPrice = 10;
$specific_price = new SpecificPrice();
$specific_price->price = $newPrice;
$specific_price->id_cart = (int) $this->context->cart->id;
$specific_price->id_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = (int) $this->context->customer->id;
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = 0;
$specific_price->reduction_type = 'amount';
$specific_price->from = '0000-00-00 00:00:00';
$specific_price->to = '0000-00-00 00:00:00';
$specific_price->add();
and if you want add it to cart
$cart->id_lang = (int)($this->context->cookie->id_lang);
$cart->id_currency = (int)($this->context->cookie->id_currency);
$cart->updateQty($qte, $id_product);
and after order is done you put the normal price, so override the orderConfirmation controller in override/controllers/front/OrderConfirmationController.php:
class OrderConfirmationController extends OrderConfirmationControllerCore
{
public $ssl = true;
public $php_self = 'order-confirmation';
public $id_cart;
public $id_module;
public $id_order;
public $reference;
public $secure_key;
public function getPriceBack($id_product){
$normalPrice = Product::getPriceStatic($id_product);
$specific_price = new SpecificPrice();
$specific_price->price = $normalPrice;
$specific_price->id_cart = (int) $this->context->cart->id;
$specific_price->id_shop = 0;
$specific_price->id_shop_group = 0;
$specific_price->id_currency = 0;
$specific_price->id_country = 0;
$specific_price->id_group = 0;
$specific_price->id_customer = (int) $this->context->customer->id;
$specific_price->id_product = (int)$id_product;
$specific_price->id_product_attribute = 0;
$specific_price->from_quantity = 1;
$specific_price->reduction = 0;
$specific_price->reduction_type = 'amount';
$specific_price->from = '0000-00-00 00:00:00';
$specific_price->to = '0000-00-00 00:00:00';
$specific_price->add();
}
public function init()
{
parent::init();
$this->id_cart = (int)(Tools::getValue('id_cart', 0));
$is_guest = false;
/* get normal price back */
$id_product = 1;
self::getPriceBack($id_product);
/* check if the cart has been made by a Guest customer, for redirect link */
if (Cart::isGuestCartByCartId($this->id_cart)) {
$is_guest = true;
$redirectLink = 'index.php?controller=guest-tracking';
} else {
$redirectLink = 'index.php?controller=history';
}
$this->id_module = (int)(Tools::getValue('id_module', 0));
$this->id_order = Order::getOrderByCartId((int)($this->id_cart));
$this->secure_key = Tools::getValue('key', false);
$order = new Order((int)($this->id_order));
if ($is_guest) {
$customer = new Customer((int)$order->id_customer);
$redirectLink .= '&id_order='.$order->reference.'&email='.urlencode($customer->email);
}
if (!$this->id_order || !$this->id_module || !$this->secure_key || empty($this->secure_key)) {
Tools::redirect($redirectLink.(Tools::isSubmit('slowvalidation') ? '&slowvalidation' : ''));
}
$this->reference = $order->reference;
if (!Validate::isLoadedObject($order) || $order->id_customer != $this->context->customer->id || $this->secure_key != $order->secure_key) {
Tools::redirect($redirectLink);
}
$module = Module::getInstanceById((int)($this->id_module));
if ($order->module != $module->name) {
Tools::redirect($redirectLink);
}
}
}
after the order is done you have to empty the cart with id_product and delete rule in dbb :
$this->context->cart->deleteProduct(1);
Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'specific_price WHERE id_customer='.(int)$this->context->customer->id);
it s just an example and can not use without variables tests and maybe put constante for your product id concerned, hope it helps

How to view complete contents of NSUserDefaults [duplicate]

This question already has answers here:
See NSUserDefaults file content
(4 answers)
Closed 8 years ago.
I have an app where I store all of the user preferences in NSUserDefaults. I would like to be able to see (for debugging purposes) the complete contents of the NSUserDefaults file.
Can it be done without providing each of the keys?
Can it be done without providing each of the keys?
You can use dictionaryRepresentation of NSUserDefaults like that below example:-
NSUserDefaults *def=[NSUserDefaults standardUserDefaults];
[def setObject:#"test1" forKey:#"test1"];
[def setObject:#"test2" forKey:#"test2"];
NSLog(#"%#",[[NSUserDefaults standardUserDefaults]dictionaryRepresentation]);
EDIT:-
When use dictionaryRepresentation it will print the complete information of user default, including extra value which is added in the defaults.
Below is the output of above code. Also you can see the value in the last which is extra included in the user defaults :-
AppleAntiAliasingThreshold = 4;
AppleGCIdleTimeInterval = "1.0";
AppleLanguages = (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
es,
it,
nl,
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
ar,
th,
cs,
hu,
ca,
hr,
el,
he,
ro,
sk,
uk,
id,
ms,
vi
);
AppleLocale = "en_US";
AppleMeasurementUnits = Inches;
AppleMetricUnits = 0;
AppleMiniaturizeOnDoubleClick = 0;
AppleShowScrollBars = Always;
AppleTextDirection = 0;
AppleUserLanguages = 1;
Country = US;
MultipleSessionEnabled = 1;
NSBoldSystemFont = ".LucidaGrandeUI-Bold";
NSButtonDelay = "0.4";
NSButtonPeriod = "0.075";
NSDocumentRevisionsDebugMode = YES;
NSDragAutoscrollAreaWidth = "5.0";
NSDragCancelLimit = "100000.0";
NSDraggingAutoscrollDelay = "0.4";
NSEnableAutoCollapseOutlineDuringDragsDefault = NO;
NSEnableAutoExpandOutlineDuringDragsDefault = YES;
NSFixedPitchFont = "Menlo-Regular";
NSFixedPitchFontSize = 11;
NSFont = Helvetica;
NSFontSize = 12;
NSInputServerLaunchTimeout = 60;
NSInterfaceStyle = macintosh;
NSLanguages = (
en,
fr,
de,
"zh-Hans",
"zh-Hant",
ja,
es,
it,
nl,
ko,
pt,
"pt-PT",
da,
fi,
nb,
sv,
ru,
pl,
tr,
ar,
th,
cs,
hu,
ca,
hr,
el,
he,
ro,
sk,
uk,
id,
ms,
vi
);
NSMargins = "72 72 90 90";
NSMenuFlashCount = 3;
NSMenuScrollingOffset = 3;
NSMenuScrollingSpeed = 5;
NSNavPanelFileLastListModeForOpenModeKey = 1;
NSNavPanelFileListModeForOpenMode2 = 1;
NSNavPanelSidebarKeyForOpen = (
);
NSNavPanelSidebarKeyForSave = (
);
NSNavRecentPlaces = (
"~/Documents",
"~/Documents/sample Project/learning_iOS",
"~/Desktop/firstPage",
"~/Desktop/SoftwareDepotIssue",
"~/Desktop"
);
NSPreferredSpellServerVendors = {
English = "NeXT-OpenStep";
};
NSPreferredWebServices = {
NSWebServicesProviderWebSearch = {
NSDefaultDisplayName = Google;
NSProviderIdentifier = "com.google.www";
};
};
NSQuotedKeystrokeBinding = "^q";
NSRequireAutoCollapseOutlineAfterDropsDefault = NO;
NSResetIncrementalSearchOnFailure = YES;
NSScrollAnimationEnabled = YES;
NSScrollerButtonAcceleration = 8;
NSScrollerButtonDelay = "0.5";
NSScrollerButtonPeriod = "0.05";
NSScrollerHasSeparateArrows = YES;
NSScrollerKnobCount = 2;
NSScrollerKnobDelay = "0.001";
NSSmartCMYKColorConversion = YES;
NSSystemFont = ".LucidaGrandeUI";
NSSystemFontSize = 13;
NSUIHeartBeatCycle = "0.03";
NSUseCocoaInputServers = YES;
NSUserDictionaryReplacementItems = (
);
NSWindowResizeTime = ".20";
NavPanelFileListModeForOpenMode = 1;
SGTRecentFileSearches = (
{
attributes = (
kMDItemDisplayName
);
enforceStrictMatch = 0;
exactMatch = 0;
name = istsu;
scope = 4;
type = "com.apple.finder";
values = (
istsu
);
}
);
WebKitAVFoundationEnabled = 1;
WebKitAccelerated2dCanvasEnabled = 0;
WebKitAcceleratedCompositingEnabled = 1;
WebKitAcceleratedDrawingEnabled = 0;
WebKitAllowAnimatedImageLoopingPreferenceKey = 1;
WebKitAllowAnimatedImagesPreferenceKey = 1;
WebKitAllowFileAccessFromFileURLs = 1;
WebKitAllowUniversalAccessFromFileURLs = 1;
WebKitApplicationCacheDefaultOriginQuota = 9223372036854775807;
WebKitApplicationCacheTotalQuota = 9223372036854775807;
WebKitApplicationChromeModeEnabledPreferenceKey = 0;
WebKitAsynchronousSpellCheckingEnabled = 0;
WebKitAuthorAndUserStylesEnabledPreferenceKey = 1;
WebKitBackForwardCacheExpirationIntervalKey = 1800;
WebKitBackspaceKeyNavigationEnabled = 1;
WebKitCSSCompositingEnabled = 1;
WebKitCSSCustomFilterEnabled = 1;
WebKitCSSGridLayoutEnabled = 0;
WebKitCSSRegionsEnabled = 1;
WebKitCacheModelPreferenceKey = 0;
WebKitCanvasUsesAcceleratedDrawing = 0;
WebKitCursiveFont = "Apple Chancery";
WebKitDNSPrefetchingEnabled = 0;
WebKitDOMPasteAllowedPreferenceKey = 0;
WebKitDatabasesEnabledPreferenceKey = 1;
WebKitDefaultFixedFontSize = 13;
WebKitDefaultFontSize = 16;
WebKitDefaultTextEncodingName = "ISO-8859-1";
WebKitDeveloperExtrasEnabledPreferenceKey = 0;
WebKitDiagnosticLoggingEnabled = 0;
WebKitDisplayImagesKey = 1;
WebKitEditableLinkBehavior = 0;
WebKitEnableInheritURIQueryComponent = 0;
WebKitExperimentalNotificationsEnabledPreferenceKey = 0;
WebKitFantasyFont = Papyrus;
WebKitFixedFont = Courier;
WebKitFrameFlatteningEnabled = 0;
WebKitFullScreenEnabled = 0;
WebKitHiddenPageCSSAnimationSuspensionEnabled = 0;
WebKitHiddenPageDOMTimerThrottlingEnabled = 0;
WebKitHyperlinkAuditingEnabled = 1;
WebKitJavaEnabled = 1;
WebKitJavaScriptCanAccessClipboard = 0;
WebKitJavaScriptCanOpenWindowsAutomatically = 1;
WebKitJavaScriptEnabled = 1;
WebKitJavaScriptExperimentsEnabledPreferenceKey = 0;
WebKitKerningAndLigaturesEnabledByDefault = 1;
WebKitLoadSiteIconsKey = 0;
WebKitLocalFileContentSniffingEnabledPreferenceKey = 0;
WebKitLocalStorageEnabledPreferenceKey = 1;
WebKitLowPowerVideoAudioBufferSizeEnabled = 0;
WebKitMediaPlaybackAllowsInline = 1;
WebKitMediaPlaybackRequiresUserGesture = 0;
WebKitMinimumFontSize = 0;
WebKitMinimumLogicalFontSize = 9;
WebKitNotificationsEnabled = 1;
WebKitOfflineWebApplicationCacheEnabled = 0;
WebKitPDFDisplayMode = 1;
WebKitPDFScaleFactor = 0;
WebKitPageCacheSupportsPluginsPreferenceKey = 1;
WebKitPictographFont = "Apple Color Emoji";
WebKitPlugInSnapshottingEnabled = 0;
WebKitPluginsEnabled = 1;
WebKitPrivateBrowsingEnabled = 0;
WebKitQTKitEnabled = 1;
WebKitRegionBasedColumnsEnabled = 0;
WebKitRequestAnimationFrameEnabled = 1;
WebKitRespectStandardStyleKeyEquivalents = 0;
WebKitSansSerifFont = Helvetica;
WebKitScreenFontSubstitutionEnabled = 0;
WebKitSerifFont = Times;
WebKitShouldDisplayCaptions = 0;
WebKitShouldDisplaySubtitles = 0;
WebKitShouldDisplayTextDescriptions = 0;
WebKitShouldPrintBackgroundsPreferenceKey = 0;
WebKitShouldRespectImageOrientation = 0;
WebKitShowDebugBorders = 0;
WebKitShowRepaintCounter = 0;
WebKitShowsToolTipOverTruncatedText = 0;
WebKitShowsURLsInToolTips = 0;
WebKitShrinksStandaloneImagesToFit = 0;
WebKitSpatialNavigationEnabled = 0;
WebKitStandardFont = Times;
WebKitStorageBlockingPolicy = 0;
WebKitSuppressesIncrementalRendering = 0;
WebKitTabToLinksPreferenceKey = 0;
WebKitTextAreasAreResizable = 0;
WebKitTextDirectionSubmenuInclusionBehaviorPreferenceKey = 1;
WebKitUseLegacyTextAlignPositionedElementBehavior = 0;
WebKitUsePreHTML5ParserQuirks = 0;
WebKitUseSiteSpecificSpoofing = 0;
WebKitUserStyleSheetEnabledPreferenceKey = 0;
WebKitUserStyleSheetLocationPreferenceKey = "";
WebKitUsesEncodingDetector = 0;
WebKitUsesPageCachePreferenceKey = 1;
WebKitWantsBalancedSetDefersLoadingBehavior = 0;
WebKitWebArchiveDebugModeEnabledPreferenceKey = 0;
WebKitWebAudioEnabled = 0;
WebKitWebGLEnabled = 0;
WebKitWebSecurityEnabled = 1;
WebKitXSSAuditorEnabled = 1;
WebKitZoomsTextOnly = 1;
"com.apple.AppleModemSettingTool.LastCountryCode" = US;
"com.apple.ColorSync.Devices" = {
"Device.cmra.00000000-0000-0000-0000-000000533630" = {
DeviceDescriptions = {
"en_US" = "NO NAME";
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
"Device.cmra.30303441-3030-3930-4637-393830304637" = {
DeviceDescriptions = {
"en_US" = "Lumia 520";
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
"Device.cmra.37616133-3566-6339-6362-303662336639" = {
DeviceDescriptions = {
"en_US" = iPhone;
};
FactoryProfiles = {
555810816 = {
DeviceModeDescriptions = {
"en_US" = Default;
};
DeviceProfileURL = "/System/Library/Frameworks/ICADevices.framework/Versions/A/Resources/Camera RGB Profile.icc";
};
DeviceDefaultProfileID = 555810816;
};
};
};
"com.apple.TimeZonePref.Last_Selected_City" = (
"37.36883",
"-122.0363",
0,
"America/Los_Angeles",
US,
Sunnyvale,
"U.S.A.",
Sunnyvale,
"U.S.A.",
"DEPRECATED IN 10.6"
);
"com.apple.preferences.timezone.selected_city" = {
CountryCode = US;
GeonameID = 5400075;
Latitude = "37.36883";
LocalizedNames = {
ar = "\U0633\U0627\U0646\U064a\U0641\U064a\U0644";
ca = Sunnyvale;
cs = Sunnyvale;
da = Sunnyvale;
de = Sunnyvale;
el = Sunnyvale;
en = Sunnyvale;
es = Sunnyvale;
fi = Sunnyvale;
fr = Sunnyvale;
he = "\U05e1\U05d0\U05e0\U05d9\U05d5\U05d5\U05dc";
hr = Sunnyvale;
hu = Sunnyvale;
id = Sunnyvale;
it = Sunnyvale;
ja = "\U30b5\U30cb\U30fc\U30d9\U30fc\U30eb";
ko = "\Uc11c\Ub2c8\Ubca0\Uc77c";
ms = Sunnyvale;
nb = Sunnyvale;
nl = Sunnyvale;
pl = Sunnyvale;
pt = Sunnyvale;
"pt-PT" = Sunnyvale;
ro = Sunnyvale;
ru = "\U0421\U0430\U043d\U043d\U0438\U0432\U0435\U0439\U043b";
sk = Sunnyvale;
sv = Sunnyvale;
th = Sunnyvale;
tr = Sunnyvale;
uk = "\U0421\U0430\U043d\U043d\U0456\U0432\U0435\U0439\U043b";
vi = Sunnyvale;
"zh-Hans" = "\U6851\U5c3c\U7ef4\U5c14";
"zh-Hant" = "\U6851\U5c3c\U7dad\U723e";
};
Longitude = "-122.0363";
Name = Sunnyvale;
Population = 140081;
RegionalCode = CA;
TimeZoneName = "America/Los_Angeles";
Version = 1;
};
"com.apple.springing.delay" = "0.5";
"com.apple.springing.enabled" = 1;
"com.apple.trackpad.enableSecondaryClick" = 1;
"com.apple.trackpad.fiveFingerPinchSwipeGesture" = 2;
"com.apple.trackpad.fourFingerHorizSwipeGesture" = 2;
"com.apple.trackpad.fourFingerPinchSwipeGesture" = 2;
"com.apple.trackpad.fourFingerVertSwipeGesture" = 2;
"com.apple.trackpad.momentumScroll" = 1;
"com.apple.trackpad.pinchGesture" = 1;
"com.apple.trackpad.rotateGesture" = 1;
"com.apple.trackpad.scrollBehavior" = 2;
"com.apple.trackpad.threeFingerDragGesture" = 0;
"com.apple.trackpad.threeFingerHorizSwipeGesture" = 2;
"com.apple.trackpad.threeFingerTapGesture" = 2;
"com.apple.trackpad.threeFingerVertSwipeGesture" = 2;
"com.apple.trackpad.twoFingerDoubleTapGesture" = 1;
"com.apple.trackpad.twoFingerFromRightEdgeSwipeGesture" = 3;
"com.apple.trackpad.version" = 5;
"com.apple.updatesettings_did_disable_ftp" = 1;
test1 = test1;
test2 = test2;

How to extract data values and added to tableview

How to extract the data from the below data structure, and display on tableview
id = extractData
[extractData objectForKey:#"data"] //BELOW IS OUTPUT:
( {
Name = {
id = 2;
name = rat;
};
Place = {
id = 7;
name = New York;
};
Item = {
Times = "100";
“expire” = 10-19-2015;
“value” = 300;
id = 1;
name = newname;
“checked” = 0;
};
Type = {
id = 1;
name = round;
};
},
{
Name = {
id = 2;
name = norway;
};
Place = {
id = 3;
name = ops;
};
Item = {
Times = "100";
“expire” = 10-18-2015;
“value” = 300;
id = 1;
name = new;
“checked” = 1;
};
Type = {
id = 2;
name = square;
};
}
)
Want to display Name,Place,Item,Type values in tableview cell with each iterations.
Can any one advice, how can extract value from above data.
Under your cellForRowAtIndexPath after initializing the custom cell add this code :
NSDictionary *dicVal = [yourDataArray objectAtIndex:indexPath.row];
cell.labelName.text = [[dicVal objectForKey:#"Name"] objectForKey:#"name"];
cell.labelPlace.text = [[dicVal objectForKey:#"Place"] objectForKey:#"name"];
cell.labelItem.text = [[dicVal objectForKey:#"Item"] objectForKey:#"name"];
cell.labelType.text = [[dicVal objectForKey:#"Type"] objectForKey:#"name"];
return yourCustomCell;
This should do the work. Thanks.