コード例 #1
0
ファイル: Region.php プロジェクト: arslbbt/mangentovies
 public function loadByName(Mage_Directory_Model_Region $region, $regionName, $countryId)
 {
     $locale = Mage::app()->getLocale()->getLocaleCode();
     $select = $this->_read->select()->from(array('region' => $this->_regionTable))->where('region.country_id=?', $countryId)->where('region.default_name=?', $regionName)->join(array('rname' => $this->_regionNameTable), 'rname.region_id=region.region_id AND rname.locale=\'' . $locale . '\'', array('name'));
     $region->setData($this->_read->fetchRow($select));
     return $this;
 }
コード例 #2
0
ファイル: Db.php プロジェクト: arslbbt/mangentovies
 public function getTableDataDump($tableName, $step = 100)
 {
     $sql = '';
     if ($this->_read) {
         $quotedTableName = $this->_read->quoteIdentifier($tableName);
         $colunms = $this->_read->fetchRow('SELECT * FROM ' . $quotedTableName . ' LIMIT 1');
         if ($colunms) {
             $arrSql = array();
             $colunms = array_keys($colunms);
             $quote = $this->_read->getQuoteIdentifierSymbol();
             $sql = 'INSERT INTO ' . $quotedTableName . ' (' . $quote . implode($quote . ', ' . $quote, $colunms) . $quote . ')';
             $sql .= ' VALUES ';
             $startRow = 0;
             $select = $this->_read->select();
             $select->from($tableName)->limit($step, $startRow);
             while ($data = $this->_read->fetchAll($select)) {
                 $dataSql = array();
                 foreach ($data as $row) {
                     $dataSql[] = $this->_read->quoteInto('(?)', $row);
                 }
                 $arrSql[] = $sql . implode(', ', $dataSql) . ';';
                 $startRow += $step;
                 $select->limit($step, $startRow);
             }
             $sql = implode("\n", $arrSql) . "\n";
         }
     }
     return $sql;
 }
コード例 #3
0
ファイル: Roles.php プロジェクト: arslbbt/mangentovies
 public function load($roleId)
 {
     if ($roleId) {
         $row = $this->_read->fetchRow("SELECT * FROM {$this->_roleTable} WHERE role_id = {$roleId}");
         return $row;
     } else {
         return array();
     }
 }
コード例 #4
0
 /**
  * Initialize payment data.
  * replaces method getPayment($id)
  */
 protected function _initData()
 {
     $tbl_prefix = SimpleInvoices_Db_Table_Abstract::getTablePrefix();
     $select = new Zend_Db_Select($this->_db);
     $select->from($tbl_prefix . 'payment');
     $select->joinInner($tbl_prefix . 'invoices', $tbl_prefix . "payment.ac_inv_id = " . $tbl_prefix . "invoices.id", NULL);
     $select->joinInner($tbl_prefix . 'customers', $tbl_prefix . "invoices.customer_id = " . $tbl_prefix . "customers.id", array('customer_id' => $tbl_prefix . "customers.id", 'customer' => $tbl_prefix . "customers.name"));
     $select->joinInner($tbl_prefix . 'biller', $tbl_prefix . "invoices.biller_id = " . $tbl_prefix . "biller.id", array('biller_id' => $tbl_prefix . "biller.id", 'biller' => $tbl_prefix . "biller.name"));
     $select->where($tbl_prefix . 'payment.id=?', $this->_id);
     $this->_data = $this->_db->fetchRow($select);
     $this->_data['date'] = siLocal::date($payment['ac_date']);
 }
コード例 #5
0
 /**
  * read syncstate from database 
  *
  * @param ActiceSync_Model_SyncState $_syncState
  * @return ActiceSync_Model_SyncState
  */
 public function get(ActiveSync_Model_SyncState $_syncState)
 {
     $select = $this->_db->select()->from(SQL_TABLE_PREFIX . 'acsync_synckey')->where('device_id = ?', $_syncState->device_id)->where('type = ?', $_syncState->type)->order('counter DESC')->limit(1);
     if (!empty($_syncState->counter)) {
         $select->where('counter = ?', $_syncState->counter);
     }
     $row = $this->_db->fetchRow($select);
     if (!$row) {
         throw new ActiveSync_Exception_SyncStateNotFound('syncState not found: ' . $select);
     }
     $result = new ActiveSync_Model_SyncState($row);
     return $result;
 }
コード例 #6
0
 /**
  * Calculation the field info display for this type
  *
  * @param array $currentValue The current value
  * @param array $fieldData The other values loaded so far
  * @return mixed the new value
  */
 public function calculateFieldInfo($currentValue, array $fieldData)
 {
     if (!$currentValue) {
         return $currentValue;
     }
     // Display nice
     $sql = $this->_sql . "WHERE grr_id = ?";
     $row = $this->db->fetchRow($sql, $currentValue);
     if ($row && isset($row['name'])) {
         return $row['name'];
     }
     return $currentValue;
 }
