Пример #1
0
 public function testFind()
 {
     $tree = new Node();
     $node1 = new Node();
     $node2 = new Node();
     $tree->add($node1);
     $node1->add($node2);
     $this->assertNull($tree->find($node2->hashCode(), false));
     $this->assertEquals($node2, $tree->find($node2->hashCode()));
 }
 /**
  * @mcms_message ru.molinos.cms.cron
  */
 public static function taskRun(Context $ctx)
 {
     $types = $ctx->config->get('modules/subscription/types', array());
     $xsl = $ctx->config->get('modules/subscription/stylesheet', os::path('lib', 'modules', 'subscription', 'message.xsl'));
     $sub = $ctx->config->get('modules/subscription/subject', 'Новости сайта %host');
     if (empty($types)) {
         return;
     }
     $ctx->db->beginTransaction();
     $users = Node::find(array('class' => 'subscription', 'deleted' => 0, 'published' => 1, '#sort' => 'name'), $ctx->db);
     // Обрабатываем активных пользователей.
     foreach ($users as $user) {
         $olast = $last = intval($user->last);
         if ($sections = (array) $user->tags) {
             list($sql, $params) = Query::build(array('class' => $types, 'tags' => $sections, 'published' => 1, 'deleted' => 0, 'id' => array('>' . ($olast + 1))))->getSelect(array('id', 'xml'));
             $nodes = $ctx->db->getResultsKV('id', 'xml', $sql, $params);
             // Отправляем документы.
             foreach ($nodes as $nid => $node) {
                 $xml = html::em('message', array('mode' => 'regular', 'unsubscribe' => 'subscription.rpc?action=remove&name=' . urlencode($user->name) . '&id=' . $user->id, 'base' => $ctx->url()->getBase($ctx), 'host' => MCMS_HOST_NAME), $node);
                 $body = xslt::transform($xml, $xsl, null);
                 $subject = t($sub, array('%host' => $ctx->url()->host()));
                 BebopMimeMail::send(null, $user->name, $subject, $body);
                 $last = max($last, $nid);
             }
             // Запоминаем последнее отправленное сообщение.
             $user->last = $last;
             $user->save();
         }
     }
     $ctx->db->commit();
 }
Пример #3
0
 public function create()
 {
     $node = Node::find(Input::get('node_id'));
     $nodes = Node::allLevelUp();
     //        return View::make('topics.create_edit', compact('nodes', 'node'));
     return View::make('topics.create_article', compact('nodes', 'node'));
 }
Пример #4
0
 public function fire($job, $data)
 {
     $node = Node::find($data['message']['node_id']);
     $node->limbo = false;
     $node->save();
     return $job->delete();
 }
Пример #5
0
 /**
  * @mcms_message ru.molinos.cms.module.settings.drawtext
  */
 public static function on_get_settings(Context $ctx)
 {
     $fonts = array();
     foreach (Node::find(Context::last()->db, array('class' => 'file', 'filetype' => 'application/x-font-ttf')) as $n) {
         $fonts[$n->id] = isset($n->name) ? $n->name : $n->filename;
     }
     return new Schema(array('font' => array('type' => 'EnumControl', 'label' => t('Шрифт по умолчанию'), 'default' => t('(не использовать)'), 'options' => $fonts, 'description' => t('Вы можете <a href=\'@url\'>загрузить новый шрифт</a> в файловый архив.', array('@url' => '?q=admin/content/create&type=file&destination=CURRENT')))));
 }
Пример #6
0
 public static function rpc_purge(Context $ctx)
 {
     $filter = array('class' => 'message', 're' => $ctx->user->id);
     $ids = join(', ', array_keys(Node::find($ctx->db, $filter)));
     if (!empty($ids)) {
         $ctx->db->exec("DELETE FROM `node` WHERE `id` IN ({$ids})");
         mcms::flush();
     }
 }
Пример #7
0
 private static function getGroups()
 {
     $result = array();
     foreach (Node::find(array('class' => 'group')) as $g) {
         $result[$g->id] = $g->name;
     }
     asort($result);
     return $result;
 }
Пример #8
0
 private function getList(Context $ctx)
 {
     $filter = array('class' => 'todo', '#sort' => 'created');
     if (!empty($this->options['rel'])) {
         $rel = $this->options['rel'];
         $filter['id'] = $ctx->db->getResultsV("id", "SELECT n.id AS `id` " . "FROM node n " . "WHERE n.class = 'todo' AND n.id IN " . "(SELECT tid FROM node__rel WHERE nid = ? " . "UNION SELECT nid FROM node__rel WHERE tid = ? " . "UNION SELECT rel FROM node__idx_todo WHERE rel = ?)", array($rel, $rel, $rel));
     }
     return Node::find($ctx->db, $filter);
 }
