本文整理汇总了PHP中D::manager方法的典型用法代码示例。如果您正苦于以下问题:PHP D::manager方法的具体用法?PHP D::manager怎么用?PHP D::manager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类D
的用法示例。
在下文中一共展示了D::manager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValue
public static function getValue($value, $settings, $model)
{
// Check if the src is set and the converted values are not - this means we need to check for
// the progress file and possibly update the database
if (is_array($value) && isset($value['src']) && strlen($value['src']) > 0 && (!isset($value['converted']) || empty($value['converted']))) {
// See if the progress file exists
$path = DOCROOT . $value['src'];
if (file_exists($path . '.progress')) {
$value['progress'] = json_decode(file_get_contents($path . '.progress'));
} else {
// It doesn't exist - populate the field
if (isset($value['progress'])) {
unset($value['progress']);
}
$path_info = pathinfo($value['src']);
$value['poster'] = $path_info['dirname'] . '/' . $path_info['basename'] . '.jpg';
$value['converted'] = array('mp4' => $path_info['dirname'] . '/converted/' . $path_info['filename'] . '.mp4', 'webm' => $path_info['dirname'] . '/converted/' . $path_info['filename'] . '.webm');
//$class = \CMF::getClass($model);
$field_name = $settings['mapping']['fieldName'];
$model->set($field_name, $value);
\D::manager()->persist($model);
\D::manager()->flush();
}
}
return $value;
}
示例2: enableListener
public static function enableListener()
{
if (empty(static::$listener)) {
return;
}
\D::manager()->getEventManager()->addEventSubscriber(static::$listener);
}
示例3: removeOldKeys
/**
* Purge all expired API keys from the database
*/
public function removeOldKeys()
{
$keys = \CMF\Model\User\Apikey::select('item')->andWhere('item.expires_at < :now')->setParameter('now', new \DateTime())->getQuery()->getResult();
foreach ($keys as $key) {
\D::manager()->remove($key);
}
\D::manager()->flush();
}
示例4: action_languageCanonicals
public function action_languageCanonicals()
{
$lang = \Config::get('language');
$em = \D::manager();
if (empty($lang)) {
throw new \Exception("You do not have set any language for this site , this action is not available");
}
$canonicalLanguage = "";
if (isset($_SERVER["HTTP_CONTENT_LANGUAGE"])) {
$canonicalLanguage = $_SERVER["HTTP_CONTENT_LANGUAGE"];
if ($canonicalLanguage == $lang) {
throw new \Exception("Canonical Language id the same as Main site language");
}
} else {
throw new \Exception("The Request has got not language set");
}
$jsonObject = null;
try {
$jsonObject = json_decode(file_get_contents('php://input'));
} catch (\Exception $e) {
}
if (!empty($jsonObject) && !empty($jsonObject->data)) {
foreach ($jsonObject->data as $table => $items) {
foreach ($items as $canonical) {
$class = $canonical->class;
$item = $class::find($canonical->id);
if (!empty($item) && !empty($item->settings)) {
$settings = $item->settings;
if (!isset($settings['languages'])) {
$settings['languages'] = array();
}
if (isset($canonical->url)) {
if (!isset($settings['languages'][$canonicalLanguage])) {
$settings['languages'][$canonicalLanguage] = \Uri::base(false) . $item->url;
}
$settings['languages'][$canonicalLanguage] = $canonical->url;
} else {
if (isset($settings['languages'][$canonicalLanguage])) {
unset($settings['languages'][$canonicalLanguage]);
}
}
$item->set('settings', $settings);
$em->persist($item);
}
}
}
}
$em->flush();
exit(true);
}
示例5: cleanOld
public static function cleanOld()
{
$urls = \CMF\Model\URL::select('item')->getQuery()->getResult();
$deleted = 0;
foreach ($urls as $url) {
$item = $url->item();
if (empty($item)) {
\D::manager()->remove($url);
$deleted++;
}
}
\D::manager()->flush();
return $deleted;
}
示例6: startQuery
public function startQuery($sql, array $params = null, array $types = null)
{
if ($this->logger) {
$this->logger->startQuery($sql, $params, $types);
}
// Store select queries for later use
if (substr($sql, 0, 6) == 'SELECT') {
if ($params) {
// Attempt to replace placeholders so that we can log a final SQL query for profiler's EXPLAIN statement
// (this is not perfect-- getPlaceholderPositions has some flaws-- but it should generally work with ORM-generated queries)
$is_positional = is_numeric(key($params));
list($sql, $params, $types) = \Doctrine\DBAL\SQLParserUtils::expandListParameters($sql, $params, $types);
if (empty($types)) {
$types = array();
}
$placeholders = \Doctrine\DBAL\SQLParserUtils::getPlaceholderPositions($sql, $is_positional);
if ($is_positional) {
$map = array_flip($placeholders);
} else {
$map = array();
foreach ($placeholders as $name => $positions) {
foreach ($positions as $pos) {
$map[$pos] = $name;
}
}
}
ksort($map);
$src_pos = 0;
$final_sql = '';
$first_param_index = key($params);
foreach ($map as $pos => $replace_name) {
$final_sql .= substr($sql, $src_pos, $pos - $src_pos);
if ($sql[$pos] == ':') {
$src_pos = $pos + strlen($replace_name);
$index = trim($replace_name, ':');
} else {
$src_pos = $pos + 1;
$index = $replace_name + $first_param_index;
}
$final_sql .= \D::manager()->getConnection()->quote($params[$index], \Arr::get($types, $index));
}
$final_sql .= substr($sql, $src_pos);
$this->queries[] = $final_sql;
} else {
$this->queries[] = $sql;
}
}
}
示例7: instance
/** inheritdoc */
public static function instance()
{
$called_class = get_called_class();
if (!isset($called_class::$instances[$called_class])) {
$result = $called_class::select('item, start_page')->leftJoin('item.start_page', 'start_page')->setMaxResults(1)->getQuery()->getResult();
if (count($result) == 0) {
// Create the item if it doesn't exist
$result = new $called_class();
$result->blank();
\D::manager()->persist($result);
\D::manager()->flush();
$called_class::$instances[$called_class] = $result;
} else {
$called_class::$instances[$called_class] = $result[0];
}
}
return $called_class::$instances[$called_class];
}
示例8: pageTree
protected function pageTree($model = 'Model_Page_Base', $label = null, $active_url = null, $extra_fields = null)
{
$extra_fields_str = !is_null($extra_fields) ? ', page.' . implode(', page.', $extra_fields) : '';
if ($model == 'Model_Page_Base') {
$extra_fields_str = ', TYPE(page) AS type';
}
$nodes = $model::select('page.id, page.title, page.menu_title, page.lvl, page.lft, page.rgt' . $extra_fields_str . ', url.url, url.slug', 'page')->leftJoin('page.url', 'url')->where('page.lvl > 0')->andWhere('page.visible = true')->orderBy('page.root, page.lft', 'ASC')->getQuery();
// Set the query hint if multi lingual!
if (\CMF\Doctrine\Extensions\Translatable::enabled()) {
$nodes->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
}
$nodes = $nodes->getArrayResult();
$root_label = $label ? $label . '_level1' : 'level1';
$crumbs_label = $label ? $label . '_crumbs' : 'crumbs';
$uri = $active_url ? $active_url : \CMF::link(\CMF::original_uri());
$nodes = \D::manager()->getRepository($model)->buildTree($nodes, array());
$this->{$crumbs_label} = array();
$this->processNodes($nodes, $uri, 1, $label, $model);
$crumbs = $this->{$crumbs_label};
ksort($crumbs);
$this->{$crumbs_label} = $crumbs;
return $this->{$root_label} = $nodes;
}
示例9: processDeletions
/**
* Deletes any imported local data that wasn't present in the import
*/
protected static function processDeletions($model)
{
if (!isset(static::$_updatedEntities[$model]) || !is_array(static::$_updatedEntities[$model])) {
return;
}
$metadata = $model::metadata();
$polymorphic = $metadata->isInheritanceTypeJoined() || $metadata->isInheritanceTypeSingleTable();
$class = $metadata->name;
// Find all the ids of database items that have been imported
$localIds = $class::getImportedIds();
// Now get all the ids that have just been processed
$processedClasses = array($metadata->name);
$processedIds = array();
if ($polymorphic && count($metadata->subClasses)) {
foreach ($metadata->subClasses as $subClass) {
if (!in_array($subClass, $processedClasses)) {
$processedClasses[] = $subClass;
}
}
}
foreach ($processedClasses as $processedClass) {
if (!isset(static::$_updatedEntities[$processedClass]) || !is_array(static::$_updatedEntities[$processedClass])) {
continue;
}
foreach (static::$_updatedEntities[$processedClass] as $id => $entity) {
if (!in_array($entity->id, $processedIds)) {
$processedIds[] = $entity->id;
}
}
}
// Find the difference between the two
asort($localIds);
asort($processedIds);
$diff = array_diff($localIds, $processedIds);
// Delete ones that weren't imported this time
if (count($diff)) {
$entities = $class::select('item')->where('item.id IN(:ids)')->setParameter('ids', $diff)->getQuery()->getResult();
foreach ($entities as $entity) {
\D::manager()->remove($entity);
}
}
}
示例10: _add_default_role
/**
* Adds default role to a new user if enabled in config
*
* @see \CMF\Model\User::_event_before_save()
*/
private function _add_default_role()
{
// Make sure no roles exist already
if (empty($this->roles) || !static::query()->related('roles')->get_one()) {
// Check for default role
if ($default_role = \Config::get('cmf.auth.default_role')) {
$em = \D::manager();
$query = $em->createQuery("SELECT r FROM CMF\\Model\\Role r WHERE r.name = '{$default_role}'");
$record = $query->getSingleResult();
if (!is_null($role)) {
$this->roles[] = $role;
}
}
}
}
示例11: getOptionsStatic
public static function getOptionsStatic(&$settings, $model)
{
$allow_empty = isset($settings['mapping']['nullable']) && $settings['mapping']['nullable'] && !(isset($settings['required']) && $settings['required']);
if (static::$options !== null && is_array(static::$options)) {
return $allow_empty ? array('' => '') + static::$options : static::$options;
}
$options = array();
$target_class = 'CMF\\Model\\URL';
$filters = array();
$tree_types = array();
$types = $target_class::select('item.type')->distinct()->where('item.item_id IS NOT NULL')->orderBy('item.type', 'ASC')->getQuery()->getScalarResult();
foreach ($types as $type) {
$type = $type['type'];
if (!class_exists($type)) {
continue;
}
$metadata = $type::metadata();
$root_class = $metadata->rootEntityName;
if (isset($root_class)) {
$type = $root_class;
}
$name = $type::plural();
if (isset($options[$name])) {
continue;
}
$group = \Arr::get($options, $name, array());
$repository = \D::manager()->getRepository($type);
$prop = property_exists('menu_title', $type) ? 'menu_title' : 'title';
if ($repository instanceof \Gedmo\Tree\Entity\Repository\NestedTreeRepository && !in_array($name, $tree_types)) {
$tree_types[] = $name;
// Put in the tree data...
$query = $type::select('item, url')->leftJoin('item.url', 'url')->where('item.lvl > 0');
if (count($filters) > 0) {
foreach ($filters as $filter) {
$query = $query->andWhere('item.' . $filter);
}
}
$tree = $query->orderBy('item.root, item.lft', 'ASC')->getQuery();
// Set the query hint if multi lingual!
if (\CMF\Doctrine\Extensions\Translatable::enabled()) {
$tree->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
}
$tree = $tree->getArrayResult();
$tree = $repository->buildTree($tree, array());
$options[$name] = static::buildTreeOptionsStatic($tree, $prop, array());
continue;
}
$items = $type::select("item.id, item.{$prop}, url.url, url.id url_id")->leftJoin('item.url', 'url')->orderBy("item.{$prop}", "ASC")->getQuery();
// Set the query hint if multi lingual!
if (\CMF\Doctrine\Extensions\Translatable::enabled()) {
$items->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
}
$items = $items->getArrayResult();
if (is_array($items) && count($items) > 0) {
foreach ($items as $item) {
$group[strval($item[$prop])] = $item['url'];
}
$options[$name] = $group;
}
}
foreach ($options as $group_name => &$group_value) {
if (is_array($group_value) && !in_array($group_name, $tree_types)) {
uasort($group_value, function ($a, $b) {
return strcmp(strtolower($a), strtolower($b));
});
}
}
uksort($options, function ($a, $b) {
return strcmp(strtolower($a), strtolower($b));
});
static::$options = $options;
return $allow_empty ? array('' => '') + $options : $options;
}
示例12: initClassTableMap
/**
* Populates the 'tables > classes' and 'classes > tables' maps.
* @return void
*/
protected static function initClassTableMap()
{
$em = \D::manager();
$driver = $em->getConfiguration()->getMetadataDriverImpl();
static::$tables_to_classes = array();
static::$classes_to_tables = array();
static::$active_classes = array();
// Populate translatable fields
$translateListener = \CMF\Doctrine\Extensions\Translatable::getListener();
// Loop through all Doctrine's class names, get metadata for each and populate the maps
foreach ($driver->getAllClassNames() as $class_name) {
$metadata = $em->getClassMetadata($class_name);
if ($translateListener !== null) {
$tConfig = $translateListener->getConfiguration($em, $class_name);
if (is_array($tConfig) && isset($tConfig['fields']) && is_array($tConfig['fields'])) {
static::$translatable[$class_name] = $tConfig['fields'];
}
}
if ($metadata->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE) {
static::$tables_to_classes[$metadata->table['name']] = $metadata->rootEntityName;
} else {
static::$tables_to_classes[$metadata->table['name']] = $class_name;
}
static::$classes_to_tables[$class_name] = $metadata->table['name'];
if (!$metadata->isMappedSuperclass && is_subclass_of($class_name, 'CMF\\Model\\Base') && $class_name::hasPermissions()) {
if (count($metadata->parentClasses) > 0) {
$parent_class = $metadata->parentClasses[0];
if (!isset(static::$active_classes[$parent_class])) {
static::$active_classes[$parent_class] = array($parent_class, $class_name);
} else {
static::$active_classes[$parent_class][] = $class_name;
}
} else {
if (!isset(static::$active_classes[$class_name])) {
static::$active_classes[$class_name] = array($class_name);
}
}
}
}
}
示例13: action_save_all
/**
* Save everything in the entire DB again
*/
public function action_save_all()
{
try {
set_time_limit(0);
ini_set('memory_limit', '512M');
} catch (\Exception $e) {
// Nothing!
}
// Get driver and get all class names
$driver = \D::manager()->getConfiguration()->getMetadataDriverImpl();
$this->classNames = $driver->getAllClassNames();
foreach ($this->classNames as $class) {
if (is_subclass_of($class, '\\CMF\\Model\\Base')) {
$metadata = $class::metadata();
// Don't process super classes!
if ($class::superclass() || $metadata->isMappedSuperclass) {
continue;
}
$class::saveAll();
\D::manager()->clear();
sleep(1);
}
}
\Session::set_flash('main_alert', array('attributes' => array('class' => 'alert-success'), 'msg' => \Lang::get('admin.messages.save_all_success')));
\Response::redirect_back();
}
示例14: metadata1
protected function metadata1()
{
$metadata = \D::manager()->getClassMetadata('CMF\\Model\\Base');
}
示例15: action_populate
/**
* For asyncronous saving - populates a model with the posted data and responds in JSON
*/
public function action_populate($table_name, $id = null)
{
// Find class name and metadata etc
$class_name = \Admin::getClassForTable($table_name);
if ($class_name === false) {
return $this->show404(null, "type");
}
if (!\CMF\Auth::can('edit', $class_name)) {
return $this->show403('action_singular', array('action' => \Lang::get('admin.verbs.edit'), 'resource' => strtolower($class_name::singular())));
}
// Set the output content type
$this->headers = array("Content-Type: text/plain");
// If $id is null, we're populating multiple items
if ($id === null) {
// Construct the output
$result = array('success' => true, 'num_updated' => 0);
$post_data = \Input::post();
$ids = array_keys($post_data);
$em = \D::manager();
if (count($ids) == 0) {
return \Response::forge(json_encode($result), $this->status, $this->headers);
}
// Get the items we need to save
$items = $class_name::select('item')->where('item.id IN(?1)')->setParameter(1, $ids)->getQuery()->getResult();
if (count($items) == 0) {
return \Response::forge(json_encode($result), $this->status, $this->headers);
}
foreach ($items as $item) {
$id = $item->id;
if (!isset($post_data[$id])) {
continue;
}
$result['num_updated'] += 1;
$data = $post_data[$id];
$item->populate($data, false);
if (!$item->validate()) {
$result['success'] = false;
}
$em->persist($item);
}
// Try and save them all
try {
$em->flush();
} catch (\Exception $e) {
$result['success'] = false;
$result['error'] = $e->getMessage();
}
// Return the JSON response
return \Response::forge(json_encode($result), $this->status, $this->headers);
}
// Find the model, return 404 if not found
$model = $class_name::find($id);
if (is_null($model)) {
return $this->show404(null, "item");
}
// Populate with the POST data
$model->populate(\Input::post(), false);
// Construct the output
$result = array('success' => false);
// Check validation
if ($model->validate()) {
$result['success'] = true;
} else {
$result['validation_errors'] = $model->errors;
}
// Try and save it
try {
$em = \D::manager();
$em->persist($model);
$em->flush();
$result['updated_at'] = $model->updated_at->format("d/m/Y \\a\\t H:i:s");
} catch (\Exception $e) {
$result['success'] = false;
$result['error'] = $e->getMessage();
}
// Return the JSON response
return \Response::forge(json_encode($result), $this->status, $this->headers);
}