コード例 #7
0
ファイル: Review.php プロジェクト: arslbbt/mangentovies
 public function aggregate($object)
 {
     if (!$object->getEntityPkValue() && $object->getId()) {
         $object->load($object->getReviewId());
     }
     $ratingModel = Mage::getModel('rating/rating');
     $ratingSummaries = $ratingModel->getEntitySummary($object->getEntityPkValue(), false);
     $nonDelete = array();
     foreach ($ratingSummaries as $ratingSummaryObject) {
         if ($ratingSummaryObject->getCount()) {
             $ratingSummary = round($ratingSummaryObject->getSum() / $ratingSummaryObject->getCount());
         } else {
             $ratingSummary = $ratingSummaryObject->getSum();
         }
         $reviewsCount = $this->getTotalReviews($object->getEntityPkValue(), true, $ratingSummaryObject->getStoreId());
         $select = $this->_read->select();
         $select->from($this->_aggregateTable)->where("{$this->_aggregateTable}.entity_pk_value = ?", $object->getEntityPkValue())->where("{$this->_aggregateTable}.entity_type = ?", $object->getEntityId())->where("{$this->_aggregateTable}.store_id = ?", $ratingSummaryObject->getStoreId());
         $oldData = $this->_read->fetchRow($select);
         $data = new Varien_Object();
         $data->setReviewsCount($reviewsCount)->setEntityPkValue($object->getEntityPkValue())->setEntityType($object->getEntityId())->setRatingSummary($ratingSummary > 0 ? $ratingSummary : 0)->setStoreId($ratingSummaryObject->getStoreId());
         $this->_write->beginTransaction();
         try {
             if ($oldData['primary_id'] > 0) {
                 $condition = $this->_write->quoteInto("{$this->_aggregateTable}.primary_id = ?", $oldData['primary_id']);
                 $this->_write->update($this->_aggregateTable, $data->getData(), $condition);
             } else {
                 $this->_write->insert($this->_aggregateTable, $data->getData());
             }
             $this->_write->commit();
         } catch (Exception $e) {
             $this->_write->rollBack();
         }
     }
 }
コード例 #8
0
ファイル: Mysql4_Db.php プロジェクト: ronseigel/agent-ohm
 /**
  * Returns SQL header data
  */
 public function getHeader()
 {
     $dbConfig = $this->_read->getConfig();
     $versionRow = $this->_read->fetchRow('SHOW VARIABLES LIKE \'version\'');
     $header = "-- Magento DB backup\n" . "--\n" . "-- Host: {$dbConfig['host']}    Database: {$dbConfig['dbname']}\n" . "-- ------------------------------------------------------\n" . "-- Server version: {$versionRow['Value']}\n\n" . "/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;\n" . "/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;\n" . "/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;\n" . "/*!40101 SET NAMES utf8 */;\n" . "/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;\n" . "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n" . "/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;\n" . "/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;\n";
     return $header;
 }
コード例 #9
0
 public function load($object, $customerId)
 {
     $select = $this->_read->select();
     $select->from($this->_customerTable, array('login_at', 'logout_at'))->joinInner($this->_visitorTable, $this->_visitorTable . '.visitor_id=' . $this->_customerTable . '.visitor_id', array('last_visit_at'))->joinInner($this->_visitorInfoTable, $this->_visitorTable . '.visitor_id=' . $this->_visitorInfoTable . '.visitor_id', array('http_referer', 'remote_addr'))->joinInner($this->_urlInfoTable, $this->_urlInfoTable . '.url_id=' . $this->_visitorTable . '.last_url_id', array('url'))->where($this->_read->quoteInto($this->_customerTable . '.customer_id=?', $customerId))->order($this->_customerTable . '.login_at desc')->limit(1);
     $object->setData($this->_read->fetchRow($select));
     return $object;
 }
