Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

main stuff to develop

  • Loading branch information...
commit 9227ec7589ec27a9bd8f3a4271a9d3bf38faf712 1 parent e264458
Sergey Gladkovskiy authored
1  .gitignore
View
@@ -0,0 +1 @@
+nbproject
131 classes/logapp.php
View
@@ -0,0 +1,131 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+
+/**
+ * Controller Logapp
+ *
+ * @author avis <smgladkovskiy@gmail.com>
+ * @todo внедрить кэширование справочника
+ */
+class Logapp {
+
+ // Log instance
+ protected static $instance;
+
+ // Log types array
+ protected static $log_types = array(
+ '_exists' => FALSE,
+ '_parent_id' => NULL);
+
+ // Log results array
+ protected static $log_results = array(
+ '_exists' => FALSE,
+ '_parent_id' => NULL);
+
+ /**
+ * Creates a singleton of a Log Class.
+ *
+ * @return Log
+ */
+ public static function instance()
+ {
+ if ( ! isset(Loagapp::$instance))
+ {
+ // Create a new log instance
+ Loagapp::$instance = new Log();
+ }
+
+ return Loagapp::$instance;
+ }
+
+ /**
+ * Constructor
+ */
+ public function __construct()
+ {
+ $this->_get_namespaces('log_types');
+ $this->_get_namespaces('log_results');
+ }
+
+ /**
+ * Writing a log issue
+ *
+ * @param string $type
+ * @param string $result
+ * @param integer $user
+ * @param string $description
+ */
+ public function write ($type, $result, $user = NULL, $description = NULL)
+ {
+ if( ! arr::get(Loagapp::$log_types, $type))
+ {
+ $this->_set_namespace_item($type, 'log_types');
+ }
+
+ if( ! arr::get(Loagapp::$log_results, $result))
+ {
+ $this->_set_namespace_item($result, 'log_results');
+ }
+
+ Jelly::factory('log')->set(array(
+ 'time' => time(),
+ 'type' => arr::get(Loagapp::$log_types, $type, NULL),
+ 'result' => arr::get(Loagapp::$log_results, $result, NULL),
+ 'user' => $user,
+ 'description' => __($description)
+ ))->save();
+
+ }
+
+ /**
+ * Watching last Log issues
+ *
+ * @param integer $limit
+ * @return object Logs
+ */
+ public function watch($limit = 10)
+ {
+ $logs = Jelly::select('log')
+ ->limit((int) $limit)
+ ->order_by('id', 'DESC');
+ $logs = $logs->execute();
+ return $logs;
+ }
+
+ /**
+ * Getting namespaces by type
+ *
+ * @param string $type
+ */
+ protected function _get_namespaces($type)
+ {
+ $namespaces = Kohana::cache($type);
+ if( ! $namespaces)
+ {
+ $namespaces = Jelly::select($type)
+ ->execute();
+ }
+
+ foreach ($namespaces as $namespace)
+ {
+ Loagapp::${$type}[$namespace->name] = $namespace->id;
+ }
+
+ }
+
+ /**
+ * Setting namespace item for a log section
+ *
+ * @param string $item
+ * @param string $section
+ */
+ protected function _set_namespace_item($item, $section)
+ {
+ $_item = Jelly::factory($section)
+ ->set(array(
+ 'name' => $item
+ ))->save();
+
+ Loagapp::${$section}[$item] = $_item->id;
+ }
+
+} // End Controller log
46 classes/model/log.php
View
@@ -0,0 +1,46 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+
+/**
+ * Jelly Model log
+ *
+ * @author avis <smgladkovskiy@gmail.com>
+ */
+class Model_Log extends Jelly_Model {
+
+ /**
+ * Initializating model meta information
+ *
+ * @param Jelly_Meta $meta
+ */
+ public static function initialize(Jelly_Meta $meta)
+ {
+ $meta->table('logs')
+ ->fields(array(
+ 'id' => new Field_Primary(array(
+ 'label' => __('nn')
+ )),
+ 'time' => new Field_Timestamp(array(
+ 'label' => __('Время'),
+ 'pretty_format' => 'd.m.Y H:i'
+ )),
+ 'type' => new Field_BelongsTo(array(
+ 'label' => __('Событие'),
+ 'foreign' => 'log_types',
+ )),
+ 'result' => new Field_BelongsTo(array(
+ 'label' => __('Результат'),
+ 'foreign' => 'log_results',
+ )),
+ 'user' => new Field_BelongsTo(array(
+ 'label' => __('Пользователь')
+ )),
+ 'description' => new Field_Text(array(
+ 'label' => __('Описание')
+ )),
+ ))
+ ->load_with(array(
+ 'type',
+ //'result',
+ ));
+ }
+} // End Jelly Model Log
23 classes/model/log/result.php
View
@@ -0,0 +1,23 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+
+/**
+ * Jelly Model Log Result
+ *
+ * @author avis <smgladkovskiy@gmail.com>
+ */
+class Model_Log_Result extends Jelly_Model {
+
+ /**
+ * Initializating model meta information
+ *
+ * @param Jelly_Meta $meta
+ */
+ public static function initialize(Jelly_Meta $meta)
+ {
+ $meta->table('log_results')
+ ->fields(array(
+ 'id' => new Field_Primary,
+ 'name' => new Field_String,
+ ));
+ }
+} // End Jelly Model Log Result
23 classes/model/log/type.php
View
@@ -0,0 +1,23 @@
+<?php defined('SYSPATH') OR die('No direct access allowed.');
+
+/**
+ * Jelly Model Log Type
+ *
+ * @author avis <smgladkovskiy@gmail.com>
+ */
+class Model_Log_Type extends Jelly_Model {
+
+ /**
+ * Initializating model meta information
+ *
+ * @param Jelly_Meta $meta
+ */
+ public static function initialize(Jelly_Meta $meta)
+ {
+ $meta->table('log_types')
+ ->fields(array(
+ 'id' => new Field_Primary,
+ 'name' => new Field_String,
+ ));
+ }
+} // End Jelly Model Log Type
0  config/app_log.php
View
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.