Пример #1
0
 private function installTypes()
 {
     if (!Node::count($this->ctx->db, array('class' => 'type', 'name' => 'blog'))) {
         $type = Node::create('type', array('name' => 'blog', 'title' => t('Запись в дневнике'), 'description' => t('Ваш дневник — ваше личное пространство на этом сервере.  Можете писать здесь всё, что угодно. Другие пользователи смогут это читать и комментировать, но на главную страницу эта информация не попадёт.  Туда попадают только статьи.'), 'fields' => array('name' => array('type' => 'TextLineControl', 'label' => t('Заголовок'), 'required' => true), 'teaser' => array('type' => 'TextAreaControl', 'label' => t('Краткое содержание')), 'body' => array('type' => 'TextHTMLControl', 'label' => t('Текст записи'), 'required' => true), 'picture' => array('type' => 'AttachmentControl', 'label' => t('Иллюстрация')))));
         $type->save();
     }
 }
Пример #2
0
 private function installTypes()
 {
     // ЧАСТЬ ПЕРВАЯ: заказ.
     if (!Node::count(array('class' => 'type', 'name' => 'order'))) {
         $type = Node::create('type', array('name' => 'order', 'title' => t('Заказ'), 'description' => t('Документы этого типа создаются автоматически при оформлении заказов на сайте.'), 'fields' => array('name' => array('type' => 'TextLineControl', 'label' => t('Ф.И.О.'), 'description' => t('Эта информация нужна нам для обратной связи и доставки (если она осуществляется).'), 'required' => true), 'email' => array('type' => 'EmailControl', 'label' => t('Адрес электронной почты'), 'required' => true), 'phone' => array('type' => 'TextLineControl', 'label' => t('Контактный телефон')), 'address' => array('type' => 'TextAreaControl', 'label' => t('Адрес доставки')), 'orderdetauks' => array('type' => 'OrderDetailsControl', 'label' => t('Содержимое заказа'), 'required' => false, 'readonly' => true))));
         $type->save();
     }
 }
Пример #3
0
 /**
  * @mcms_message ru.molinos.cms.install
  */
 public static function onInstall(Context $ctx)
 {
     $count = Node::count(array('class' => 'type', 'name' => 'order', 'deleted' => 0), $ctx->db);
     if (!$count) {
         $ctx->db->beginTransaction();
         Node::create(array('class' => 'type', 'name' => 'order', 'title' => 'Заказ'))->save();
         $ctx->db->commit();
     }
 }
Пример #4
0
 private static function checkInstalled()
 {
     try {
         if (Node::count(array())) {
             return true;
         }
     } catch (Exception $e) {
     }
     return false;
 }
Пример #5
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;
 }
Пример #6
0
 /**
  * Добавление действия ко всем документам.
  * @mcms_message ru.molinos.cms.node.actions
  */
 public static function on_get_actions(Context $ctx, Node $node)
 {
     if ($node instanceof FileNode or !$node->checkPermission(ACL::UPDATE)) {
         return;
     }
     $count = Node::count(array('class' => 'file', 'deleted' => 0, 'tags' => $node->id), $node->getDB());
     if ($count) {
         return array('attach' => array('href' => "admin/node/attach?id={$node->id}&destination=CURRENT", 'title' => t('Управление файлами'), 'scope' => 'edit'));
     } else {
         return array('attach' => array('href' => "admin/create/file?sendto={$node->id}&destination=CURRENT", 'title' => t('Добавить файлы'), 'scope' => 'edit'));
     }
 }
