/** * * @TODO cach profilu */ protected function getCurrentProfile() { if (defined('CMD')) { $config = Zend_Registry::get('config'); if ($config['bin']['user'] === null || $config['bin']['branch'] === null) { throw new Exception('Brak ustawień w application.ini bin.user lub bin.branch'); } $u = new User(); $u_data = $u->fetchRow("login = '******'bin']['user'] . "'", "id DESC")->toArray(); $storageRow = new stdClass(); foreach ($u_data as $key => $value) { $storageRow->{$key} = $value; } $auth = Zend_Auth::getInstance(); $storage = $auth->getStorage(); $o = new Branch(); $data = $o->fetchRow("branch_name = '" . $config['bin']['branch'] . "'", "id DESC")->toArray(); $storageRow->jednostka = $data; $profile = new Profile(); $profiles = $profile->fetchAll(array('id_user = '******'id'], 'id_branch = ' . $data['id'], 'ghost = false')); if (count($profiles)) { $storageRow->profile_id = $profiles[0]['id']; } $storage->write($storageRow); } if (defined('CMD') && defined('EXPORT_ID_USER')) { $identity['id'] = EXPORT_ID_USER; $where_id = $identity['id']; } else { $where_id = Zend_Auth::getInstance()->getIdentity() ? Zend_Auth::getInstance()->getIdentity()->id : ''; } if (!$this->currentProfile and $where_id) { $cm = $this->getBootstrap()->getResource('cachemanager'); $cache = $cm->getCache('rolecache'); $cache_id = str_replace("-", "", 'OUcache' . ODDZIAL_ID . '_' . $where_id); if (!($this->currentProfile = $cache->load($cache_id))) { $profilModel = new Profile(); $this->currentProfile = $profilModel->fetchRow(array("id_user = {$where_id}", "id_branch = " . ODDZIAL_ID, 'ghost = false')); $cache->save($this->currentProfile, $cache_id); } } return $this->currentProfile; }
public function prepareData($data) { foreach ($this->checkfield as $cos) { if (array_search($cos, $this->headers) === false) { throw new Exception('There is no data to check duplicates'); } } $invalid = array(); foreach ($data as $value) { if ($this->checkDuplicates($value) == true) { $value['valid_until'] = date('c', time() + 2 * 365 * 24 * 60 * 60); $branch = new Branch(); $bdata = $branch->fetchRow("branch_name = '{$value['id_branch']}'"); $value['id_branch'] = $bdata['id']; $this->add($value, $invalid); } else { $invalid[] = $value; } } return $ile = count($invalid); }
/** Zend_Application */ require_once 'Zend/Application.php'; // Create application, bootstrap, and run $application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini'); Base_Controller_Action_Helper_Currentip::$_unitTestEnabled = true; $application->bootstrap(); Zend_Controller_Front::getInstance()->setParam('bootstrap', $application->getBootstrap()); $user = $application->getOption('bin'); if ($user['user'] === null || $user['branch'] === null) { throw new Exception('Brak ustawień w application.ini bin.user lub bin.branch'); } $u = new User(); $u_data = $u->fetchRow("login = '******'user'] . "'", "id DESC"); if (null == $u_data) { throw new Exception('Brak użytkownika o podanym loginie ' . $user['user']); } $u_data->toArray(); $storageRow = new stdClass(); foreach ($u_data as $key => $value) { $storageRow->{$key} = $value; } $auth = Zend_Auth::getInstance(); $storage = $auth->getStorage(); $o = new Branch(); $data = $o->fetchRow("branch_name = '" . $user['branch'] . "'", "id DESC"); if (null == $u_data) { throw new Exception('Brak Branch\'a ' . $user['branch']); } $data->toArray(); $storageRow->jednostka = $data; $storage->write($storageRow);
public static function syncProducts($type, $brand) { $db = new DEFProduct(); $auth = Zend_Auth::getInstance(); $user_id = $auth->getIdentity()->id; $model = new Branch(); $row = $model->fetchRow(array('branch_name ilike \'' . $brand . '\'')); if ($row === null) { throw new Logic_Exception('Cannot detect branch id'); } $idBranch = $row->id; foreach (self::getDefProductsArray($type, $brand) as $product) { $where = $db->select()->where('product_type = ?', $type)->where('id_branch = ?', $idBranch)->where('symbol = ?', $product['symbol'])->where('ghost = ?', 'f'); $same = $db->fetchRow($where); $active = false; if ($same) { $db->update(array('ghost' => 't'), array('product_type = ?' => $type, 'symbol = ?' => $product['symbol'], 'ghost = ?' => 'f', 'id_branch = ?' => $idBranch)); $active = $same->active; } if ($active) { $active = 't'; } else { $active = 'f'; } $key = $db->insert(array('def_id' => $product['id_prod'], 'symbol' => $product['symbol'], 'short_desc' => $product['short_desc'], 'desc' => $product['desc'], 'min_amount' => (double) $product['min_amnt'], 'min_amount_currency' => (int) $product['min_amnt_currency'], 'currency' => (int) $product['currency'], 'active' => $active, 'ghost' => 'f', 'product_type' => $type, 'id_branch' => $idBranch, 'id_user' => $user_id)); } }