/** * Loads script by name * * @param string $name Script name * @return RM_ReportScript_iScript */ public function loadScriptByName($name) { if (!$name) { return M('Base')->null(); } return iterFirst($this->storage('script')->getObjectList()->filter('name=?', $name)); }
/** * Merges and saves leaves (объединить пересекающиеся отпуска). * * @return bool */ public function mergeLeaves() { $request = $this->getLeaveIntersections(); if ($request->count() > 0) { $request1 = clone $request; $minObLeave = iterFirst($request->sort('date_from', 'ASC')); $maxObLeave = iterFirst($request1->sort('date_to', 'DESC')); $update_arr = array(); if (strtotime($minObLeave->date_from) < strtotime($this->date_from)) { $update_arr['date_from'] = $minObLeave->date_from; } if (strtotime($maxObLeave->date_to) > strtotime($this->date_to)) { $update_arr['date_to'] = $maxObLeave->date_to; } unset($request1); // сначала надо удалить старые отпуска $deleted_leaves = array(); foreach ($request as $item) { $deleted_leaves[$item->id()] = $item; $item->delete(); } // обновить даты начала и окончания отпуска $this->update($update_arr); // вернуть массив id удаленных отпусков return $deleted_leaves; } return FALSE; }
public function process(array $data, $field, RM_Base_iResult $result) { if (!isNull(iterFirst(M('Category')->getCategoryList()->filter('name=? and id!=?', $data[$field], $data['id'])))) { $result->error('name_not_unique', $field); return FALSE; } return TRUE; }
public function searchValueIntoAttribute(RM_Gpc_Attribute_Object $obAttribute, $value_name) { $obValue = M('Base')->null(); foreach (M('Gpc')->getValueList()->filter(L(NULL) . '_name = ?', $value_name)->sort('id', 'DESC') as $obValue) { if (!isNull(iterFirst($obAttribute->getValues()->filter('id = ?', $obValue->id())->sort('id')))) { break; } } return $obValue; }
/** * @see RM_Holder_Invoice_item_State::execute() */ public function execute() { $obInvoice = $this->_getExistsInvoiceOrCreate(); $obInvoice->addEntity($this->_obItem->getEntity()); $newItem = iterFirst($obInvoice->getItemsList()->filter('entity_id = ?', $this->_obItem->entity_id)); $newItem->addDescription('Недостающая часть для накладной №' . $this->_obItem->getInvoice()->number); $newItem->save(); $this->_obItem->addDescription('Недостающая часть в накладной №' . $obInvoice->number); $this->_obItem->save(); }
/** * Enter description here... * * @return string */ public function getSizeAsString() { $type = M('User')->getPetNameByAnimalType($this->_obFamily->animal_type); if (in_array($type, array('cat', 'dog'))) { if (!isNull($obj = iterFirst(M('Store')->requestQuery(M('Store')->factoryObject(), M('Db')->createQuery(M('user')->table($type . '_size'))->what('*')->where('id = ?', $this->_obFamily->animal_weight_id))))) { return $obj->name; } } return ''; }
/** * @see RM_Holder_Invoice_Item_State::execute() */ public function execute() { $this->_obItem->changeState(RM_Holder_Invoice_Item_State::KIT); $obBackInvoice = $this->_getExistsInvoiceOrCreate(RM_Holder_Invoice_Item_State::BACK); $obBackInvoice->addEntity($this->_obItem->getEntity()); $backItem = iterFirst($obBackInvoice->getItemsList()->filter('entity_id = ?', $this->_obItem->entity_id)); $obOldInvoice = $this->_obItem->getInvoice(); $backItem->descr .= 'Возврат из накладной №' . $obOldInvoice->number; $backItem->save(); return TRUE; }
public function process(array $data, $field, RM_Base_iResult $result) { $iterator = M('Purchase')->getPurchaseList()->filter('user_id=? and bdate=? and check_id=? and is_deleted=0 and shop_id!=?', $data['user_id'], $data['bdate'], $data['check_id'], $data['shop_id']); if ($data['id']) { $iterator->filter('id!=?', $data['id']); } if ($data['shop_id'] < 1 || isNull(iterFirst($iterator))) { return TRUE; } $result->error('shop_not_the_same', $field); return FALSE; }
public function process(array $data, $field, RM_Base_iResult $result) { $search = M('Purchase')->getPurchaseList()->filter('user_id=? and bdate=? and receipt_id=? and is_deleted=0 and barcode_value=?', $data['user_id'], $data['bdate'], $data['receipt_id'], $data['barcode_value']); if ($data['id']) { $search->filter('id!=?', $data['id']); } if ($data['is_deleted'] == 1 || isNull(iterFirst($search))) { return TRUE; } $result->error('barcode_not_unique', $field); return FALSE; }
public function process(RM_Points_Action $obAction = NULL) { $params = $obAction->getParams(); $obAccount = $this->getAccount($params['user_id']); $obPayment = iterFirst($obAccount->getPaymentList()->filter('event=? and amount_date=? and vocation_end=?', 'leave-add', $params['prevFrom'], $params['prevTo'])); if (isNull($obPayment)) { return TRUE; } $obPayment->amount_date = $params['from']; $obPayment->vocation_end = $params['to']; return $obPayment->save(); }
public function countAgain() { $barcode = MC('AveragePrice')->getBarcodeValue(); $obQuery = MC('AveragePrice')->getQuery($barcode); if ($this->getSigma() > $this->max) { $obQuery->where('p.price/p.quantity < ?', $this->getSigma(1)); } if ($this->getSigma() < $this->min) { $obQuery->where('p.price/p.quantity > ?', $this->getSigma(-1)); } $obQuery->where('b.product_qty = ? AND b.product_measure = ? ', $this->qty, $this->measure); return iterFirst($obQuery->execute()); }
public function resolveEntityNamesByIds($diff = array()) { foreach ($diff as $entity => $value) { $diff = $this->_resolveBarcodeEntities($diff, $entity, $value); $diff = $this->_resolveGpcEntities($diff, $entity, $value); $diff = $this->_resolveGpcAttributes($diff, $entity, $value); if ($entity == 'cover_code' && !empty($value)) { $obCover = iterFirst(M('Store')->requestQuery(M('Store')->factoryObject(), M('Db')->createQuery(M('Barcode')->table('covers'))->what('CoverName name ')->where('CID = ? ', $value))); $diff[$entity] = !isNull($obCover) ? $obCover->name : $value; } } return $diff; }
protected function _ignoreIncrease(RM_Points_Account $obAccount, array $params) { if (isNull($obUser = M('User')->loadUserById($obAccount->user_id))) { return TRUE; } if (isNull($obPerson = iterFirst($obUser->getMainPerson()))) { return TRUE; } if ($obPerson->sex != 1) { return TRUE; } return FALSE; }
function checkDbRec($id, $table, $qw2Props, $props = array()) { $rec = iterFirst(M('Db')->query("SELECT * FROM {$table} WHERE id=?", $id)); T()->ok($id, "#{$id} is valid"); T()->ok(!isNull($rec), "record#{$id} exists in {$table}"); $expected = array(); // // here we do some trick: '!' in expected props means "any non-empty value" // foreach (array_merge($qw2Props, $props) as $p => $val) { $expected[$p] = ($val == '!' and $rec[$p]) ? $rec[$p] : $val; } T()->is_hash_eq($rec, $expected, "record#{$id} validness"); }
public function save() { $barcode = $this->_object->getBarcode(TRUE); if ($this->_isAddToModeration()) { if (isNull($queue = iterFirst(M('Barcode')->getQueueList()->filter('purchase_id=?', $this->_object->id())))) { $queue = M('Barcode')->createQueue(array('user_id' => me()->id(), 'purchase_id' => $this->_object->id(), 'barcode_value' => $this->_object->barcode_value, 'name_old' => isNull($barcode) ? NULL : $barcode->attribute_1, 'refreshed' => isNull($barcode) ? 0 : $barcode->to_refresh)); } if (!$queue->moderated) { $queue->name_new = $this->_object->corrected_name; $queue->save(); M('Points')->registerNewBarcode($this->_object); } } //me()->refreshDay($this->_object->bdate, count(M('Purchase')->getPurchaseListForDiary(me(), $this->_object->bdate)->filter('status_id=3'))); me()->refreshDayByQuery($this->_object->bdate); }
$action = "already exists"; } echo $obValue->id() . ' ' . $obValue->getName() . " {$action}\n"; if (isNull(iterFirst($obAttribute->getValues($obBrick)->filter('id = ?', $obValue->id())))) { $obAttribute->addValue($obValue, $obBrick); echo $obValue->id() . ' ' . $obValue->getName() . " added into attribute for specified brick\n"; } else { echo $obValue->id() . ' ' . $obValue->getName() . " already into attribute\n"; } } } $obProvansValue = iterFirst($obAttribute->getValues($obBrick)->filter('rus_name = ?', 'Прованс')); $many_words = array('Великий пост' => array('великий пост'), 'Деликатесный столовый' => array('деликатесный столовый'), 'Золотой провансаль' => array('золотой провансаль'), 'Золотой провансаль-м' => array('золотой провансаль-м'), 'Летнее настроение' => array('летнее настроение'), 'Мой майонез' => array('мой майонез'), 'На всякий случай' => array('на всякий случай'), 'Премиум-М' => array('премиум-м'), 'Премиум домашний' => array('премиум домашний'), 'Премиум знатный' => array('премиум знатный'), 'Премиум золотой' => array('премиум золотой'), 'Провансаль-М премиум/Провансаль-М premium' => array('провансаль-м премиум', 'провансаль-м premium'), 'Провансаль премиум/Провансаль premium' => array('провансаль премиум', 'провансаль premium'), 'Просто любимый' => array('просто любимый')); $many_words_values = array(); foreach ($many_words as $v_name => $needles) { $obValue = iterFirst($obAttribute->getValues($obBrick)->filter('rus_name = ?', $v_name)); $many_words_values[$obValue->id()] = $needles; } $values = array(); foreach ($obAttribute->getValues($obBrick) as $obValue) { $values[$obValue->id()] = mb_strtolower($obValue->getName(), 'utf-8'); } function findNeedle($description, $subbrand_name, $value_id, $value_name) { global $obProvansValue; $result = 0; if ($subbrand_name && strstr($subbrand_name, $value_name)) { $result = $value_id; } else { if ($description && strstr($description, ' ' . $value_name)) { $result = $value_id;
/** * Returns invoice with state "crerate" between two holders * * @param RM_Holder_Object $obSourceHolder * @param RM_Holder_Object $obDestinationHolder * @return RM_Holder_Invoice */ public function getInvoiceBetweenHolders(RM_Holder_Object $obSourceHolder, RM_Holder_Object $obDestinationHolder) { return iterFirst($this->getList('invoice')->filter('from_holder_id = ? AND to_holder_id = ? AND state = ? AND is_deleted = 0', $obSourceHolder->id(), $obDestinationHolder->id(), RM_Holder_Invoice_State::OPEN)->sort('cdate', 'DESC')); }
<?php /** * Edit price distribution */ if ($list->id() != 7) { throw Exception(__FILE__ . 'Wrong report = ' . $list->id() . ' to edit!'); } try { MC('Report_PriceDistribution')->editData($_POST); } catch (RM_Validator_Exception $e) { $err = iterFirst($e->getResult()->getErrors()); error(L('purchase.' . $err['code'])); }
/** * Description... * * @return void **/ public function loadLinkByShopId($shopId, RM_User_Object $user = NULL) { if (isNull($user)) { $user = M('Account')->getLoggedUser(); } if (isNull($user)) { throw new Exception('No loggedUser!'); } return iterFirst($this->_mapper->_storage('link')->getObjectList()->filter('shop_id=? and user_id=?', $shopId, $user->id())); }
/** * Returns Barcode by value * * @param string barcode * @return RM_Barcode_Object **/ public function loadBarcodeByValue($barcode) { return iterFirst($this->_mapper->storage('barcode')->getObjectList()->filter('value=?', $barcode)); }
/** * * * @param unknown_type $elements * @param RM_ReportPeriod_Range $obRange */ public function prepareTopForMonth($elements = 10, RM_ReportPeriod_Range $obRange = NULL) { #!! Заморожено до получения новых аргументов в пользу такого решения $obCategory = iterFirst(M('Category')->getCategoryList()); $obPeriod = M('ReportPeriod')->getPeriod('month', $obRange); $obDetail = M('ReportDetail')->getDetail('brand'); $obRegion = iterFirst($this->getRestrictionList('region')); $obTop = $this->_mapper->extension('top'); $obTop->init(array('period' => $obPeriod, 'detail' => $obDetail, 'region' => $obRegion)); }
<?php require_once "inc/init.php"; if (!empty($_GET['id'])) { $obEntity = M('Forum')->loadById($_GET['id']); if (isNull($obEntity)) { error(L('forum.no_record')); goU('forum.index'); } $obEntityList = $obEntity->getBranch(); } else { $obEntityList = M('Forum')->getThemeList(); } # if only one theme available -> go into if (!$admin && count($obEntityList) == 1 && iterFirst($obEntityList)->parent_id == 0) { $obEntityList = iterFirst($obEntityList)->getChildren(); } show("/forum/index", array('page_size' => 20, 'page' => p('page'), 'obEntityList' => $obEntityList, 'admin' => $admin));
group by b.owner_id, b.name order by 3 desc', 'N/A', 'N\\A') as $item) { if ($item['qty'] < 2) { break; } $request = M('Barcode')->getBrandList()->filter('owner_id=? and name=?', $item['owner_id'], $item['name'])->sort('id', 'asc'); $master = iterFirst($request); foreach ($request as $brand) { if ($brand->id() == $master->id()) { continue; } print $master->id() . " - " . $master->name . " - " . $master->owner_id . "\t\t" . $brand->id() . " - " . $brand->name . " - " . $brand->owner_id . "\n"; $brand->join($master); } } foreach (M('Db')->query('select b.brand_id, b.name, count(*) as qty from panelie_brand_subunits b left join panelie_barcode bc on bc.SubBrand_ID=b.id where bc.ProductGeneralType_ID in (3150,2915,16,3361,3409,3177,1057,469,232,485,3316,1231,2782,2256,451,4217) and b.name not in (?,?) group by brand_id, name order by 3 desc', 'N/A', 'N\\A') as $item) { if ($item['qty'] < 2) { break; } $request = M('Barcode')->getSubbrandList()->filter('brand_id=? and name=?', $item['brand_id'], $item['name'])->sort('id', 'asc'); $master = iterFirst($request); foreach ($request as $subbrand) { if ($subbrand->id() == $master->id()) { continue; } print $master->id() . " - " . $master->name . " - " . $master->brand_id . "\t\t" . $subbrand->id() . " - " . $subbrand->name . " - " . $subbrand->brand_id . "\n"; $subbrand->join($master); } }
/** * Process event. * * @param query string Query for fetching event * @param binds mixed Optional binds * @return void */ protected function _processEvent($query, $binds = array()) { if ($this->_lockFile) { flock($this->_lockFile, LOCK_EX) or trigger_error("Cannot obtain event lock", E_USER_ERROR); } $event = iterFirst($this->_dbh->query($query, $binds)); if (isNull($event)) { if ($this->_lockFile) { flock($this->_lockFile, LOCK_UN); } $this->_trace("Nothing to do"); return FALSE; } $this->_dbh->exec("UPDATE {$this->eventQueue} SET process_start = NOW(), process_pid = ? WHERE id = ?", function_exists('posix_getpid') ? posix_getpid() : 0, $event['id']); if ($this->_lockFile) { flock($this->_lockFile, LOCK_UN); } $this->_trace("Processing event #{$event['id']}/{$event['event_name']}", $event); #!! log $event['event_vars'] = unserialize($event['event_vars']); $event['async'] = 1; $time = $this->_executeEvent($event); $this->_dbh->exec("UPDATE {$this->eventQueue} SET process_finish = NOW(), process_time = process_time + ? WHERE id = ?", $time, $event['id']); $this->_trace("Event \"{$event['id']}/{$event['event_name']}\" has been processed"); return TRUE; }
/** * Return root node id for object * * @return int id */ private function _getTheme() { if (is_null($this->_root)) { $this->_root = iterFirst($this->_mapper->getList('ancestor_id')->filter('descendent_id = ? AND level > 0', $this->id())->sort('level', 'DESC')); } return $this->_root; }
public function getValueMaxLevel() { static $cache = NULL; if (!isset($cache)) { $aliases = array(); list($q, $binds) = $this->_valuesQuery($aliases); $q->what()->reset(); $q->what('max(v.level) as level'); if ($this->_usePermissions) { $q->where($aliases['values_access_ri'] . '=?', $binds['ri'][0], $binds['ri'][1], PERM_ALLOW); } $total = iterFirst($q->execute(), M('Store')->factorySimple()); $cache = $total['level'] + 0; } return $cache; }
<?php require_once $_SERVER['ROOT_DIR'] . '/init.php'; $aId = p('id'); $barcode = p('barcode'); $obControl = iterFirst(M('Store')->requestQuery(M('Store')->factoryObject(), M('Db')->createQuery(M('Barcode')->table('barcode_control'))->what('id')->where('id < ? AND barcode = ? ', $aId, $barcode)->order('id desc'))); if (!isNull($obControl)) { $pId = $obControl->id; } $data = array(); if (!isNull($obBarcode = M('Barcode')->loadBarcodeByValue($barcode))) { $active = $obBarcode->getHistory($aId); $prev = array_fill_keys(M('Barcode')->control()->getValiedEntities(), ''); if (!empty($pId)) { $prev = $obBarcode->getHistory($pId); } foreach ($active as $key => $val) { if (eregi("(a|v)([1-9]{1})", $key, $match)) { if (!empty($prev[$key])) { $data['attribute'][$match[2]]['p'][$match[1] == 'a' ? 1 : 2] = $prev[$key]; } if (!empty($active[$key])) { $data['attribute'][$match[2]]['a'][$match[1] == 'a' ? 1 : 2] = $active[$key]; } continue; } if ($key == 'complete') { $data[$key]['p'] = L('news.' . ($prev[$key] ? 'yes' : 'no')); $data[$key]['a'] = L('news.' . ($active[$key] ? 'yes' : 'no')); continue; }
function ___weight($type, $id) { $obj = iterFirst(M('Store')->requestQuery(M('Store')->factoryObject(), M('Db')->createQuery(M('user')->table($type . '_size'))->what('*')->where('id = ?', $id))); return !isNull($obj) ? $obj->name : L('user.undefined_weight'); }
<?php /** * Retriev a list of shops in given area * * xmin, ymin, xmax, ymax theese are coordinates of area OR * CID - City id */ $PROFILER_ENABLED = 0; $INIT_LIGHT = 0; $INIT_CONFIG = 1; $INIT_NO_CS_AUTH = 1; $USE_POST_PROCESS = 0; require_once $_SERVER["ROOT_DIR"] . "/init.php"; if (!me()->isAdmin() || isNull($photo = iterFirst(M('ObjectFs')->getAllFiles()->filter('id=?', $_GET['id'])))) { M('Ajax')->cheater(); exit; } try { $photo->delete(); okMessage(); } catch (RM_Validator_Exception $e) { ajaxMessages($e->getResult()); }
protected function _setDescriptionFromMyPurchases(RM_Purchase_Object $purchase, $minDate = NULL) { if (isNull(iterFirst(M('Barcode')->getQueueList()->filter('user_id=? and moderated=0', $purchase->user_id)))) { return; } $request = $this->storage('purchase')->getObjectList()->filter('user_id=? and barcode_value=? and status_id=3 and is_deleted=0', $purchase->user_id, $purchase->barcode_value)->sort('id', 'desc'); if ($minDate) { $request->filter('cdate>?', $minDate); } $cache = iterFirst($request); if (!isNull($cache)) { $purchase->corrected_name = $cache->corrected_name; } }