Пример #7
0
 public static function list_xml(Context $ctx)
 {
     $filter = array('deleted' => 0, 'published' => 1, '#sort' => $ctx->get('sort', '-id'), '#limit' => $ctx->get('limit', 10), '#offset' => $ctx->get('skip', 0));
     if ($tmp = $ctx->get('class')) {
         $filter['class'] = self::split($tmp);
     }
     if ($tmp = $ctx->get('tags')) {
         $filter['tags'] = self::split($tmp);
     }
     if ($tmp = $ctx->get('tagged')) {
         $filter['tagged'] = self::split($tmp);
     }
     if ($tmp = $ctx->get('author')) {
         $filter['uid'] = $tmp;
     }
     foreach (explode(',', $ctx->get('filters')) as $f) {
         if (!empty($f)) {
             $filter[$f] = $ctx->get($f);
         }
     }
     $attrs = array('limit' => $filter['#limit'], 'skip' => $filter['#offset']);
     $output = Node::findXML($filter, $ctx->db);
     if ($ctx->get('pager')) {
         $attrs['total'] = Node::count($filter, $ctx->db);
         $attrs['prev'] = max($filter['#offset'] - $filter['#limit'], 0);
         if ($filter['#offset'] + $filter['#limit'] < $attrs['total']) {
             $attrs['next'] = $filter['#offset'] + $filter['#limit'];
         }
         // Вычисляем диапазон.
         if ($attrs['total']) {
             $r1 = $filter['#offset'] + 1;
             $r2 = min($attrs['total'], $filter['#offset'] + $filter['#limit']);
             $attrs['range'] = $r1 . '-' . $r2;
         }
     }
     return self::xml(html::em('nodes', $attrs, $output));
 }
Пример #8
0
 public function getPreviewXML(Context $ctx)
 {
     $result = parent::getPreviewXML($ctx);
     if (!$this->published) {
         $message = t('Документы этого (скрытого) типа не отображаются в обычном <a href="@url1">списке документов</a>, их не предлагают в стандартной <a href="@url2">форме создания документа</a>.', array('@url1' => 'admin/content/list', '@url2' => 'admin/create'));
         $result .= html::em('field', array('title' => t('Комментарий')), html::em('value', html::cdata($message)));
     }
     $count = Node::count(array('class' => $this->name, 'deleted' => 0), $ctx->db);
     if ($count) {
         $message = t('%count документов (<a href="@url">список</a>)', array('%count' => $count, '@url' => Node::create($this->name)->getListURL()));
         $result .= html::em('field', array('title' => t('Статистика')), html::em('value', html::cdata($message)));
     }
     return $result;
 }
Пример #9
0
 /**
  * Проверка уникальности.
  *
  * @param string $field имя поля, по которому проверяется уникальность.  Поле
  * должно быть базовым или должно быть проиндексировано.  Обычно используется
  * "name".
  *
  * @param string $message сообщение об ошибке при нарушении уникальности. По
  * умолчанию: "Такой объект уже существует".
  *
  * @param array $filter Дополнительные условия, накладываемые на проверяемые
  * объекты.  Например, можно указать "parent_id" для обеспечния уникальности в
  * рамках одной ветки — так работает проверка имени страницы, например.
  *
  * @return void
  */
 protected function checkUnique($field, $message = null, array $filter = array())
 {
     if ($this->deleted) {
         return;
     }
     $filter['class'] = $this->class;
     $filter['deleted'] = 0;
     $filter[$field] = $this->{$field};
     if ($this->id) {
         $filter['-id'] = $this->id;
     }
     try {
         if (Node::count($filter, $this->getDB())) {
             throw new DuplicateException($message ? $message : t('Такой объект уже существует.'));
         }
     } catch (PDOException $e) {
     }
 }
Пример #10
0
 protected function onGetLast(array $options)
 {
     $result = array();
     $filter = array('class' => 'comment', 'published' => 1, '#sort' => '-id');
     if (($count = Node::count($this->ctx->db, $filter)) > $this->perpage) {
         $result['pager'] = $this->getPager($count, $options['page'], $this->perpage);
     }
     $page = empty($result['pager']['current']) ? 1 : $result['pager']['current'];
     $limit = $this->perpage;
     $offset = ($page - 1) * $limit;
     $result['comments'] = self::fixNames(Node::find($this->ctx->db, $filter, $limit, $offset));
     if (!empty($result['comments'])) {
         $parents = array();
         $cids = join(', ', array_keys($result['comments']));
         $map = $this->ctx->db->getResultsKV("nid", "tid", "SELECT `r`.`nid` as `nid`, `r`.`tid` as `tid` FROM `node__rel` `r` WHERE `r`.`nid` IN ({$cids})");
         $nodes = Node::find($this->ctx->db, array('id' => array_unique($map)));
         foreach ($map as $k => $v) {
             $result['comments'][$k]['node'] = $nodes[$v]->getRaw();
         }
     }
     if (null !== $this->ctx->document->id) {
         $result['root'] = $this->ctx->document->getRaw();
     }
     return $result;
 }
