public function _searchOtherWay(RM_Barcode_Entity $obEntity, $restriction) { $orPart = array('query' => array(), 'binds' => array()); $query = M('Db')->createQuery($this->table('barcode'))->what('count(*) as qty'); foreach ($restriction as $key => $value) { if ($obEntity->type() . '_id' == $key) { $invert = 0; } else { $invert = 1; } if (is_array($value)) { $condition = ($invert ? ' not' : '') . ' in (' . sqlBinds($value) . ')'; } else { $condition = ($invert ? ' !' : '') . '=? '; } if (!$invert) { $query->where($this->fields('barcode', $key) . $condition, $value); } else { $orPart['query'][] = $this->fields('barcode', $key) . $condition; $orPart['binds'][] = $value; } } if ($orPart['query']) { $orRestriction = join(' or ', $orPart['query']); call_user_func_array(array($query, 'where'), array_merge(array('(' . $orRestriction . ')'), $orPart['binds'])); } foreach ($query->execute() as $row) { return $row['qty']; } return 0; }
/** * Moves barcodes * * @param RM_Barcode_Entity $obDestination * @param array $restriction * @return bool **/ public function move(RM_Barcode_Entity $obDestination, $restriction = array()) { if ($obDestination->id() == $this->id()) { return FALSE; } if ($this->stoplist) { if ($this->type() == 'generaltype') { throw new RM_Base_Exception_BadUsage(__METHOD__ . "(): Cannot move generaltype generaltype allocated in the stoplist!"); } } return $this->_mapper->moveBarcodes($this, $obDestination, $restriction); }