/** * This method returns update clause which will be later on passed to collection * * @param $data Data from request * @param $params Arrays with possible additional params (for different modes of updater * * @return Based on mode of updater, either update clause or updated document */ public function getUpdateClause($data, $params = array()) { // check required parameters if (!$this->checkParams($params)) { return null; } $data = $this->inputFilter()->clean($data, "string"); switch ($this->attribute->getUpdaterMode()) { case 0: throw new \Exception("Unsupported mode for this operation in Mass Update"); break; case 1: $doc = $params['document']; $name_with_idx = $this->getNameWithIdx(); $dataset = $params['dataset']; $attr_collection = $this->attribute->getAttributeCollection(); $name_type = $name_with_idx . '_type'; $name_op = $name_with_idx . '_operation'; // cant find type => skip this if (empty($dataset[$name_type]) || empty($dataset[$name_op])) { return null; } $act_data = \Dsc\ArrayHelper::get($doc, $attr_collection); $res = ''; $type = $dataset[$name_type]; $op = $dataset[$name_op]; switch ($op) { case '+': $res = $this->handleAdding($type, $act_data, $data); break; case '-': $res = $this->handleRemoving($type, $act_data, $data); break; default: $res = $act_data; break; } \Dsc\ObjectHelper::set($doc, $attr_collection, $res); return $doc; default: throw new \Exception("Unknown type of operation in Mass Update"); } }
/** * Assign value to field * * @return scalar FALSE * @param $key string * @param $val scalar * */ function set($key, $val) { if (!property_exists($this, $key) || $this->isPublic($key)) { \Dsc\ObjectHelper::set($this, $key, $val); } \Dsc\ArrayHelper::set($this->__doc, $key, $val); return $this; }