Esempio n. 1
0
 public function pushEach($fieldName, array $values)
 {
     // value must be list, not dictionary
     $values = array_values($values);
     // prepasre to store
     $values = Structure::prepareToStore($values);
     // no $push operator found
     if (!isset($this->operators['$push'])) {
         $this->operators['$push'] = array();
     }
     // no field name found
     if (!isset($this->operators['$push'][$fieldName])) {
         $this->operators['$push'][$fieldName] = array('$each' => $values);
     } else {
         if (!is_array($this->operators['$push'][$fieldName]) || !isset($this->operators['$push'][$fieldName]['$each'])) {
             $oldValue = $this->operators['$push'][$fieldName];
             $this->operators['$push'][$fieldName] = array('$each' => array_merge(array($oldValue), $values));
         } else {
             $this->operators['$push'][$fieldName]['$each'] = array_merge($this->operators['$push'][$fieldName]['$each'], $values);
         }
     }
     return $this;
 }