本文整理汇总了PHP中dmArray::first方法的典型用法代码示例。如果您正苦于以下问题:PHP dmArray::first方法的具体用法?PHP dmArray::first怎么用?PHP dmArray::first使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dmArray
的用法示例。
在下文中一共展示了dmArray::first方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createPageTranslations
protected function createPageTranslations($pageId)
{
$cultures = $this->getOption('cultures');
$translationTable = dmDb::table('DmPageTranslation');
$existingCultures = $translationTable->createQuery('t')->where('t.id = ? ', $pageId)->andWhereIn('t.lang', $cultures)->select('t.lang')->fetchFlat();
// can not generate translations from nothing
if (empty($existingCultures)) {
return;
}
// calculate missing cultures for this page
$missingCultures = array_diff($cultures, $existingCultures);
// all translations exist
if (empty($missingCultures)) {
return;
}
if (in_array(sfConfig::get('sf_default_culture'), $existingCultures)) {
$mainCulture = sfConfig::get('sf_default_culture');
} elseif (in_array(myDoctrineRecord::getDefaultCulture(), $existingCultures)) {
$mainCulture = myDoctrineRecord::getDefaultCulture();
} else {
$mainCulture = dmArray::first($existingCultures);
}
$mainTranslationArray = $translationTable->createQuery('t')->select('t.slug, t.name, t.title, t.h1, t.description, t.keywords, t.is_active')->where('t.id = ?', $pageId)->andWhere('t.lang = ?', $mainCulture)->limit(1)->fetchOne(array(), Doctrine_Core::HYDRATE_ARRAY);
$missingTranslations = new myDoctrineCollection(dmDb::table('DmPageTranslation'));
if ($this->getOption('activate_new_translations')) {
$isActive = $mainTranslationArray['is_active'];
} else {
$isActive = false;
}
foreach ($missingCultures as $culture) {
$missingTranslations->add($translationTable->create(array_merge($mainTranslationArray, array('lang' => $culture, 'is_active' => $isActive))));
}
$missingTranslations->save();
}
示例2: initialize
protected function initialize(array $options)
{
$this->configure($options);
if (!$this->themeNameExists($this->options['default'])) {
$this->options['default'] = dmArray::first($this->getThemeNames());
}
$this->themes = array();
}
示例3: configure
public function configure()
{
$this->widgetSchema['media_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true));
$this->validatorSchema['media_id'] = new sfValidatorDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true));
$this->validatorSchema['media_link'] = new sfValidatorPass();
$this->validatorSchema['media_alt'] = new sfValidatorPass();
$this->validatorSchema['media_position'] = new sfValidatorPass();
$this->widgetSchema['width'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['width'] = new dmValidatorCssSize(array('required' => false));
$this->widgetSchema['height'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['height'] = new dmValidatorCssSize(array('required' => false));
$this->widgetSchema['cols'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['cols'] = new sfValidatorNumber(array('required' => false, 'min' => 1, 'max' => 20));
if (!$this->hasDefault('cols')) {
$this->setDefault('cols', 3);
}
$this->widgetSchema['rows'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['rows'] = new sfValidatorNumber(array('required' => false, 'min' => 1, 'max' => 20));
if (!$this->hasDefault('rows')) {
$this->setDefault('rows', 3);
}
$this->widgetSchema['margin'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['margin'] = new dmValidatorCssSize(array('required' => false));
$this->widgetSchema['big_width'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['big_width'] = new dmValidatorCssSize(array('required' => false));
$this->widgetSchema['big_height'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['big_height'] = new dmValidatorCssSize(array('required' => false));
$methods = $this->getService('i18n')->translateArray(self::$methods);
$this->widgetSchema['method'] = new sfWidgetFormSelect(array('choices' => $methods));
$this->validatorSchema['method'] = new sfValidatorChoice(array('choices' => array_keys($methods)));
if (!$this->getDefault('method')) {
$this->setDefault('method', dmConfig::get('image_resize_method', 'center'));
}
$transitions = $this->getService('i18n')->translateArray(self::$transitions);
$this->widgetSchema['transition'] = new sfWidgetFormSelect(array('choices' => $transitions));
$this->validatorSchema['transition'] = new sfValidatorChoice(array('choices' => array_keys($transitions)));
if (!$this->getDefault('transition')) {
$this->setDefault('transition', dmArray::first(array_keys($transitions)));
}
$this->widgetSchema['speed'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['speed'] = new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 2000));
$this->widgetSchema['opacity'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['opacity'] = new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 1));
$this->widgetSchema['config'] = new sfWidgetFormTextarea(array(), array('cols' => 15, 'rows' => 3));
$this->validatorSchema['config'] = new sfValidatorString(array('required' => false));
$this->widgetSchema['quality'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['quality'] = new sfValidatorInteger(array('required' => false, 'min' => 0, 'max' => 100));
if (!$this->getDefault('medias')) {
$this->setDefault('medias', array());
}
// $this->widgetSchema['background'] = new sfWidgetFormInputText(array(), array('size' =>7));
// $this->validatorSchema['background'] = new sfValidatorString(array(
// 'required' => false
// ));
$this->validatorSchema['widget_width'] = new sfValidatorInteger(array('required' => false));
parent::configure();
}
示例4: executeChangeMaxPerPage
public function executeChangeMaxPerPage(sfWebRequest $request)
{
$this->forward404Unless($module = $this->context->getModuleManager()->getModuleBySfName($sfModule = $request->getParameter('dm_module')));
if ($maxPerPage = $request->getParameter('max_per_page')) {
$maxPerPages = sfConfig::get('dm_admin_max_per_page', array(10));
$maxPerPage = in_array($maxPerPage, $maxPerPages) ? $maxPerPage : dmArray::first($maxPerPages);
$this->getUser()->setAttribute($sfModule . '.max_per_page', $maxPerPage, 'admin_module');
$this->getUser()->setAttribute($sfModule . '.page', 1, 'admin_module');
}
return $this->redirectBack();
}
示例5: execute
public function execute(array $onlyModules = array())
{
if (empty($onlyModules)) {
$onlyModules = $this->moduleManager->getProjectModules();
} elseif (is_string(dmArray::first($onlyModules))) {
$onlyModules = $this->moduleManager->keysToModules($onlyModules);
}
$onlyModules = dmModuleManager::removeModulesChildren($onlyModules);
$this->updateListPages();
$this->removeShowPages($onlyModules);
$this->updateShowPages($onlyModules);
}
示例6: configure
public function configure()
{
/*
* Record id
*/
$this->widgetSchema['recordId'] = new sfWidgetFormDoctrineChoice(array('model' => $this->dmModule->getModel(), 'add_empty' => $this->allowAutoRecordId() ? sprintf('(%s) %s', $this->__('contextual'), $this->getAutoRecord()->__toString()) : false));
$this->widgetSchema['recordId']->setLabel($this->getDmModule()->getName());
$this->validatorSchema['recordId'] = new sfValidatorDoctrineChoice(array('model' => $this->dmModule->getModel(), 'required' => !$this->allowAutoRecordId()));
$this->setDefaults($this->getDefaultsFromLastUpdated());
if (!$this->allowAutoRecordId() && !$this->getDefault('recordId')) {
$this->setDefault('recordId', dmArray::first(array_keys($this->widgetSchema['recordId']->getChoices())));
}
parent::configure();
}
示例7: execute
public function execute(array $onlyModules, $culture)
{
$this->setCulture($culture);
$recordDefaultCulture = myDoctrineRecord::getDefaultCulture();
myDoctrineRecord::setDefaultCulture($this->culture);
if (empty($onlyModules)) {
$onlyModules = $this->moduleManager->getProjectModules();
} elseif (is_string(dmArray::first($onlyModules))) {
$onlyModules = $this->moduleManager->keysToModules($onlyModules);
}
$onlyModules = dmModuleManager::removeModulesChildren($onlyModules);
foreach ($onlyModules as $module) {
$this->updateRecursive($module);
}
myDoctrineRecord::setDefaultCulture($recordDefaultCulture);
}
示例8: findPageAndCultureForAnotherCulture
protected function findPageAndCultureForAnotherCulture($slug)
{
$i18n = $this->serviceContainer->getService('i18n');
if (!$i18n->hasManyCultures()) {
return false;
}
// search in all cultures
$page = dmDb::query('DmPage p')->innerJoin('p.Translation t')->where('t.slug = ?', $slug)->fetchOne();
if (!$page) {
return false;
}
// use the default culture
if ($page->get('Translation')->contains(sfConfig::get('sf_default_culture'))) {
$culture = sfConfig::get('sf_default_culture');
} else {
$culture = dmArray::first(array_keys($page->get('Translation')->getData()));
}
return array($page, $culture);
}
示例9: initConfiguration
/**
* @see sfProjectConfiguration
*/
public function initConfiguration()
{
parent::initConfiguration();
include $this->getConfigCache()->checkConfig('config/dm/config.yml');
/*
* Replace sf default culture by first culture in dm cultures configuration
*/
sfConfig::set('sf_default_culture', dmArray::first(sfConfig::get('dm_i18n_cultures')));
/*
* Symfony 1.3 registers sfAutoloadAgain on dev env. This causes huge performance issues.
*/
if ($this->isDebug()) {
sfAutoloadAgain::getInstance()->unregister();
}
/*
* Now that we have the project config, we can configure the doctrine cache
*/
$this->configureDoctrineCache(Doctrine_Manager::getInstance());
}
示例10: preloadPagesForRecords
public function preloadPagesForRecords($records)
{
if ($records instanceof Doctrine_Collection) {
$records = $records->getData();
}
foreach ($records as $index => $record) {
if (!$record instanceof dmDoctrineRecord) {
unset($records[$index]);
}
}
if (!empty($records)) {
if (($module = dmArray::first($records)->getDmModule()) && $module->hasPage()) {
$ids = array();
foreach ($records as $record) {
$ids[] = $record->get('id');
}
$this->prepareRecordPageCache($module->getKey(), array_unique($ids));
}
}
}
示例11: configure
public function configure()
{
$this->widgetSchema['media_id'] = new sfWidgetFormDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true));
$this->validatorSchema['media_id'] = new sfValidatorDoctrineChoice(array('model' => 'DmMedia', 'multiple' => true));
$this->validatorSchema['media_link'] = new sfValidatorPass();
$this->validatorSchema['media_alt'] = new sfValidatorPass();
$this->validatorSchema['media_position'] = new sfValidatorPass();
$this->widgetSchema['width'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['width'] = new dmValidatorCssSize(array('required' => false));
$this->widgetSchema['height'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['height'] = new dmValidatorCssSize(array('required' => false));
$methods = $this->getService('i18n')->translateArray(self::$methods);
$this->widgetSchema['method'] = new sfWidgetFormSelect(array('choices' => $methods));
$this->validatorSchema['method'] = new sfValidatorChoice(array('choices' => array_keys($methods)));
if (!$this->getDefault('method')) {
$this->setDefault('method', dmConfig::get('image_resize_method', 'center'));
}
$this->widgetSchema['show_pager'] = new sfWidgetFormInputCheckbox();
$this->validatorSchema['show_pager'] = new sfValidatorBoolean();
$animations = $this->getService('i18n')->translateArray(self::$animations);
$this->widgetSchema['animation'] = new sfWidgetFormSelect(array('choices' => $animations));
$this->validatorSchema['animation'] = new sfValidatorChoice(array('choices' => array_keys($animations)));
if (!$this->getDefault('animation')) {
$this->setDefault('animation', dmArray::first(array_keys($animations)));
}
$this->widgetSchema['delay'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['delay'] = new sfValidatorNumber(array('required' => false, 'min' => 0, 'max' => 1000));
if (!$this->hasDefault('delay')) {
$this->setDefault('delay', 3);
}
$this->widgetSchema['quality'] = new sfWidgetFormInputText(array(), array('size' => 5));
$this->validatorSchema['quality'] = new sfValidatorInteger(array('required' => false, 'min' => 0, 'max' => 100));
if (!$this->getDefault('medias')) {
$this->setDefault('medias', array());
}
$this->widgetSchema['background'] = new sfWidgetFormInputText(array(), array('size' => 7));
$this->validatorSchema['background'] = new sfValidatorString(array('required' => false));
$this->validatorSchema['widget_width'] = new sfValidatorInteger(array('required' => false));
parent::configure();
}
示例12: loadSettings
protected function loadSettings()
{
$array = array('site_name' => array('default_value' => dmString::humanize(dmProject::getKey()), 'description' => 'The site name', 'group_name' => 'site'), 'site_active' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is the site ready for visitors ?', 'group_name' => 'site'), 'site_indexable' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is the site ready for search engine crawlers ?', 'group_name' => 'site'), 'site_working_copy' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Is this site the current working copy ?', 'group_name' => 'site'), 'ga_key' => array('description' => 'The google analytics key without javascript stuff ( e.g. UA-9876614-1 )', 'group_name' => 'tracking', 'credentials' => 'google_analytics'), 'ga_token' => array('description' => 'Auth token gor Google Analytics, computed from password', 'group_name' => 'internal', 'credentials' => 'google_analytics'), 'gwt_key' => array('description' => 'The google webmaster tools filename without google and .html ( e.g. a913b555ba9b4f13 )', 'group_name' => 'tracking', 'credentials' => 'google_webmaster_tools'), 'xiti_code' => array('type' => 'textarea', 'description' => 'The xiti html code', 'group_name' => 'tracking', 'credentials' => 'xiti'), 'search_stop_words' => array('type' => 'textarea', 'description' => 'Words to exclude from searches (e.g. the, a, to )', 'group_name' => 'search engine', 'credentials' => 'search_engine'), 'base_urls' => array('type' => 'textarea', 'description' => 'Diem base urls for different applications/environments/cultures', 'group_name' => 'internal', 'credentials' => 'system'), 'image_resize_method' => array('type' => 'select', 'default_value' => 'center', 'description' => 'Default method when an image needs to be resized', 'params' => 'fit=Fit scale=Scale inflate=Inflate top=Top right=Right left=Left bottom=Bottom center=Center', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'image_resize_quality' => array('type' => 'number', 'default_value' => 95, 'description' => 'Jpeg default quality when generating thumbnails', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_external_blank' => array('type' => 'boolean', 'default_value' => 0, 'description' => 'Links to other domain get automatically a _blank target', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_current_span' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Links to current page are changed from <a> to <span>', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'link_use_page_title' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'Add an automatic title on link based on the target page title', 'group_name' => 'interface', 'credentials' => 'interface_settings'), 'title_prefix' => array('default_value' => '', 'description' => 'Append something at the beginning of all pages title', 'group_name' => 'seo', 'credentials' => 'manual_metas'), 'title_suffix' => array('default_value' => ' | ' . dmString::humanize(dmProject::getKey()), 'description' => 'Append something at the end of all pages title', 'group_name' => 'seo', 'credentials' => 'manual_metas'), 'smart_404' => array('type' => 'boolean', 'default_value' => 1, 'description' => 'When a page is not found, user is redirect to a similar page. The internal search index is used to find the best page for requested url.', 'group_name' => 'seo', 'credentials' => 'url_redirection'));
$existingSettings = dmDb::query('DmSetting s INDEXBY s.name')->withI18n()->fetchRecords();
foreach ($array as $name => $config) {
if (!isset($existingSettings[$name])) {
$setting = new DmSetting();
$setting->set('name', $name);
$setting->fromArray($config);
$setting->save();
} elseif (!$existingSettings[$name]->hasCurrentTranslation()) {
/*
* Try to find an existing config from another culture
*/
$existing = dmDb::query('DmSettingTranslation s')->where('s.id = ?', $existingSettings[$name]->id)->limit(1)->fetchArray();
if ($existing = dmArray::first($existing)) {
$config = $existing;
unset($config['id'], $config['lang']);
}
$existingSettings[$name]->fromArray($config)->getCurrentTranslation()->save();
}
}
dmConfig::load(false);
}
示例13: getFirstChild
public function getFirstChild()
{
return dmArray::first($this->children);
}
示例14: dirname
<?php
require_once dirname(__FILE__) . '/helper/dmUnitTestHelper.php';
$helper = new dmUnitTestHelper();
$helper->boot();
$t = new lime_test(21);
$t->diag('first');
$t->is_deeply(dmArray::first('alpha'), 'alpha', 'first parameter is not an array');
$t->is_deeply(dmArray::first(array()), null, 'empty source array');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::first($array), 'alpha', 'first value');
$t->diag('firsts');
$t->is_deeply(dmArray::firsts('alpha', 2), 'alpha', 'first parameter is not an array');
$t->is_deeply(dmArray::firsts(array(), 2), null, 'empty source array');
$t->is_deeply(dmArray::firsts(array('alpha'), 2), array('alpha'), 'not enough values');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::firsts($array, 2), array('alpha', 'beta'), 'first values');
$t->diag('get');
$t->is_deeply(dmArray::get('alpha', null, 'test'), 'test', 'first parameter is not an array');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test'), 'alpha', 'key exists');
$t->is_deeply(dmArray::get(array('alpha'), 1, 'test'), 'test', 'key not exists');
$t->is_deeply(dmArray::get(array(''), 0, 'test', false), '', 'empty value without default if empty');
$t->is_deeply(dmArray::get(array(''), 0, 'test', true), 'test', 'empty value with default if empty');
$t->is_deeply(dmArray::get(array('alpha'), 0, 'test', true), 'alpha', 'key exists with default if empty');
$t->diag('last');
$t->is_deeply(dmArray::last('alpha'), 'alpha', 'first parameter is not an array');
$t->is_deeply(dmArray::last(array()), null, 'empty source array');
$array = array('alpha', 'beta', 'gamma', 'delta');
$t->is_deeply(dmArray::last($array), 'delta', 'last value');
$t->diag('toHtmlCssClasses');
$classes = array('class1', '', ' class2', ' ', ' class3 ');
示例15: getPrimaryKey
/**
* Will return pk column name if table has only one pk, or null
*/
public function getPrimaryKey()
{
if (count($this->getPrimaryKeys()) === 1) {
return dmArray::first($this->getPrimaryKeys());
}
return null;
}