function DataBind() { //$this->DataSource = new DataSource(); $ds = new DataSource($this->DataSource); $ds->DataList = $this->DataSource; $ds->arrDataColumns = $this->DataColumns; $this->Data = $ds->GetData($this->DataColumns); }
/** * Find all DB records and generate array with arrays that filled by records data. */ public function findAll($where = '1=1', $limit = null) { $sql = 'SELECT * FROM ' . $this->tableName() . ' WHERE ' . $where . ' ' . ($limit !== null ? ' LIMIT ' . $limit : ''); $sth = new DataSource($sql); $models = array(); while (($model = $sth->getLine()) !== false) { $models[] = $model; } return $models; }
/** * Source currency * @param $source * * Destination currency * @param $destination * * Amount to convert * @param $amount */ function convert($source, $destination, $amount) { $currencies = $this->source->fetch(); if (!isset($currencies[$source])) { throw new \RuntimeException("Currency not found: {$source}"); } if (!isset($currencies[$destination])) { throw new \RuntimeException("Currency not found: {$destination}"); } return $amount * $currencies[$destination] / $currencies[$source]; }
function __construct($config) { parent::__construct($config); $this->api_key = $this->config['api_key']; $this->username = $this->config['username']; $this->password = $this->config['password']; }
public function __construct($config = array(), $autoConnect = true) { parent::__construct($config); $config['region'] = $this->region; $this->S3 = S3Client::factory($config); $this->bucketName = $config['bucket_name']; }
private function handle($col) { $globalDAO = new GlobalDAO(DataSource::getInstance()); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $content = trim(remove_slashes($_POST['content'])); if ($globalDAO->update($col, $content)) { $message = array('type' => 'info', 'value' => 'Lưu thành công.'); } else { $message = array('type' => 'error', 'value' => 'Có lỗi xảy ra!'); } $this->registry->template->message = $message; $this->registry->template->content = $content; $tmp = $globalDAO->select($col); $this->registry->template->content_backup = $tmp; } else { if ($_SERVER['REQUEST_METHOD'] == 'GET') { $tmp = $globalDAO->select($col); $this->registry->template->content = $tmp; $this->registry->template->content_backup = $tmp; } } if ($col == 'about') { $s = '“Giới thiệu”'; } else { if ($col == 'contact') { $s = '“Liên hệ”'; } } $this->registry->template->tile_title = 'Soạn thảo trang ' . $s; $this->registry->template->tile_content = 'admin/compose.php'; $this->registry->template->show('admin/layout/admin.php'); }
/** * Datasource constructor, creates the Configuration, Connection and DocumentManager objects * * ### You can pass the following configuration options * * - server: name of the server that will be used to connect to Mongo (default: `localhost`) * - database: name of the database to use when connecting to Mongo (default: `cake`) * - documentPaths: array containing a list of full path names where Document classes can be located (default: `App::path('Model')`) * - proxyDir: full path to the directory that will contain the generated proxy classes for each document (default: `TMP . 'cache'`) * - proxyNamespace: string representing the namespace the proxy classes will reside in (default: `Proxies`) * - hydratorDir: directory well the hydrator classes will be generated in (default: `TMP . 'cache'`) * - hydratorNamespace: string representing the namespace the hydrator classes will reside in (default: `Hydrators`) * * @param arary $config * @param boolean $autoConnect whether this object should attempt connection on creation * @throws MissingConnectionException if it was not possible to connect to MongoDB */ public function __construct($config = array(), $autoConnect = true) { $modelPaths = $this->_cleanupPaths(App::path('Model')); $this->_baseConfig = array('proxyDir' => TMP . 'cache', 'proxyNamespace' => 'Proxies', 'hydratorDir' => TMP . 'cache', 'hydratorNamespace' => 'Hydrators', 'server' => 'localhost', 'database' => 'cake', 'documentPaths' => $modelPaths, 'prefix' => null); foreach (CakePlugin::loaded() as $plugin) { $this->_baseConfig['documentPaths'] = array_merge($this->_baseConfig['documentPaths'], $this->_cleanupPaths(App::path('Model', $plugin))); } parent::__construct($config); extract($this->config, EXTR_OVERWRITE); $configuration = new Configuration(); $configuration->setProxyDir($proxyDir); $configuration->setProxyNamespace($proxyNamespace); $configuration->setHydratorDir($hydratorDir); $configuration->setHydratorNamespace($hydratorNamespace); $configuration->setDefaultDB($database); $configuration->setMetadataDriverImpl($this->_getMetadataReader($documentPaths)); if (Configure::read('debug') === 0) { $configuration->setAutoGenerateHydratorClasses(false); $configuration->setAutoGenerateProxyClasses(false); $configuration->setMetadataCacheImpl(new ApcCache()); } $this->configuration = $configuration; $this->connection = new Connection($server, array(), $configuration); $this->documentManager = DocumentManager::create($this->connection, $configuration); $this->documentManager->getEventManager()->addEventListener(array(Events::prePersist, Events::preUpdate, Events::preRemove, Events::postPersist, Events::postUpdate, Events::postRemove), $this); try { if ($autoConnect) { $this->connect(); } } catch (Exception $e) { throw new MissingConnectionException(array('class' => get_class($this))); } $this->setupLogger(); }
public function getBrands() { $brands = array(); $pdo = DataSource::load(); $data = array(); $statement = 'SELECT brand.*, category.name AS categoryName FROM brand LEFT JOIN category ON brand.category = category.id WHERE deleted = 0'; if (!empty($this->categoryId)) { $statement .= ' AND category = :category'; $data['category'] = $this->categoryId; } if ($this->status !== null) { $statement .= ' AND status = :status'; $data['status'] = $this->status; } if (!empty($this->orderBy)) { $statement .= ' ORDER BY ' . $this->orderBy; } if (!empty($this->limit)) { $statement .= ' LIMIT ' . (int) $this->limit; } if (!empty($this->offset)) { $statement .= ' OFFSET ' . (int) $this->offset; } $preparedStatement = $pdo->prepare($statement); $preparedStatement->execute($data); $brandsData = $preparedStatement->fetchAll(); foreach ($brandsData as $brandData) { $brand = new Brand(); $brand->setProperties($brandData); $brands[] = $brand; } return $brands; }
/** * Since Datasource has the method `describe()`, it won't be caught `__call()`. * This ensures it is called on the original datasource properly. * * @param mixed $model * @return mixed */ public function describe($model) { if (method_exists($this->source, 'describe')) { return $this->source->describe($model); } return $this->describe($model); }
function __construct($config) { parent::__construct($config); $this->Http =& new HttpSocket(); $this->email = $this->config['email']; $this->password = $this->config['password']; }
/** * Constructor * @param array $config An array defining the configuration settings */ public function __construct($config) { //Construct API version in this to go to SalesforceBaseClass! parent::__construct($config); $this->_baseConfig = $config; $this->connect(); }
public static function closeCon() { if (self::$instance) { self::$instance->closeSql(); self::$instance = NULL; } }
public function index() { if (empty($_GET['seo_url'])) { $this->notFound(); return; } $promoDAO = new PromoDAO(DataSource::getInstance()); $promo = $promoDAO->findBySeoUrl($_GET['seo_url']); if (!$promo) { $this->notFound(); return; } $categoryDAO = new CatDAO(DataSource::getInstance()); $categories_list = $categoryDAO->findByAll_Navigation(); $cart = getCart(); $this->registry->template->categories_list = $categories_list; $this->registry->template->cart = $cart; $this->registry->template->promo_seo_url_newest = $promoDAO->findNewestSeoUrl(); $this->registry->template->is_promo_active = TRUE; $this->registry->template->promo = $promo; $this->registry->template->related_promos = $promoDAO->findNewestList(); $this->registry->template->tile_title = $promo['subject']; $this->registry->template->tile_content = 'promo.php'; $this->registry->template->tile_footer = 'footer.php'; $this->registry->template->show('layout/user.php'); }
function __construct($config) { parent::__construct($config); $this->Http =& new HttpSocket(); $this->username = $this->config['username']; $this->password = $this->config['password']; }
public function read(Model $model, $queryData = array(), $recursive = null) { parent::read($model, $queryData, $recursive); $services = array(); if (!empty($queryData['conditions']['servicos'])) { if (is_array($queryData['conditions']['servicos'])) { foreach ($queryData['conditions']['servicos'] as $servico) { $services[] = $this->services[$servico]; } } else { $services = $this->services[$queryData['conditions']['servicos']]; } } else { // SET DEFAULT FORMAT $this->format = ECTFormatos::FORMATO_CAIXA_PACOTE; } if (!empty($queryData['conditions']['formato'])) { $this->format = $queryData['conditions']['formato']; } // GET VALUES $return = $this->_getECTValues($queryData['conditions']['altura'], $queryData['conditions']['comprimento'], $queryData['conditions']['largura'], $queryData['conditions']['peso'], $queryData['conditions']['ceporigem'], $queryData['conditions']['cep'], $services, $this->format); // CONVERTS ARRAY ITERATOR TO ARRAY $return = iterator_to_array($return, true); // CONVERT ARRAY OBJECTS TO ARRAY $return = $this->_toArray($return); // INSERT MODEL NAME AND RETURNS return $this->_fixReturn($return); }
function __construct($config) { parent::__construct($config); $this->Http =& new HttpSocket(); $this->params['login'] = $this->config['login']; $this->params['apiKey'] = $this->config['apiKey']; }
public function __construct($config = null, $autoConnect = true) { parent::__construct($config); if ($autoConnect) { return $this->connect(); } }
/** * Alter Table method * * @param string $type Type of operation to be done * @param array $tables List of tables and fields * @return boolean Return true in case of success, otherwise false * @access protected */ protected function _alterTable($type, $tables) { foreach ($tables as $table => $fields) { $indexes = array(); if (isset($fields['indexes'])) { $indexes = $fields['indexes']; unset($fields['indexes']); } foreach ($fields as $field => $col) { $model = new Model(array('table' => $table, 'ds' => $this->connection)); $tableFields = $this->db->describe($model); if ($type === 'drop') { $field = $col; } if ($type !== 'add' && !isset($tableFields[$field])) { throw new MigrationException($this, sprintf(__d('migrations', 'Field "%s" does not exists in "%s".', true), $field, $table)); } switch ($type) { case 'add': if (isset($tableFields[$field])) { throw new MigrationException($this, sprintf(__d('migrations', 'Field "%s" already exists in "%s".', true), $field, $table)); } $sql = $this->db->alterSchema(array($table => array('add' => array($field => $col)))); break; case 'drop': $sql = $this->db->alterSchema(array($table => array('drop' => array($field => array())))); break; case 'change': $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($tableFields[$field], $col))))); break; case 'rename': $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($tableFields[$field], array('name' => $col)))))); break; } if ($type == 'rename') { $data = array('table' => $table, 'old_name' => $field, 'new_name' => $col); } else { $data = array('table' => $table, 'field' => $field); } $this->_invokeCallbacks('beforeAction', $type . '_field', $data); if (@$this->db->execute($sql) === false) { throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s', true), $this->db->error)); } $this->_invokeCallbacks('afterAction', $type . '_field', $data); } foreach ($indexes as $key => $index) { if (is_numeric($key)) { $key = $index; $index = array(); } $sql = $this->db->alterSchema(array($table => array($type => array('indexes' => array($key => $index))))); $this->_invokeCallbacks('beforeAction', $type . '_index', array('table' => $table, 'index' => $key)); if (@$this->db->execute($sql) === false) { throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s', true), $this->db->error)); } $this->_invokeCallbacks('afterAction', $type . '_index', array('table' => $table, 'index' => $key)); } } return true; }
public function __construct($config = null) { if ($config === null) { $config = $this->config; } parent::__construct($config); }
public function __construct($config) { $this->indexFile = $config['indexFile']; $this->__setSources($config['source']); $this->__loadIndex(TMP . $this->indexFile); parent::__construct($config); }
/** * Default Constructor * * @param array $config options * @access public */ function __construct($config) { //Select contacts service for login token $this->GoogleApiContacts = new GoogleApiContacts($config); $this->_schema = $this->GoogleApiContacts->getSchema(); parent::__construct($config); }
public function loader() { $this->getController(); if (!is_readable($this->file)) { $this->file = $this->path . '/error404.php'; $this->controller = 'error404'; } include $this->file; $pos = strrpos($this->controller, '/'); if ($pos) { $this->controller = substr($this->controller, $pos + 1); } $class = $this->controller . 'Controller'; $controller = new $class($this->registry); session_start(); if (!is_callable(array($controller, $this->action))) { $action = 'index'; } else { $action = $this->action; } $controller->countStats(); if ($controller->checkPermission($action)) { $controller->{$action}(); } else { $controller->showError777(); } DataSource::closeCon(); }
protected function _execute($sql) { if (@$this->db->execute($sql) === false) { throw new Exception($this, sprintf(__d('Auditable', 'SQL Error: %s'), $this->db->lastError())); } return true; }
public function __construct($config = array()) { parent::__construct($config); $this->Node = ClassRegistry::init('Nodes.Node'); $this->TypeField = ClassRegistry::init('CustomFields.TypeField'); $this->columns = $this->Node->getDataSource()->columns; }
public function __construct($init = array()) { $this->clazz = get_class($this); $this->dirty = false; $this->ds = DataSource::getSettings(SPHORM_ENV); if (!isset(self::$reflectors[$this->clazz])) { self::$reflectors[$this->clazz] = new ReflectionClass($this->clazz); } $this->loadStaticFields(); if (isset($this->mapping['table'])) { $this->table = $this->mapping['table']; } else { $this->table = $this->clazz; } if (!empty($init)) { foreach ($init as $key => $val) { if (is_int($key)) { throw new Excetion('Illegal argument: init parameters require assoc array...'); } $this->data[$key] = $val; } } //check if current clazz was defined as a bean $beansAsKeys = array_flip(Beans::$beans); if (!isset($beansAsKeys[$this->clazz])) { throw new Exception('Undefined bean ' . $this->clazz . '. Please check Beans.php'); } $this->db = new Db($this->ds, $this->clazz, $this->table, false); $this->createOrUpdateDbModel(); }
/** * Constructor. Sets API key and throws an error if it's not defined in the * db config * * @param array $config */ public function __construct($config = array()) { parent::__construct($config); if (empty($config['api_key'])) { throw new CakeException('StripeSource: Missing api key'); } $this->Http = new HttpSocket(); }
private function open() { self::$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, DB_PORT); if (self::$conn->connect_errno) { die("Connect failed: " . self::$conn->connect_error); } return self::$conn; }
/** * Constructer. Load the HttpSocket into the Http var. */ function __construct($config) { parent::__construct($config); $this->map = $this->_map(); App::import('HttpSocket'); $this->Http = new HttpSocket(); Configure::load('Cart.config'); }
/** * Loads HttpSocket class * * @param array $config * @param HttpSocket $Http */ public function __construct($config, $Http = null) { parent::__construct($config); if (!$Http) { App::uses('HttpSocket', 'Network/Http'); $Http = new HttpSocket(); } $this->Http = $Http; }
public function index() { $globalDAO = new GlobalDAO(DataSource::getInstance()); $this->registry->template->count_stats = $globalDAO->getStats(); $this->registry->template->tile_title = 'Trang quản trị'; $this->registry->template->tile_content = 'admin/dashboard.php'; $this->registry->template->show('admin/layout/admin.php'); }