Пример #9
0
 /**
  * Возвращает форму для настройки виджета.
  *
  * Добавляет к полученной от родиетля форме возможность выбрать базовый
  * виджет, с которым следует работать в паре.  Выбрать позволяют только один
  * из списков (ListWidget).
  *
  * @return Form вкладка формы, используется для настройки виджета.
  */
 public static function getConfigOptions(Context $ctx)
 {
     $widgets = array();
     foreach (Node::find(array('class' => 'widget'), $ctx->db) as $w) {
         if (!strcasecmp('ListWidget', $w->classname)) {
             $widgets[$w->name] = $w->title;
         }
     }
     return array('host' => array('type' => 'EnumControl', 'label' => t('Привязать к виджету'), 'description' => t('Выберите список документов, который будет параметризован этим виджетом.&nbsp; Ссылки, которые формирует навигатор по архиву, будут содержать параметры не для него самого, а для виджета, с которым он связан.'), 'options' => $widgets), 'reverse_years' => array('type' => 'BoolControl', 'label' => t('Список годов в обратном порядке')), 'reverse_months' => array('type' => 'BoolControl', 'label' => t('Список месяцев в обратном порядке')));
 }
Пример #10
0
 public function onGet(array $options)
 {
     $result = array('list' => array());
     $filter = array('class' => 'message', 're' => $options['uid'], 'deleted' => 0, '#sort' => '-id');
     foreach (Node::find($this->ctx->db, $filter, $options['limit']) as $n) {
         $result['list'][] = $n->getRaw();
     }
     $result['count'] = Node::count($filter);
     $result['left'] = $result['count'] - count($result['list']);
     return $result;
 }
Пример #11
0
 public static function on_get_groups(Context $ctx)
 {
     $nodes = Node::find(array('class' => 'group', 'deleted' => 0), $ctx->db);
     $counts = $ctx->db->getResultsKV('id', 'count', "SELECT tid AS id, COUNT(*) AS count FROM node__rel r INNER JOIN node g ON g.id = r.tid INNER JOIN node u ON u.id = r.nid WHERE g.deleted = 0 AND u.deleted = 0 AND g.class = 'group' AND u.class = 'user' GROUP BY tid");
     $html = '';
     foreach ($nodes as $node) {
         $count = isset($counts[$node->id]) ? $counts[$node->id] : 0;
         $html .= html::em('node', array('id' => $node->id, 'name' => $node->getName(), 'created' => $node->created, 'users' => $count, 'editable' => $node->checkPermission(ACL::UPDATE), 'published' => true));
     }
     $html = html::wrap('data', $html);
     return html::em('content', array('name' => 'list', 'preset' => 'groups', 'title' => t('Группы пользователей'), 'nosearch' => true, 'create' => 'admin/create/group'), $html);
 }
 public static function hookRemoteCall(Context $ctx)
 {
     if (null !== $ctx->get('source') and null !== $ctx->get('search')) {
         $output = array();
         $parts = explode('.', $ctx->get('source'), 2);
         foreach (Node::find($ctx->db, $filter = array('class' => $parts[0], $parts[1] => '%' . $ctx->get('search') . '%'), 10) as $n) {
             $output[$n->id] = isset($n->{$parts}[1]) ? $n->{$parts}[1] : $n->name;
         }
         $output = join("\n", array_values($output));
         return new Response($output, 'text/plain');
     }
 }
Пример #13
0
 protected function getData()
 {
     $data = Node::find(array('class' => 'type', 'deleted' => 0, '#sort' => '-published name'), $this->ctx->db);
     $counts = $this->ctx->db->getResultsKV("name", "count", "SELECT `class` AS `name`, COUNT(*) AS `count` FROM `node` WHERE `deleted` = 0 GROUP BY `class`");
     $nodes = '';
     foreach ($data as $node) {
         if ($node->isdictionary) {
             $attrs = array('id' => $node->id, 'name' => $node->name, 'title' => $node->title, 'list' => Node::create($node->name)->getListURL(), 'published' => (bool) $node->published);
             $attrs['count'] = array_key_exists($node->name, $counts) ? $counts[$node->name] : 0;
             $nodes .= html::em('node', $attrs);
         }
     }
     return html::wrap('data', $nodes);
 }