Пример #11
0
 private static function haveRoot()
 {
     return Node::count(array('class' => 'tag', 'parent_id' => null, 'deleted' => 0));
 }
Пример #12
0
 /**
  * Возвращает дополнительные поля для предварительного просмотра.
  */
 public function getPreviewXML(Context $ctx)
 {
     $result = parent::getPreviewXML($ctx);
     if ($this->width and $this->height) {
         $tmp = $this->width . '×' . $this->height;
         if ($this->filesize) {
             $tmp .= ', ' . mcms::filesize($this->filesize);
         }
         $result .= html::em('field', array('title' => t('Исходные размеры')), html::em('value', html::cdata($tmp)));
     }
     if ($this->duration) {
         $result .= html::em('field', array('title' => t('Продолжительность')), html::em('value', html::cdata($this->duration)));
     }
     if ($this->bitrate) {
         $result .= html::em('field', array('title' => t('Битрейт')), html::em('value', html::cdata(ceil($this->bitrate))));
     }
     if ($this->channels) {
         switch ($this->channels) {
             case 1:
                 $tmp = t('моно');
                 break;
             case 2:
                 $tmp = t('стерео');
                 break;
             case 4:
                 $tmp = t('квадро');
                 break;
             default:
                 $tmp = t('%count каналов', array('%count' => $this->channels));
         }
         $result .= html::em('field', array('title' => t('Звук')), html::em('value', array('channels' => $this->channels), html::cdata($tmp)));
     }
     if ($tmp = $this->getEmbedHTML($ctx)) {
         $result .= html::em('field', array('title' => t('Оригинал')), html::em('value', array('class' => 'embed'), html::cdata($tmp)));
     }
     if (!empty($this->versions)) {
         foreach ((array) $this->versions as $name => $info) {
             $em = array('title' => t('Версия %name', array('%name' => $name)));
             $url = os::webpath($ctx->config->getPath('modules/files/storage'), $info['filename']);
             $tmp = t('<a href="@url"><img src="@url" width="%width" height="%height" alt="%filename" /></a>', array('%name' => $name, '%width' => $info['width'], '%height' => $info['height'], '%filename' => basename($info['filename']), '@url' => $url));
             $tmp .= t('<br/>%width×%height', array('%width' => $info['width'], '%height' => $info['height']));
             $em['#text'] = html::em('value', html::cdata($tmp));
             $result .= html::em('field', $em);
         }
     }
     $count = Node::count(array('deleted' => 0, 'tagged' => $this->id), $ctx->db);
     if ($count) {
         $message = t('%count документов используют этот файл (<a href="@url">список</a>)', array('%count' => $count, '@url' => 'admin/content/list?search=tagged%3A' . $this->id));
         $result .= html::em('field', array('title' => t('Статистика')), html::em('value', html::cdata($message)));
     }
     return $result;
 }
Пример #13
0
 protected function getCount()
 {
     if (null === $this->pgcount) {
         switch ($this->preset) {
             case '404':
                 $this->pgcount = $this->ctx->db->fetch("SELECT COUNT(*) FROM `node__fallback`");
                 break;
             default:
                 $filter = $this->getNodeFilter();
                 $this->pgcount = Node::count($filter, $this->ctx->db);
         }
     }
     return $this->pgcount;
 }
Пример #14
0
 public function testCountDeletedNodes()
 {
     $db = get_test_context()->db;
     $count = $db->getResult("SELECT COUNT(*) FROM `node` WHERE `class` = 'type' AND `deleted` = 1");
     $this->assertEquals($count, Node::count(array('class' => 'type', 'deleted' => 1)));
 }