コード例 #10
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @return boolean
  * @throws \Zend_Valid_Exception If validation of $value is impossible
  */
 public function isValid($value)
 {
     if ($throttleSettings = $this->project->getAskThrottleSettings()) {
         // Prune the database for (very) old attempts
         $where = $this->db->quoteInto('gta_datetime < DATE_SUB(NOW(), INTERVAL ? second)', $throttleSettings['period'] * 20);
         $this->db->delete('gems__token_attempts', $where);
         // Retrieve the number of failed attempts that occurred within the specified window
         $select = $this->db->select();
         $select->from('gems__token_attempts', array(new \Zend_Db_Expr('COUNT(*) AS attempts'), new \Zend_Db_Expr('UNIX_TIMESTAMP(MAX(gta_datetime)) - UNIX_TIMESTAMP() AS last')))->where('gta_datetime > DATE_SUB(NOW(), INTERVAL ? second)', $throttleSettings['period']);
         $attemptData = $this->db->fetchRow($select);
         $remainingDelay = $attemptData['last'] + $throttleSettings['delay'];
         // \MUtil_Echo::track($throttleSettings, $attemptData, $remainingDelay);
         if ($attemptData['attempts'] > $throttleSettings['threshold'] && $remainingDelay > 0) {
             $this->logger->log("Possible token brute force attack, throttling for {$remainingDelay} seconds", \Zend_Log::ERR);
             $this->_messages = $this->translate->_('The server is currently busy, please wait a while and try again.');
             return false;
         }
     }
     // The pure token check
     if ($this->isValidToken($value)) {
         return true;
     }
     $max_length = $this->tracker->getTokenLibrary()->getLength();
     $this->db->insert('gems__token_attempts', array('gta_id_token' => substr($value, 0, $max_length), 'gta_ip_address' => $this->getRequest()->getClientIp()));
     return false;
 }
コード例 #11
0
 /**
  * Process everything after authentication.
  *
  * @param \Zend_Auth_Result $result
  */
 protected function afterAuthorization(\Zend_Auth_Result $result, $lastAuthorizer = null)
 {
     try {
         $select = $this->db->select();
         $select->from('gems__user_login_attempts', array('gula_failed_logins', 'gula_last_failed', 'gula_block_until', new \Zend_Db_Expr('UNIX_TIMESTAMP() - UNIX_TIMESTAMP(gula_last_failed) AS since_last')))->where('gula_login = ?', $this->getLoginName())->where('gula_id_organization = ?', $this->getCurrentOrganizationId())->limit(1);
         $values = $this->db->fetchRow($select);
         // The first login attempt
         if (!$values) {
             $values['gula_login'] = $this->getLoginName();
             $values['gula_id_organization'] = $this->getCurrentOrganizationId();
             $values['gula_failed_logins'] = 0;
             $values['gula_last_failed'] = null;
             $values['gula_block_until'] = null;
             $values['since_last'] = $this->failureIgnoreTime + 1;
         }
         if ($result->isValid()) {
             // Reset login failures
             $values['gula_failed_logins'] = 0;
             $values['gula_last_failed'] = null;
             $values['gula_block_until'] = null;
         } else {
             // Reset the counters when the last login was longer ago than the delay factor
             if ($values['since_last'] > $this->failureIgnoreTime) {
                 $values['gula_failed_logins'] = 1;
             } elseif ($lastAuthorizer === 'pwd') {
                 // Only increment failed login when password failed
                 $values['gula_failed_logins'] += 1;
             }
             // If block is already set
             if ($values['gula_block_until']) {
                 // Do not change it anymore
                 unset($values['gula_block_until']);
             } else {
                 // Only set the block when needed
                 if ($this->failureBlockCount <= $values['gula_failed_logins']) {
                     $values['gula_block_until'] = new \Zend_Db_Expr('DATE_ADD(CURRENT_TIMESTAMP, INTERVAL ' . $this->failureIgnoreTime . ' SECOND)');
                 }
             }
             // Always record the last fail
             $values['gula_last_failed'] = new \MUtil_Db_Expr_CurrentTimestamp();
             $values['gula_failed_logins'] = max(1, $values['gula_failed_logins']);
             // Response gets slowly slower
             $sleepTime = min($values['gula_failed_logins'] - 1, 10) * 2;
             sleep($sleepTime);
             // \MUtil_Echo::track($sleepTime, $values, $result->getMessages());
         }
         // Value not saveable
         unset($values['since_last']);
         if (isset($values['gula_login'])) {
             $this->db->insert('gems__user_login_attempts', $values);
         } else {
             $where = $this->db->quoteInto('gula_login = ? AND ', $this->getLoginName());
             $where .= $this->db->quoteInto('gula_id_organization = ?', $this->getCurrentOrganizationId());
             $this->db->update('gems__user_login_attempts', $values, $where);
         }
     } catch (\Zend_Db_Exception $e) {
         // Fall through as this does not work if the database upgrade did not yet run
         // \MUtil_Echo::r($e);
     }
 }