Пример #14
0
 public function set($value, &$node)
 {
     $this->validate($value);
     if (null === ($email = $this->findEmail($node))) {
         throw new InvalidArgumentException(t('Не удалось подписать вас на новости: в профиле не обнаружен ни один почтовый адрес.'));
     }
     $s = Node::find(array('class' => 'subscription', 'name' => $email), $node->getDB());
     if (empty($s)) {
         $s = Node::create('subscription', array('name' => $email));
     } else {
         $s = array_shift($s);
     }
     $s->linkSetParents($value, 'tag', $this->enabled)->save();
 }
Пример #15
0
 public static function openIDAuthorize($openid_mode, Context $ctx)
 {
     self::includeOpenID();
     $mode = $ctx->config->get('modules/openid/mode', 'open');
     if ('none' == $mode) {
         throw new RuntimeException(t('Поддержка OpenID отключена администратором.'));
     }
     if ('id_res' == $openid_mode) {
         $openid = null;
         foreach (array('openid1_claimed_id', 'openid_claimed_id', 'openid_identity') as $key) {
             if (!empty($_GET[$key])) {
                 $openid = $_GET[$key];
                 break;
             }
         }
         if (null === $openid) {
             throw new RuntimeException('OpenID провайдер не вернул идентификатор.');
         }
         $nodes = Node::find(array('class' => 'user', 'name' => $openid, 'deleted' => 0), $ctx->db);
         if (!count($nodes)) {
             if ('open' != $mode) {
                 throw new ForbiddenException(t('Извините, автоматическая регистрация пользователей через OpenID отключена.'));
             }
             $fieldmap = array('sreg_email' => 'email', 'sreg_fullname' => 'fullname', 'sreg_nickname' => 'nickname');
             $node = Node::create(array('class' => 'user', 'parent_id' => null, 'name' => $openid, 'published' => true));
             foreach ($fieldmap as $k => $v) {
                 if (!empty($_GET[$key = 'openid_' . $k])) {
                     $node->{$v} = $_GET[$key];
                 }
             }
             $node->setRegistered($ctx);
             $node->save();
         } else {
             $node = array_shift($nodes);
             if (!$node->published) {
                 throw new ForbiddenException(t('Ваш профиль заблокирован.'));
             }
         }
         return $node;
     } else {
         // Login canceled
         Logger::log('login cancelled ?!');
         $ctx->redirect("auth/logout.rpc");
     }
 }
Пример #16
0
 /**
  * {@inheritdoc}
  */
 public function main(App $app)
 {
     $app['node'] = function ($app) {
         if ($id = $app['request']->attributes->get('_node') and $node = Node::find($id, true)) {
             return $node;
         }
         return Node::create();
     };
     $app['menu'] = function ($app) {
         $menus = new MenuManager($app->config($app['theme']->name), $this->config('menus'));
         foreach ($app['theme']->get('menus', []) as $name => $label) {
             $menus->register($name, $label);
         }
         return $menus;
     };
     $app->extend('view', function ($view) use($app) {
         return $view->addHelper(new MenuHelper($app['menu']));
     });
 }
Пример #17
0
 /**
  * Формирует обратное облако (используемых объектов). Применяется, например,
  * для оценки редакторской активности.
  */
 public static function on_get_cloud_rev_xml(Context $ctx)
 {
     list($st, $tt, $limit, $cache) = self::get_params($ctx);
     if ($cache) {
         $ckey = 'cloud/rev';
         if ($ctx->get('extended')) {
             $ckey .= '/ext';
         }
         $ttl = floor(time() / $cache);
         $ckey = sprintf($ckey . '/%s/%s/%u/%u', $st, $tt, $limit, floor(time() / $cache));
         if ($cached = cache::getInstance()->{$ckey}) {
             return new Response($cached, 'text/xml');
         }
     }
     $params = array();
     $sql1 = sql::in(explode(' ', $st), $params);
     $sql2 = sql::in(explode(' ', $tt), $params);
     $data = $ctx->db->getResults($sql = 'SELECT n.id AS id, n.name AS name, ' . 'COUNT(*) AS `cnt` ' . 'FROM node n ' . 'INNER JOIN node__rel r ON r.nid = n.id ' . 'WHERE n.class ' . $sql1 . ' ' . 'AND n.published = 1 ' . 'AND n.deleted = 0 ' . 'AND r.tid IN (SELECT id FROM node WHERE published = 1 AND deleted = 0 AND class ' . $sql2 . ') ' . 'GROUP BY n.id, n.name ' . 'ORDER BY cnt DESC LIMIT ' . $limit, $params);
     // Идентификаторы объектов, для получения расширенной информации
     $nids = array();
     // Считаем общее количество объектов.
     $count = 0;
     foreach ($data as $item) {
         $count += $item['cnt'];
         $nids[] = $item['id'];
     }
     $percent = $count / 100;
     $nodes = $ctx->get('extended') ? Node::find(array('id' => $nids), $ctx->db) : array();
     $result = '';
     $keys = array();
     foreach ($data as $item) {
         $p = round($item['cnt'] / $percent);
         $name = isset($nodes[$item['id']]) ? $nodes[$item['id']]->getName() : $item['name'];
         $result .= html::em('item', array('id' => $item['id'], 'name' => trim($name), 'count' => $item['cnt'], 'percent' => $p, 'weight' => round($p / 10) + 1));
         $keys[] = $item['id'];
     }
     $xml = html::em('cloud', array('total' => $count), $result);
     if ($cache) {
         cache::getInstance()->{$ckey} = $xml;
     }
     return new Response($xml, 'text/xml');
 }
