public function getUnit() { if (empty($this->unit)) { $this->unit = \Pimcore\Model\Object\QuantityValue\Unit::getById($this->unitId); } return $this->unit; }
public function getUnit() { if (empty($this->unit)) { $this->unit = Unit::getById($this->unitId); } return $this->unit; }
/** * @return array */ public function load() { $units = array(); $unitIds = $this->db->fetchCol("SELECT id FROM " . Object\QuantityValue\Unit\Dao::TABLE_NAME . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit()); foreach ($unitIds as $id) { $units[] = Object\QuantityValue\Unit::getById($id); } $this->model->setUnits($units); return $units; }
public function unitProxyAction() { if ($this->getParam("data")) { if ($this->getParam("xaction") == "destroy") { $data = Zend_Json::decode($this->getParam("data")); $id = $data["id"]; $unit = \Pimcore\Model\Object\QuantityValue\Unit::getById($id); if (!empty($unit)) { $unit->delete(); $this->_helper->json(array("data" => array(), "success" => true)); } else { throw new Exception("Unit with id " . $id . " not found."); } } elseif ($this->getParam("xaction") == "update") { $data = Zend_Json::decode($this->getParam("data")); $unit = Pimcore\Model\Object\QuantityValue\Unit::getById($data['id']); if (!empty($unit)) { $unit->setValues($data); $unit->save(); $this->_helper->json(array("data" => get_object_vars($unit), "success" => true)); } else { throw new Exception("Unit with id " . $data['id'] . " not found."); } } elseif ($this->getParam("xaction") == "create") { $data = Zend_Json::decode($this->getParam("data")); unset($data['id']); $unit = new Pimcore\Model\Object\QuantityValue\Unit(); $unit->setValues($data); $unit->save(); $this->_helper->json(array("data" => get_object_vars($unit), "success" => true)); } } else { $list = new Pimcore\Model\Object\QuantityValue\Unit\Listing(); $list->setOrder("asc"); $list->setOrderKey("abbreviation"); if ($this->getParam("dir")) { $list->setOrder($this->getParam("dir")); } if ($this->getParam("sort")) { $list->setOrderKey($this->getParam("sort")); } $list->setLimit($this->getParam("limit")); $list->setOffset($this->getParam("start")); $condition = "1 = 1"; if ($this->getParam("filter")) { $filterString = $this->getParam("filter"); $filters = json_decode($filterString); $db = \Pimcore\Db::get(); foreach ($filters as $f) { if ($f->type == "string") { $condition .= " AND " . $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " LIKE " . $db->quote("%" . $f->value . "%"); } elseif ($f->type == "numeric") { $operator = $this->getOperator($f->comparison); $condition .= " AND " . $db->getQuoteIdentifierSymbol() . $f->field . $db->getQuoteIdentifierSymbol() . " " . $operator . " " . $db->quote($f->value); } } $list->setCondition($condition); } $list->load(); $units = array(); foreach ($list->getUnits() as $u) { $units[] = get_object_vars($u); } $this->_helper->json(array("data" => $units, "success" => true, "total" => $list->getTotalCount())); } }
/** * converts data to be imported via webservices * @param mixed $value * @return mixed */ public function getFromWebserviceImport($value) { if (empty($value)) { return null; } else { if ($value["value"] !== null && $value["unit"] !== null && $value["unitAbbreviation"] !== null) { $unit = Model\Object\QuantityValue\Unit::getById($value["unit"]); if ($unit && $unit->getAbbreviation() == $value["unitAbbreviation"]) { return new \Object_Data_QuantityValue($value["value"], $value["unit"]); } else { throw new Exception(get_class($this) . ": cannot get values from web service import - unit id and unit abbreviation do not match with local database"); } } else { throw new Exception(get_class($this) . ": cannot get values from web service import - invalid data"); } } }
/** * converts data to be imported via webservices * @param mixed $value * @param null|Model\Object\AbstractObject $object * @param mixed $params * @return mixed */ public function getFromWebserviceImport($value, $object = null, $params = [], $idMapper = null) { if (empty($value)) { return null; } else { $value = (array) $value; if ($value["value"] !== null && $value["unit"] !== null && $value["unitAbbreviation"] !== null) { $unitId = $value["unit"]; if ($idMapper) { $unitId = $idMapper->getMappedId("unit", $unitId); } $unit = Model\Object\QuantityValue\Unit::getById($unitId); if ($unit && $unit->getAbbreviation() == $value["unitAbbreviation"]) { return new \Pimcore\Model\Object\Data\QuantityValue($value["value"], $unitId); } else { throw new \Exception(get_class($this) . ": cannot get values from web service import - unit id and unit abbreviation do not match with local database"); } } else { throw new \Exception(get_class($this) . ": cannot get values from web service import - invalid data"); } } }