コード例 #12
0
 /**
  * Load the data when the cache is empty.
  *
  * @param mixed $id
  * @return array The array of data values
  */
 protected function loadData($id)
 {
     if (\Gems_User_UserLoader::SYSTEM_NO_ORG === $id) {
         $data = false;
     } else {
         try {
             $sql = "SELECT * FROM gems__organizations WHERE gor_id_organization = ? LIMIT 1";
             $data = $this->db->fetchRow($sql, intval($id));
         } catch (\Exception $e) {
             $data = false;
         }
     }
     if ($data) {
         try {
             $dbOrgId = $this->db->quote($id, \Zend_Db::INT_TYPE);
             $sql = "SELECT gor_id_organization, gor_name\n                    FROM gems__organizations\n                    WHERE gor_active = 1 AND\n                        (\n                          gor_id_organization = {$dbOrgId} OR\n                          gor_accessible_by LIKE '%:{$dbOrgId}:%'\n                        )\n                    ORDER BY gor_name";
             $data['can_access'] = $this->db->fetchPairs($sql);
             natsort($data['can_access']);
         } catch (\Exception $e) {
             $data['can_access'] = array();
         }
         // \MUtil_Echo::track($sql, $data['can_access']);
         if (array_key_exists('gor_url_base', $data) && ($baseUrls = explode(' ', $data['gor_url_base']))) {
             $data['base_url'] = reset($baseUrls);
         }
     } else {
         $data = $this->_noOrganization;
         $data['gor_id_organization'] = $id;
     }
     return $data;
 }
コード例 #13
0
ファイル: Model.php プロジェクト: rocknoon/TCVM
 /**
  * count
  * @return int
  */
 public function count()
 {
     $this->_selector->reset(Zend_Db_Select::COLUMNS);
     $this->_selector->columns(array('count' => 'count(*)'));
     $data = $this->_adapter->fetchRow($this->_selector);
     $this->_initSelector();
     return intval($data['count']);
 }
コード例 #14
0
ファイル: XenForo.php プロジェクト: Sywooch/forums
 protected function _importUser(array $user, array $options = array())
 {
     if ($this->_groupMap === null) {
         $this->_groupMap = $this->_importModel->getImportContentMap('userGroup');
     }
     $import = $this->_quickAssembleData($user, array('username', 'email', 'gender', 'custom_title', 'timezone', 'visible', 'user_group_id' => $this->_mapLookUp($this->_groupMap, $user['user_group_id'], XenForo_Model_User::$defaultRegisteredGroupId), 'secondary_group_ids' => $this->_translateUserGroupIdList($user['secondary_group_ids'], true), 'display_style_group_id' => $this->_mapLookUp($this->_groupMap, $user['display_style_group_id'], XenForo_Model_User::$defaultRegisteredGroupId), 'message_count', 'conversations_unread', 'register_date', 'last_activity', 'avatar_date', 'avatar_width', 'avatar_height', 'gravatar', 'user_state', 'is_moderator', 'is_admin', 'is_staff', 'is_banned', 'like_count', 'warning_points', 'dob_day', 'dob_month', 'dob_year', 'status', 'status_date', 'signature', 'homepage', 'location', 'occupation', 'avatar_crop_x', 'avatar_crop_y', 'about', 'show_dob_year', 'show_dob_date', 'content_show_signature', 'receive_admin_email', 'email_on_conversation', 'is_discouraged', 'default_watch_state', 'alert_optout', 'enable_rte', 'enable_flash_uploader', 'allow_view_profile', 'allow_post_profile', 'allow_send_personal_conversation', 'allow_view_identities', 'allow_receive_news_feed', 'scheme_class', 'data'));
     // custom user fields
     if ($user['custom_fields'] = unserialize($user['custom_fields'])) {
         if ($this->_userFieldMap === null) {
             $this->_userFieldMap = $this->_importModel->getImportContentMap('userField');
         }
         $userFieldDefinitions = $this->_importModel->getUserFieldDefinitions();
         foreach ($user['custom_fields'] as $oldFieldId => $customField) {
             $newFieldId = $this->_mapLookUp($this->_userFieldMap, $oldFieldId);
             if (!$newFieldId) {
                 continue;
             }
             $import[XenForo_Model_Import::USER_FIELD_KEY][$newFieldId] = $user['custom_fields'][$oldFieldId];
         }
     }
     $importedUserId = $this->_importModel->importUser($user['user_id'], $import, $failedKey, false);
     if ($importedUserId) {
         // banned users
         if ($user['is_banned']) {
             if ($ban = $this->_sourceDb->fetchRow('SELECT * FROM xf_user_ban WHERE user_id = ?', $user['user_id'])) {
                 $this->_importModel->importBan($this->_quickAssembleData($ban, array('user_id' => $importedUserId, 'ban_user_id' => $this->_importModel->mapUserId($ban['ban_user_id'], 0), 'ban_date', 'end_date', 'user_reason', 'triggered')));
             }
         }
         // handle admins in a different way from normal imports so that we get a complete data import
         if ($user['is_admin'] && (!$this->_importModel->keysRetained() || $user['user_id'] != 1)) {
             if ($admin = $this->_sourceDb->fetchRow('SELECT * FROM xf_admin WHERE user_id = ?', $user['user_id'])) {
                 $this->_importModel->importAdmin($this->_quickAssembleData($admin, array('user_id' => $importedUserId, 'extra_user_group_ids' => $this->_translateUserGroupIdList($admin['extra_user_group_ids']), 'last_login', 'permission_cache')));
             }
         }
         // avatar
         if ($user['avatar_date']) {
             /* @var $avatarModel XenForo_Model_Avatar */
             $avatarModel = XenForo_Model::create('XenForo_Model_Avatar');
             foreach (array('l', 'm', 's') as $size) {
                 $oldAvatar = $avatarModel->getAvatarFilePath($user['user_id'], $size, $this->_config['dir']['data']);
                 if (!file_exists($oldAvatar) || !is_readable($oldAvatar)) {
                     continue;
                 }
                 $newAvatar = $avatarModel->getAvatarFilePath($importedUserId, $size);
                 $directory = dirname($newAvatar);
                 if (XenForo_Helper_File::createDirectory($directory, true) && is_writable($directory)) {
                     copy($oldAvatar, $newAvatar);
                 }
             }
         }
     } else {
         if ($failedKey) {
             $this->_session->setExtraData('userFailed', $user['user_id'], $failedKey);
         }
     }
     return $importedUserId;
 }