Пример #18
0
 public function onGet(array $options)
 {
     $result = array();
     $filter = array('class' => 'blog', 'published' => 1, '#sort' => '-id');
     if (null !== $options['user']) {
         $user = array_pop(Node::find($this->ctx->db, array('class' => 'user', 'published' => 1, 'login' => $options['user'])));
         if (empty($user)) {
             throw new PageNotFoundException();
         }
         $result['user'] = $user->getRaw();
         if (array_key_exists('password', $result['user'])) {
             unset($result['user']['password']);
         }
         $filter['uid'] = $user->id;
     }
     $total = Node::count($this->ctx->db, $filter);
     $result['pager'] = parent::getPager($total, $options['page'], $options['limit']);
     foreach (Node::find($this->ctx->db, $filter, $options['limit'], $options['limit'] * ($options['page'] - 1)) as $post) {
         $result['documents'][] = $post->getRaw();
     }
     return $result;
 }
Пример #19
0
 public static function hookRemoteCall(Context $ctx)
 {
     if (!count($nids = explode(',', $ctx->get('nodes')))) {
         throw new InvalidArgumentException('Nodes not specified.');
     }
     $output = '';
     $tracks = array();
     foreach ($nodes = Node::find($ctx->db, array('class' => 'file', 'id' => $nids)) as $node) {
         $track = html::em('title', $node->name);
         $track .= html::em('location', 'http://' . $_SERVER['HTTP_HOST'] . 'attachment/' . $node->id . '?' . $node->filename);
         $tracks[] = html::em('track', $track);
     }
     if (empty($tracks)) {
         throw new PageNotFoundException();
     }
     // TODO: если запрошен один документ, и это — не файл, можно сразу возвращать все его файлы.
     $output .= "<?xml version='1.0' encoding='utf-8'?>";
     $output .= "<playlist version='1' xmlns='http://xspf.org/ns/0/'>";
     $output .= html::em('trackList', join('', $tracks));
     $output .= '</playlist>';
     return new Response($output, 'application/xspf+xml');
 }
Пример #20
0
 /**
  * Вывод поисковой формы.
  */
 public static function on_get_search_form(Context $ctx)
 {
     $output = '';
     $url = new url($ctx->get('destination', $ctx->get('from')));
     if (null === $url->arg('preset')) {
         $types = Node::find(array('class' => 'type', 'published' => 1, 'deleted' => 0, 'name' => $ctx->user->getAccess(ACL::READ)), $ctx->db);
         $list = array();
         foreach ($types as $type) {
             if (!$type->isdictionary) {
                 $list[$type->name] = $type->title;
             }
         }
         asort($list);
         if ('file' == ($type = $ctx->get('type')) and array_key_exists($type, $list)) {
             $list = array($type => $type);
         }
         $tmp = '';
         foreach ($list as $k => $v) {
             $tmp .= html::em('type', array('name' => $k, 'title' => $v));
         }
         $output .= html::em('types', $tmp);
     }
     $tmp = '';
     foreach (Node::getSortedList('user', 'fullname', 'id') as $k => $v) {
         $tmp .= html::em('user', array('id' => $k, 'name' => $v));
     }
     $output .= html::em('users', $tmp);
     if (null === $url->arg('preset')) {
         $tmp = '';
         foreach (Node::getSortedList('tag', 'id', 'name') as $k => $v) {
             $tmp .= html::em('section', array('id' => $k, 'name' => $v));
         }
         $output .= html::em('sections', $tmp);
     }
     return html::em('content', array('name' => 'search', 'query' => self::get_clean_query($url->arg('search')), 'from' => urlencode($ctx->get('from'))), $output);
 }
