Пример #1
0
 /**
  * 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");
     }
 }
Пример #2
0
 /**
  * Delete field
  *
  * @return NULL
  * @param $key string            
  *
  */
 function clear($key)
 {
     $keys = explode('.', $key);
     $first_key = $keys[0];
     if ($this->isPublic($first_key)) {
         \Dsc\ObjectHelper::clear($this, $key);
     }
     \Dsc\ArrayHelper::clear($this->__doc, $key);
     return $this;
 }