コード例 #15
0
    /**
     * Gets the discussion from the update marked with "for update" to ensure that position
     * counters are maintained correctly.
     *
     * @param Zend_Db_Adapter_Abstract $db
     * @param integer $id
     *
     * @return array|false Discussion info or false to use what's in the DW already
     */
    public function getDiscussionForUpdate(Zend_Db_Adapter_Abstract $db, $id)
    {
        return $db->fetchRow('
			SELECT *
			FROM xf_thread
			WHERE thread_id = ?
			FOR UPDATE
		', $id);
    }
コード例 #16
0
ファイル: Common.php プロジェクト: jorgenils/zend-framework
 /**
  * Test the Adapter's fetchRow() method.
  */
 public function testAdapterFetchRow()
 {
     $id = $this->getResultSetKey('id');
     $table = $this->getIdentifier(self::TABLE_NAME);
     $result = $this->_db->fetchRow('SELECT * FROM ' . $this->_db->quoteIdentifier($table) . ' WHERE date_created > ? ORDER BY id', array('2006-01-01'));
     $this->assertEquals(5, count($result));
     // count columns
     $this->assertEquals(1, $result[$id]);
 }
コード例 #17
0
ファイル: Passport.php プロジェクト: bjtenao/tudu-web
 /**
  * Performs an authentication attempt
  *
  * @throws Zend_Auth_Adapter_Exception If authentication cannot
  *                                     be performed
  * @return Zend_Auth_Result
  */
 public function authenticate()
 {
     // 数据库读取操作
     $sql = 'SELECT U.id, U.account, U.password, U.rnd, U.isenable ' . 'FROM ' . $this->_dbName . '.dbo.Users U ' . 'WHERE ';
     if (is_int($this->_username)) {
         $where = 'U.id = ?';
     } elseif (strpos($this->_username, '@') > 0) {
         $where = 'U.account = (SELECT account FROM ' . $this->_dbName . '.dbo.EmailAccount WHERE email = ?)';
     } else {
         $where = 'U.account = ?';
     }
     $sql .= $this->_db->quoteInto($where, $this->_username);
     $row = $this->_db->fetchRow($sql);
     do {
         if (!$row) {
             $this->_resultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
             $this->_resultInfo['message'][] = 'not found';
             break;
         }
         if ($row['isenable'] != 1) {
             $this->_resultInfo['code'] = Zend_Auth_Result::FAILURE;
             $this->_resultInfo['message'][] = 'forbid';
             break;
         }
         $row['password'] = bin2hex($row['password']);
         $row['account'] = rtrim($row['account']);
         $valid = false;
         /**
          * @see Oray_Coder_Passport
          */
         require_once 'Oray/Coder/Passport.php';
         switch ($this->_authType) {
             case Oray_Auth::AUTH_TYPE_CLEAR:
                 $valid = Oray_Coder_Passport::checkCode($row['password'], $this->_password, $row['account']);
                 break;
             case Oray_Auth::AUTH_TYPE_MD5:
                 $valid = Oray_Coder_Passport::checkCode($row['password'], $this->_password, $row['account'], true);
                 break;
             case Oray_Auth::AUTH_TYPE_AUTH:
                 $valid = !empty($row['rnd']) && $this->_password == $row['rnd'];
                 break;
             case Oray_Auth::AUTH_TYPE_AUTO:
                 $valid = true;
             default:
                 break;
         }
         if (!$valid) {
             $this->_resultInfo['code'] = Zend_Auth_Result::FAILURE;
             $this->_resultInfo['message'][] = 'failure';
             break;
         }
         $this->setIdentity($row);
         $this->_resultInfo['code'] = Zend_Auth_Result::SUCCESS;
         $this->_resultInfo['message'][] = 'success';
     } while (false);
     return new Zend_Auth_Result($this->_resultInfo['code'], $this->_identity, $this->_resultInfo['message']);
 }
コード例 #18
0
ファイル: Db.php プロジェクト: shabbirvividads/magento2
 /**
  * @param mixed $nodeId
  * @return Node
  */
 public function loadNode($nodeId)
 {
     $select = clone $this->_select;
     $condition = $this->_conn->quoteInto("{$this->_table}.{$this->_idField}=?", $nodeId);
     $select->where($condition);
     $node = new Node($this->_conn->fetchRow($select), $this->_idField, $this);
     $this->addNode($node);
     return $node;
 }
コード例 #19
0
ファイル: Tree.php プロジェクト: chucky515/Magento-CE-Mirror
 public function getNode($nodeId)
 {
     $dbSelect = new Zend_Db_Select($this->_db);
     $dbSelect->from($this->_table)->where($this->_table . '.' . $this->_id . ' >= :id');
     $this->_addExtTablesToSelect($dbSelect);
     $data = array();
     $data['id'] = $nodeId;
     $data = $this->_db->fetchRow($dbSelect, $data);
     return new Varien_Db_Tree_Node($data, $this->getKeys());
 }
コード例 #20
0
 /**
  * @param $oo_id
  * @param bool $createMissingChildrenRows
  * @throws \Zend_Db_Adapter_Exception
  */
 public function doUpdate($oo_id, $createMissingChildrenRows = false)
 {
     if (empty($this->fields) && empty($this->relations) && !$createMissingChildrenRows) {
         return;
     }
     $this->idTree = [];
     $fields = implode("`,`", $this->fields);
     if (!empty($fields)) {
         $fields = ", `" . $fields . "`";
     }
     $result = $this->db->fetchRow("SELECT " . $this->idField . " AS id" . $fields . " FROM " . $this->storetable . " WHERE " . $this->idField . " = ?", $oo_id);
     $o = new \stdClass();
     $o->id = $result['id'];
     $o->values = $result;
     $o->childs = $this->buildTree($result['id'], $fields);
     if (!empty($this->fields)) {
         foreach ($this->fields as $fieldname) {
             foreach ($o->childs as $c) {
                 $this->getIdsToUpdateForValuefields($c, $fieldname);
             }
             $this->updateQueryTable($oo_id, $this->fieldIds[$fieldname], $fieldname);
         }
     }
     if (!empty($this->relations)) {
         foreach ($this->relations as $fieldname => $fields) {
             foreach ($o->childs as $c) {
                 $this->getIdsToUpdateForRelationfields($c, $fieldname);
             }
             if (is_array($fields)) {
                 foreach ($fields as $f) {
                     $this->updateQueryTable($oo_id, $this->fieldIds[$fieldname], $f);
                 }
             } else {
                 $this->updateQueryTable($oo_id, $this->fieldIds[$fieldname], $fieldname);
             }
         }
     }
     // check for missing entries which can occur in object bricks and localized fields
     // this happens especially in the following case:
     // parent object has no brick, add child to parent, add brick to parent & click save
     // without this code there will not be an entry in the query table for the child object
     if ($createMissingChildrenRows) {
         $idsToUpdate = $this->extractObjectIdsFromTreeChildren($o->childs);
         if (!empty($idsToUpdate)) {
             $idsInTable = $this->db->fetchCol("SELECT " . $this->idField . " FROM " . $this->querytable . " WHERE " . $this->idField . " IN (" . implode(",", $idsToUpdate) . ")");
             $diff = array_diff($idsToUpdate, $idsInTable);
             // create entries for children that don't have an entry yet
             $originalEntry = $this->db->fetchRow("SELECT * FROM " . $this->querytable . " WHERE " . $this->idField . " = ?", $oo_id);
             foreach ($diff as $id) {
                 $originalEntry[$this->idField] = $id;
                 $this->db->insert($this->querytable, $originalEntry);
             }
         }
     }
 }
コード例 #21
0
ファイル: Model.php プロジェクト: vgrish/dvelum
 /**
  * Get object by unique field
  *
  * @param string $fieldName
  * @param string $value
  * @param array $fields - optional
  * @throws Exception
  * @return array
  */
 public function getItemByUniqueField($fieldName, $value, $fields = '*')
 {
     if (!$this->_objectConfig->isUnique($fieldName)) {
         $eText = 'getItemByUniqueField field "' . $fieldName . '" [' . $this->_objectConfig->getName() . '] should be unique';
         $this->logError($eText);
         throw new Exception($eText);
     }
     $sql = $this->_dbSlave->select()->from($this->table(), $fields);
     $sql->where($this->_dbSlave->quoteIdentifier($fieldName) . ' = ?', $value);
     return $this->_dbSlave->fetchRow($sql);
 }
コード例 #22
0
 /**
  * Returns the name of the user definition class of this user.
  *
  * @param string $login_name
  * @param int $organization
  * @return \Gems_User_User But ! ->isActive when the user does not exist
  */
 protected function getUserClass($login_name, $organization)
 {
     //First check for project user, as this one can run without a db
     if (null !== $login_name && $this->isProjectUser($login_name)) {
         return $this->loadUser(self::USER_PROJECT, $organization, $login_name);
     }
     if (null == $login_name) {
         return $this->loadUser(self::USER_NOLOGIN, $organization, $login_name);
     }
     if (!$this->allowLoginOnWithoutOrganization) {
         if (null == $organization || !intval($organization)) {
             return $this->loadUser(self::USER_NOLOGIN, $organization, $login_name);
         }
     }
     try {
         $select = $this->getUserClassSelect($login_name, $organization);
         if ($row = $this->db->fetchRow($select, null, \Zend_Db::FETCH_NUM)) {
             if ($row[3] == 1 || $this->allowLoginOnOtherOrganization === true) {
                 // \MUtil_Echo::track($row);
                 return $this->loadUser($row[0], $row[1], $row[2]);
             }
         }
     } catch (\Zend_Db_Exception $e) {
         // Intentional fall through
     }
     // Fail over for pre 1.5 projects
     //
     // No login as other organization or with e-mail possible for first login, before running of upgrade / patches
     //
     // Test code voor old user, code for password 'guest' is: 084e0343a0486ff05530df6c705c8bb4,
     // for 'test4': 86985e105f79b95d6bc918fb45ec7727
     $sql = "SELECT gsf_id_user\n            FROM gems__staff INNER JOIN\n                    gems__organizations ON gsf_id_organization = gor_id_organization\n                    WHERE gor_active = 1 AND gsf_active = 1 AND gsf_login = ? AND gsf_id_organization = ?";
     if ($user_id = $this->db->fetchOne($sql, array($login_name, $organization))) {
         // Move user to new staff.
         $values['gul_login'] = $login_name;
         $values['gul_id_organization'] = $organization;
         $values['gul_user_class'] = self::USER_OLD_STAFF;
         // Old staff as password is still in gems__staff
         $values['gul_can_login'] = 1;
         $values['gul_changed'] = new \MUtil_Db_Expr_CurrentTimestamp();
         $values['gul_changed_by'] = $user_id;
         $values['gul_created'] = $values['gul_changed'];
         $values['gul_created_by'] = $user_id;
         try {
             $this->db->insert('gems__user_logins', $values);
         } catch (\Zend_Db_Exception $e) {
             // Fall through as this does not work if the database upgrade did not run
             // \MUtil_Echo::r($e);
         }
         return $this->loadUser(self::USER_OLD_STAFF, $organization, $login_name);
     }
     return $this->loadUser(self::USER_NOLOGIN, $organization, $login_name);
 }
コード例 #23
0
 /**
  * Use the Mail template code to select and set the template
  * @param string mail
  */
 public function setTemplateByCode($templateCode)
 {
     $select = $this->loader->getModels()->getCommTemplateModel()->getSelect();
     $select->where('gct_code = ?', $templateCode);
     $template = $this->db->fetchRow($select);
     if ($template) {
         $this->setTemplate($template['gct_id_template']);
         return true;
     } else {
         return false;
     }
 }
コード例 #24
0
 /**
  * Enter description here...
  *
  * @param int|string $nodeId
  * @return Varien_Data_Tree_Node
  */
 public function loadNode($nodeId)
 {
     $select = clone $this->_select;
     if (is_numeric($nodeId)) {
         $condField = $this->_conn->quoteIdentifier(array($this->_table, $this->_idField));
     } else {
         $condField = $this->_conn->quoteIdentifier(array($this->_table, $this->_pathField));
     }
     $select->where("{$condField} = ?", $nodeId);
     $node = new Varien_Data_Tree_Node($this->_conn->fetchRow($select), $this->_idField, $this);
     $this->addNode($node);
     return $node;
 }
コード例 #25
0
 /**
  * @param  $url
  * @param  $queryStr
  * @return string
  */
 public function getSumaryForUrl($url, $queryStr)
 {
     $query = "SELECT content from plugin_searchphp_contents where id = ? ";
     $params = array(md5($url));
     $data = $this->db->fetchRow($query, $params);
     $sumary = null;
     if ($data) {
         $sumary = $this->getHighlightedSumary($data['content'], array($queryStr));
         if (empty($sumary)) {
             $tokens = explode(" ", $queryStr);
             if (count($tokens) > 1) {
                 foreach ($tokens as $token) {
                     $sumary = $this->getHighlightedSumary($data['content'], $tokens);
                     if (!empty($sumary)) {
                         break;
                     }
                 }
             }
         }
     }
     return $sumary;
 }
コード例 #26
0
 /**
  *
  * @param array $gemsData Optional, the data refresh with, otherwise refresh from database.
  * @return \Gems_Tracker_RespondentTrack (continuation pattern)
  */
 public function refresh(array $gemsData = null)
 {
     if (is_array($gemsData)) {
         $this->_respTrackData = $gemsData + $this->_respTrackData;
     } else {
         $sql = "SELECT *\n                        FROM gems__respondent2track\n                        WHERE gr2t_id_respondent_track = ? LIMIT 1";
         $this->_respTrackData = $this->db->fetchRow($sql, $this->_respTrackId);
     }
     $this->_ensureFieldData(true);
     $this->_rounds = null;
     $this->_tokens = null;
     return $this;
 }
コード例 #27
0
 /**
  * Get a display version of the patient name
  *
  * @return string
  */
 protected function getRespondentName()
 {
     if ($this->respondentTrack instanceof \Gems_Tracker_RespondentTrack) {
         return $this->respondentTrack->getRespondentName();
     } else {
         $select = $this->db->select();
         $select->from('gems__respondents')->joinInner('gems__respondent2org', 'grs_id_user = gr2o_id_user', array())->where('gr2o_patient_nr = ?', $this->patientId)->where('gr2o_id_organization = ?', $this->organizationId);
         $data = $this->db->fetchRow($select);
         if ($data) {
             return trim($data['grs_first_name'] . ' ' . $data['grs_surname_prefix']) . ' ' . $data['grs_last_name'];
         }
     }
     return '';
 }
コード例 #28
0
ファイル: Subscriber.php プロジェクト: arslbbt/mangentovies
 /**
  * Load subscriber by customer
  *
  * @param 	Mage_Customer_Model_Customer $customer
  * @return 	array
  */
 public function loadByCustomer(Mage_Customer_Model_Customer $customer)
 {
     $select = $this->_read->select()->from($this->_subscriberTable)->where('customer_id=?', $customer->getId());
     $result = $this->_read->fetchRow($select);
     if ($result) {
         return $result;
     }
     $select = $this->_read->select()->from($this->_subscriberTable)->where('subscriber_email=?', $customer->getEmail());
     $result = $this->_read->fetchRow($select);
     if ($result) {
         return $result;
     }
     return array();
 }
コード例 #29
0
 /**
  * Load subscriber by customer
  *
  * @param \Magento\Customer\Api\Data\CustomerInterface $customer
  * @return array
  */
 public function loadByCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
 {
     $select = $this->_read->select()->from($this->getMainTable())->where('customer_id=:customer_id');
     $result = $this->_read->fetchRow($select, ['customer_id' => $customer->getId()]);
     if ($result) {
         return $result;
     }
     $select = $this->_read->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');
     $result = $this->_read->fetchRow($select, ['subscriber_email' => $customer->getEmail()]);
     if ($result) {
         return $result;
     }
     return [];
 }
コード例 #30
0
ファイル: Subscriber.php プロジェクト: aiesh/magento2
 /**
  * Load subscriber by customer
  *
  * @param \Magento\Customer\Service\V1\Data\Customer $customer
  * @return array
  */
 public function loadByCustomerData(\Magento\Customer\Service\V1\Data\Customer $customer)
 {
     $select = $this->_read->select()->from($this->getMainTable())->where('customer_id=:customer_id');
     $result = $this->_read->fetchRow($select, array('customer_id' => $customer->getId()));
     if ($result) {
         return $result;
     }
     $select = $this->_read->select()->from($this->getMainTable())->where('subscriber_email=:subscriber_email');
     $result = $this->_read->fetchRow($select, array('subscriber_email' => $customer->getEmail()));
     if ($result) {
         return $result;
     }
     return array();
 }