Пример #21
0
    ?>
			<tr>
				<td><?php 
    echo User::find($alert->user_id)->name;
    ?>
</td>
				<td>All Packages</td>
				<td><?php 
    if ($alert->condition == -1) {
        ?>
				All Managed Nodes
				<?php 
    } else {
        ?>
				<?php 
        echo Node::find($alert->condition)->hostname;
        ?>
				<?php 
    }
    ?>
				</td>
				<td><?php 
    if ($alert->value == 1) {
        ?>
				New vulnerabilities are discovered.
				<?php 
    } elseif ($alert->value == 2) {
        ?>
				Existing vulnerabilties are remedied.
				<?php 
    }
Пример #22
0
 /**
  * test that saving HABTM with an empty array will clear existing HABTM if
  * unique is true
  *
  * @return void
  */
 public function testSaveHabtmEmptyData()
 {
     $this->loadFixtures('Node', 'Dependency');
     $Node = new Node();
     $data = array('Node' => array('name' => 'New First'));
     $Node->id = 1;
     $Node->save($data);
     $node = $Node->find('first', array('conditions' => array('Node.id' => 1), 'contain' => array('ParentNode')));
     $result = Hash::extract($node, 'ParentNode.{n}.id');
     $expected = array(2);
     $this->assertEquals($expected, $result);
     $data = array('ParentNode' => array());
     $Node->id = 1;
     $Node->save($data);
     $node = $Node->find('first', array('conditions' => array('Node.id' => 1), 'contain' => array('ParentNode')));
     $result = Hash::extract($node, 'ParentNode.{n}.id');
     $expected = array();
     $this->assertEquals($expected, $result);
 }
Пример #23
0
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
    //
});
App::after(function ($request, $response) {
    //
});
Route::filter('isNodeOwner', function ($route) {
    $node_id = $route->getParameter('nodes');
    if (Auth::user()->id !== Node::find($node_id)->owner_id) {
        App::abort(401, 'Unauthorized access attempt');
    }
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function () {
    if (Auth::guest()) {
Пример #24
0
 /**
  * Возвращает обрабатываемые ноды.
  * Для запросов методом POST использует массив selected[],
  * для запросов методом GET — параметр node.
  */
 private static function getNodes(Context $ctx)
 {
     if ($ctx->method('post')) {
         $ids = $ctx->post('selected', array());
     } else {
         $ids = explode(' ', $ctx->get('node'));
     }
     if (empty($ids)) {
         throw new BadRequestException(t('Не указаны идентификаторы документов (POST-массив selected[] или GET-параметр node)'));
     }
     return Node::find(array('id' => $ids), $ctx->db);
 }
Пример #25
0
 public function backportLinkedFields()
 {
     if (!empty($this->fields)) {
         return;
     }
     $fields = Node::find(array('class' => 'field', 'deleted' => 0, 'tags' => $this->id), $this->getDB());
     if (!empty($fields)) {
         $result = array();
         foreach ($fields as $field) {
             foreach (array('label', 'type', 'weight', 'indexed', 'required', 'description', 'group') as $key) {
                 if (!empty($field->{$key})) {
                     $result[$field->name][$key] = $field->{$key};
                 }
             }
         }
         $this->fields = $result;
         return true;
     }
 }
Пример #26
0
 public static function getSortedList($class, $field = 'name', $key = 'id')
 {
     $result = array();
     // Вывод дерева страниц и разделов
     if (in_array($class, array('tag', 'domain'))) {
         $result = array();
         foreach (Node::listChildren($class) as $item) {
             $result[$item[0]] = str_repeat(' ', 2 * $item[2]) . $item[1];
         }
     } else {
         foreach ((array) Node::find(array('class' => $class, 'deleted' => 0)) as $n) {
             $value = 'name' == $field ? $n->getName() : $n->{$field};
             if (empty($value)) {
                 $value = $n->getName();
             }
             $result[$n->{$key}] = $value;
         }
         asort($result);
     }
     return $result;
 }
Пример #27
0
 public function edit($id)
 {
     $node = Node::find($id);
     return View::make('nodes.edit', compact('node'));
 }
 public function read(Model $Model, $queryData = array(), $recursive = null)
 {
     $queryType = 'all';
     $query = array();
     if (!isset($queryData['recursive'])) {
         $queryData['recursive'] = $Model->recursive;
     }
     $query['conditions'] = $this->__rebuildConditions($Model, $queryData['conditions']);
     $query['conditions'][$this->Node->alias . '.type'] = Inflector::singularize($Model->table);
     foreach ($queryData['order'] as $orderData) {
         if (!$orderData) {
             continue;
         }
         foreach ($orderData as $field => $condition) {
             list($field, $model) = array_reverse(explode('.', $field));
             $query['order'][$this->Node->alias . '.' . $field] = $condition;
         }
     }
     if (is_array($queryData['fields'])) {
         foreach ($queryData['fields'] as $field) {
             if (!$field) {
                 continue;
             }
             if (strstr($field, '.')) {
                 list($field, $model) = array_reverse(explode('.', $field));
             }
             $query['fields'][] = $this->Node->alias . '.' . $field;
         }
     } else {
         if ($queryData['fields'] === 'COUNT') {
             $queryType = 'count';
         }
     }
     //		if ($queryData['limit']) {
     //			$query['limit'] = $queryData['limit'];
     //		}
     //		if ($queryData['offset']) {
     //			$query['offset'] = $queryData['offset'];
     //		}
     //		debug($query);
     $nodes = $this->Node->find('all', $query);
     //		debug($nodes);
     $fields = array_keys($this->describe($Model));
     $modelData = array();
     foreach ($nodes as $node) {
         $modelEntry = array();
         $modelEntry[$Model->alias] = $node['Node'];
         unset($modelEntry[$Model->alias]['url']);
         unset($modelEntry[$Model->alias]['type']);
         foreach ($fields as $field) {
             if (isset($modelEntry[$Model->alias][$field])) {
                 continue;
             }
             $modelEntry[$Model->alias][$field] = null;
         }
         $relations = array_merge(array_keys($Model->belongsTo), array_keys($Model->hasOne), array_keys($Model->hasMany));
         foreach ($relations as $relation) {
             if (!isset($node[$relation])) {
                 continue;
             }
             $modelEntry[$relation] = $node[$relation];
         }
         if (isset($modelEntry['Meta'])) {
             foreach ($modelEntry['Meta'] as $meta) {
                 $modelEntry[$Model->alias][$meta['key']] = $meta['value'];
             }
         }
         $modelData[] = $modelEntry;
     }
     $modelData = $this->__filterLocal($Model, $queryData['conditions'], $modelData);
     if (isset($queryData['limit'])) {
         $modelData = array_slice($modelData, isset($queryData['offset']) ? $queryData['offset'] : 0, $queryData['limit']);
     }
     if ($queryData['fields'] === 'COUNT') {
         return array(array(array('count' => $modelData)));
     }
     if ($queryData['recursive'] > -1) {
         foreach ($Model->_associations as $type) {
             foreach ($Model->{$type} as $assoc => $assocData) {
                 $LinkModel = $Model->{$assoc};
                 $stack = array($assoc);
                 $this->queryAssociation($Model, $LinkModel, $type, $assoc, $assocData, $queryData, true, $modelData, $queryData['recursive'] - 1, $stack);
             }
         }
     }
     return $modelData;
 }
Пример #29
0
 public function getFormattedParentNodeAttribute()
 {
     $parent_id = $this->getAttribute('parent_node');
     $parent_node = Node::find($parent_id);
     return $parent_node->name;
 }
Пример #30
0
 private static function fixNames(array $nodes)
 {
     $uids = array();
     foreach ($nodes as $k => $v) {
         if (null !== $v->uid and !is_object($v->uid)) {
             $uids[] = $v->uid;
         }
         if (null !== $v->node) {
             $uids[] = $v->node;
         }
     }
     if (empty($uids)) {
         $users = array();
     } else {
         $users = Node::find(context::last()->db, array('id' => array_unique($uids)));
     }
     foreach ($nodes as $k => $v) {
         if (null !== $v->uid and !is_object($v->uid) and array_key_exists($v->uid, $users)) {
             $v->uid = $users[$v->uid];
         }
         if (null !== $v->node and array_key_exists($v->node, $users)) {
             $v->node = $users[$v->node];
         }
         $nodes[$k] = $v->getRaw();
     }
     return $nodes;
 }