Commits

Bogdan Savluk  committed 2d4d1a8

start using migrations, added table prefix for db connection,
updated admin module, added site/siteMap action,
behavior to manage many to many relation, behaviour for formatted date field,
removed some outdated junk

  • Participants
  • Parent commits 5ebf13e

Comments (0)

Files changed (21)

 .idea
 app/gallery
 app/protected/config/main.php
-*.mwb.bak
+app/protected/config/console.php
+*.mwb.bak
+app/images
 app/protected/extensions/swiftMailer=https://bitbucket.org/z_bodya/yii-swiftmailer
 app/protected/extensions/multiselect=https://bitbucket.org/z_bodya/yii-multiselect
 app/protected/extensions/datetimepicker=https://bitbucket.org/z_bodya/yii-datetimepicker
-app/protected/extensions/admin=ssh://hg@bitbucket.org/z_bodya/yii-admin
+app/protected/extensions/admin=https://bitbucket.org/z_bodya/yii-admin
+app/protected/extensions/settings=https://bitbucket.org/z_bodya/yii-settings
 
-1e7750a32a039b4f05b48d0f2b0c255bd48bc2d9 app/protected/extensions/admin
+8b490d2e3b3324b9d019578220c8bccaba5cd5ba app/protected/extensions/admin
 32f6261081e6b6e874e9e7d280a06b11683d7fcb app/protected/extensions/chosen
 10f95710bd0c9fabee232b0b5dd6d0b9fa0c1928 app/protected/extensions/coordinatepicker
 9de050cb21a3dd1e4be5399dfd3f2cc2d7a6df01 app/protected/extensions/datetimepicker
 f0142cc5cb14eb3dac7386fef8687347a340b6ad app/protected/extensions/elFinder
-9b139a80de80fe528f69d02e57ef6af02a6e88f9 app/protected/extensions/fileimagearbehavior
+b39059da1fe59dcb672876e92fcf844ed242a5a9 app/protected/extensions/fileimagearbehavior
 ecd2dec6c92bf0789054ae888ee4e92827c17b42 app/protected/extensions/galleryManager
 2c669abd97f92c898b10672b8ebf0f2f7e73ff27 app/protected/extensions/image
 2ac3fda0ab7e2754826e5969cff43ec5ddf4229b app/protected/extensions/multiselect
+8dc517ab01762a9f33feb6e6cdef319f02c0ff05 app/protected/extensions/settings
 29a901c09ec8ec796efe967b2eb127790a78e3ea app/protected/extensions/swiftMailer
 4a204c302973fade3c2afdf56aec9729c5b655d5 app/protected/extensions/tinymce

File app/index.php

 
 // change the following paths if necessary
 $yii=dirname(__FILE__).'/../../yii-1.1.13/framework/yii.php';
-$config=dirname(__FILE__).'/protected/config/main.php';
+$config=dirname(__FILE__).'/protected/config/web.php';
 
 // remove the following lines when in production mode
 defined('YII_DEBUG') or define('YII_DEBUG',true);

File app/protected/components/FormattedDateFieldBehavior.php

+<?php
+
+/**
+ * Behavior to add custom formatted date time field to model.
+ *
+ * @author Bogdan Savluk <savluk.bogdan@gmail.com>
+ *
+ * Example configuration:
+ *
+ *   'dateRuBehavior' => array(
+ *        'class' => 'FormattedDateFieldBehavior',
+ *        'fieldName' => 'dateRu',
+ *        'fieldFormat' => 'dd.MM.yyyy hh:mm:ss',
+ *        'modelFieldName' => 'date',
+ *        'modelFieldFormat' => 'yyyy-MM-dd hh:mm:ss',
+ *   )
+ */
+class FormattedDateFieldBehavior extends CActiveRecordBehavior
+{
+
+    public $fieldName;
+    public $fieldFormat;
+
+    public $modelFieldName;
+    public $modelFieldFormat;
+
+    public function hasProperty($name)
+    {
+        if ($name == $this->fieldName) return true;
+        return parent::hasProperty($name);
+    }
+
+    public function canGetProperty($name)
+    {
+        if ($name == $this->fieldName) return true;
+        return parent::canGetProperty($name);
+    }
+
+    public function canSetProperty($name)
+    {
+        if ($name == $this->fieldName) return true;
+        return parent::canSetProperty($name);
+    }
+
+    public function __get($name)
+    {
+        if ($name == $this->fieldName) {
+            return $this->getField();
+        }
+        return parent::__get($name);
+    }
+
+    public function __set($name, $value)
+    {
+        if ($name == $this->fieldName) {
+            $this->setField($value);
+        } else {
+            parent::__set($name, $value);
+        }
+    }
+
+    private function getField()
+    {
+        $date = $this->getOwner()->{$this->modelFieldName};
+        if ($date !== null)
+            $timestamp = CDateTimeParser::parse($date, $this->modelFieldFormat);
+        else
+            $timestamp = time();
+        return Yii::app()->dateFormatter->format($this->fieldFormat, $timestamp);
+    }
+
+    private function setField($value)
+    {
+        $timestamp = CDateTimeParser::parse($value, $this->fieldFormat);
+        $this->getOwner()->{$this->modelFieldName} = Yii::app()->dateFormatter->format($this->modelFieldFormat, $timestamp);
+    }
+}

File app/protected/components/RelatedIdsFieldBehavior.php

+<?php
+
+/**
+ * Adds field to manage many-to-many relation
+ *
+ * @author Bogdan Savluk <savluk.bogdan@gmail.com>
+ *
+ * Example configuration, for models:
+ *
+ *      Picture(id),
+ *      PictureCategory(id),
+ *      PictureHasCategory(picture_id, picture_category_id)
+ *
+ *      'pictureCategoryIdsBehavior' => array(
+ *          'class' => 'RelatedIdsFieldBehavior',
+ *          'modelName' => 'PictureHasCategory',
+ *          'relatedId' => 'picture_category_id',
+ *          'ownerId' => 'picture_id',
+ *          'relatedModelId' => 'id',
+ *          'modelId' => 'id',
+ *          'fieldName' => 'pictureCategoryIds',
+ *          'relationName' => 'pictureCategories',
+ *      ),
+ */
+class RelatedIdsFieldBehavior extends CActiveRecordBehavior
+{
+    /**
+     * Name of model for many-to-many relation table
+     * @var string
+     */
+    public $modelName;
+
+    /**
+     * Name of filed for related model id in relation table
+     * @var string
+     */
+    public $relatedId;
+
+    /**
+     * Name of filed for owner model id in relation table
+     * @var string
+     */
+    public $ownerId;
+
+    /**
+     * Name of id filed in related model
+     * @var string
+     */
+    public $relatedModelId;
+
+    /**
+     * Name of id filed in host model
+     * @var string
+     */
+    public $modelId;
+
+    /**
+     * Name of filed to add into model
+     * @var string
+     */
+    public $fieldName;
+
+    /**
+     * Name of many-to-many relation in owner
+     * @var string
+     */
+    public $relationName;
+
+    private $_relatedIds;
+
+    public function hasProperty($name)
+    {
+        if ($name == $this->fieldName) return true;
+        return parent::hasProperty($name);
+    }
+
+    public function canGetProperty($name)
+    {
+        if ($name == $this->fieldName) return true;
+        return parent::canGetProperty($name);
+    }
+
+    public function canSetProperty($name)
+    {
+        if ($name == $this->fieldName) return true;
+        return parent::canSetProperty($name);
+    }
+
+    public function __get($name)
+    {
+        if ($name == $this->fieldName) {
+            return $this->getRelatedIds();
+        }
+        return parent::__get($name);
+    }
+
+    public function __set($name, $value)
+    {
+        if ($name == $this->fieldName) {
+            $this->setRelatedIds($value);
+        } else {
+            parent::__set($name, $value);
+        }
+    }
+
+
+    private function getRelatedIds()
+    {
+        if (!isset($this->_relatedIds)) {
+            $res = array();
+            foreach ($this->owner->{$this->relationName} as $related) {
+                $res[] = $related->{$this->relatedModelId};
+            }
+            $this->_relatedIds = $res;
+        }
+        return $this->_relatedIds;
+    }
+
+    public function setRelatedIds($value)
+    {
+        if (is_array($value))
+            $this->_relatedIds = $value;
+    }
+
+    public function afterSave($event)
+    {
+        parent::afterSave($event);
+        $relatedModels = $this->owner->{$this->relationName};
+
+        $relatedIds = array_flip($this->getRelatedIds());
+        foreach ($relatedModels as $related) {
+            if (!isset($relatedIds[$related->{$this->relatedModelId}])) {
+                $this->getModel()->deleteByPk(array(
+                    $this->ownerId => $this->owner->{$this->modelId},
+                    $this->relatedId => $related->{$this->relatedModelId}
+                ));
+            }
+        }
+        $idsToAdd = $relatedIds;
+        foreach ($relatedModels as $related) {
+            if (isset($idsToAdd[$related->{$this->relatedModelId}]))
+                unset($idsToAdd[$related->{$this->relatedModelId}]);
+        }
+        foreach ($idsToAdd as $id => $v) {
+            $rel = $this->newRelation();
+            $rel->{$this->ownerId} = $this->owner->{$this->modelId};
+            $rel->{$this->relatedId} = $id;
+            $rel->save();
+        }
+    }
+
+    public function beforeDelete($event)
+    {
+        $this->getModel()->deleteAll($this->ownerId . ' = ' . $this->owner->{$this->modelId});
+        parent::beforeDelete($event);
+    }
+
+    /**
+     * @return CActiveRecord
+     */
+    private function getModel()
+    {
+        return CActiveRecord::model($this->modelName);
+    }
+
+    /**
+     * @return CActiveRecord
+     */
+    private function newRelation()
+    {
+        return new $this->modelName;
+    }
+}

File app/protected/components/SiteMapWriter.php

+<?php
+/**
+ * @author Bogdan Savluk <savluk.bogdan@gmail.com>
+ * For more info about params see:
+ * @link http://www.sitemaps.org/protocol.html
+ */
+class SiteMapWriter
+{
+    const FREQ_ALWAYS = 0;
+    const FREQ_HOURLY = 1;
+    const FREQ_DAILY = 2;
+    const FREQ_WEEKLY = 3;
+    const FREQ_MONTHLY = 4;
+    const FREQ_YEARLY = 5;
+    const FREQ_NEVER = 6;
+    private static $freq = array(
+        'always',
+        'hourly',
+        'daily',
+        'weekly',
+        'monthly',
+        'yearly',
+        'newer');
+    private $_pull = array();
+
+    public function addPage($location, $lastmod = null, $changefreq = null, $priority = null)
+    {
+        $this->_pull[] = array(
+            $location, $lastmod, $changefreq, $priority
+        );
+    }
+
+    public function generateXml($processOutput = false)
+    {
+        if ($processOutput) {
+            ob_start();
+        }
+        echo '<?xml version="1.0" encoding="UTF-8"?>',
+
+        '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
+
+        foreach ($this->_pull as &$item) {
+            echo '<url>', '<loc>', htmlentities($item[0]), '</loc>';
+            if (isset($item[1])) {
+                echo '<lastmod>', $item[1], '</lastmod>';
+            }
+            if (isset($item[1])) {
+                echo '<changefreq>', self::$freq[$item[2]], '</changefreq>';
+
+            }
+            if (isset($item[1])) {
+                echo '<priority>', $item[3], '</priority>';
+            }
+            echo '</url>';
+        }
+        echo '</urlset>';
+        $res = null;
+        if ($processOutput) {
+            $res = ob_get_clean();
+        }
+        return $res;
+    }
+}

File app/protected/components/SitemapWriter.php

-<?php
-/**
- * @author Bogdan Savluk <savluk.bogdan@gmail.com>
- * For more info about params see:
- * @link http://www.sitemaps.org/protocol.html
- */
-class SitemapWriter
-{
-    const FREQ_ALWAYS = 0;
-    const FREQ_HOURLY = 1;
-    const FREQ_DAILY = 2;
-    const FREQ_WEEKLY = 3;
-    const FREQ_MONTHLY = 4;
-    const FREQ_YEARLY = 5;
-    const FREQ_NEVER = 6;
-    private static $freq = array(
-        'always',
-        'hourly',
-        'daily',
-        'weekly',
-        'monthly',
-        'yearly',
-        'newer');
-    private $_pull = array();
-
-    public function addPage($location, $lastmod = null, $changefreq = null, $priority = null)
-    {
-        $this->_pull[] = array(
-            $location, $lastmod, $changefreq, $priority
-        );
-    }
-
-    public function generateXml($processOutput = false)
-    {
-        if ($processOutput) {
-            ob_start();
-        }
-        echo '<?xml version="1.0" encoding="UTF-8"?>',
-
-        '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
-
-        foreach ($this->_pull as &$item) {
-            echo '<url>', '<loc>', htmlentities($item[0]), '</loc>';
-            if (isset($item[1])) {
-                echo '<lastmod>', $item[1], '</lastmod>';
-            }
-            if (isset($item[1])) {
-                echo '<changefreq>', self::$freq[$item[2]], '</changefreq>';
-
-            }
-            if (isset($item[1])) {
-                echo '<priority>', $item[3], '</priority>';
-            }
-            echo '</url>';
-        }
-        echo '</urlset>';
-        $res = null;
-        if ($processOutput) {
-            $res = ob_get_clean();
-        }
-        return $res;
-    }
-}

File app/protected/config/console.php

 <?php
 
 return CMap::mergeArray(
-	require(dirname(__FILE__).'/main.php'),
-	array(
-	)
+    require(dirname(__FILE__) . '/main.php'),
+    array()
 );

File app/protected/config/main.php.dist

 return array(
     'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..',
     'name' => 'CMS Test',
+    'language' => 'ru',
 
     // preloading 'log' component
     'preload' => array('log'),
             // If removed, Gii defaults to localhost only. Edit carefully to taste.
             'ipFilters' => array('127.0.0.1', '::1'),
             'generatorPaths' => array(
-                'application.modules.admin.gii', // a path alias
+                'ext.admin.gii', // a path alias
             ),
         ),
         'admin' => array(
             'class' => 'ext.admin.AdminModule',
+            'defaultController' => 'playground',
             'modules' => array(
                 'manager' => array(
                     'class' => 'application.modules.manager.ManagerModule',
                 'playground',
             ),
         ),
+        // uncomment while using gii
+        // 'manager',
     ),
 
     // application components
     'components' => array(
+        'cache' => array(
+            'class' => 'system.caching.CFileCache',
+        ),
+        'settings' => array(
+            'class' => 'ext.settings.Settings',
+            'cacheComponentId' => 'cache',
+            'cacheId' => 'website_settings',
+            'cacheTime' => 0,
+            'tableName' => '{{settings}}',
+            'dbComponentId' => 'db',
+            'createTable' => true,
+            'dbEngine' => 'InnoDB',
+        ),
+        'swiftMailer' => array(
+            'class' => 'ext.swiftMailer.YiiSwiftMailer'
+        ),
         'request' => array(
-                'enableCsrfValidation' => true,
-        ),
-        'swiftMailer'=>array(
-            'class'=>'ext.swiftMailer.YiiSwiftMailer'
+            'enableCsrfValidation' => true,
         ),
         'assetManager' => array(
             'linkAssets' => true,
             'urlFormat' => 'path',
             'showScriptName' => false,
             'rules' => array(
+                'sitemap.xml'=>'site/siteMap',
                 '<controller:\w+>/<id:\d+>' => '<controller>/view',
                 '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                 '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
             'username' => 'root',
             'password' => '',
             'charset' => 'utf8',
+            'tablePrefix' => 'tbl_'
         ),
 
         'errorHandler' => array(
             // use 'site/error' action to display errors
             'errorAction' => 'site/error',
         ),
+
         'log' => array(
             'class' => 'CLogRouter',
             'routes' => array(

File app/protected/config/web.php

+<?php
+
+return CMap::mergeArray(
+    require(dirname(__FILE__) . '/main.php'),
+    array(
+    )
+);

File app/protected/controllers/SiteController.php

         $this->render('contact', array('model' => $model));
     }
 
-    /**
-     * Displays the login page
-     */
-    public function actionLogin()
+    public function actionSiteMap()
     {
-        $model = new LoginForm;
+        $writer = new SiteMapWriter();
+        $staticPages = array(
+            'site/index',
+            'site/contact',
+        );
 
-        // if it is ajax validation request
-        if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
-            echo CActiveForm::validate($model);
-            Yii::app()->end();
+        // add all static pages
+        foreach ($staticPages as $r) {
+            $writer->addPage(Yii::app()->createAbsoluteUrl($r));
         }
 
-        // collect user input data
-        if (isset($_POST['LoginForm'])) {
-            $model->attributes = $_POST['LoginForm'];
-            // validate user input and redirect to the previous page if valid
-            if ($model->validate() && $model->login())
-                $this->redirect(Yii::app()->user->returnUrl);
-        }
-        // display the login form
-        $this->render('login', array('model' => $model));
-    }
-
-    /**
-     * Logs out the current user and redirect to homepage.
-     */
-    public function actionLogout()
-    {
-        Yii::app()->user->logout();
-        $this->redirect(Yii::app()->homeUrl);
+        header('Content-Type:application/xml');
+        $writer->generateXml();
     }
 }

File app/protected/data/database.sql

--- phpMyAdmin SQL Dump
--- version 3.5.1
--- http://www.phpmyadmin.net
---
--- Host: 127.0.0.1
--- Generation Time: Jul 08, 2012 at 02:49 AM
--- Server version: 5.5.19
--- PHP Version: 5.3.12
-
-SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-SET time_zone = "+00:00";
-
-
-/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
-/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
-/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
-/*!40101 SET NAMES utf8 */;
-
---
--- Database: `testcms`
---
-
--- --------------------------------------------------------
-
---
--- Table structure for table `admin_auth_assignment`
---
-
-CREATE TABLE IF NOT EXISTS `admin_auth_assignment` (
-  `itemname` varchar(64) NOT NULL,
-  `userid` varchar(64) NOT NULL,
-  `bizrule` text,
-  `data` text,
-  PRIMARY KEY (`itemname`,`userid`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
---
--- Dumping data for table `admin_auth_assignment`
---
-
-INSERT INTO `admin_auth_assignment` (`itemname`, `userid`, `bizrule`, `data`) VALUES
-('admin', 'admin', NULL, 'N;'),
-('developer', 'developer', NULL, 'N;');
-
--- --------------------------------------------------------
-
---
--- Table structure for table `admin_auth_item`
---
-
-CREATE TABLE IF NOT EXISTS `admin_auth_item` (
-  `name` varchar(64) NOT NULL,
-  `type` int(11) NOT NULL,
-  `description` text,
-  `bizrule` text,
-  `data` text,
-  PRIMARY KEY (`name`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
---
--- Dumping data for table `admin_auth_item`
---
-
-INSERT INTO `admin_auth_item` (`name`, `type`, `description`, `bizrule`, `data`) VALUES
-('admin', 2, 'Администратор', NULL, 'N;'),
-('authenticated', 2, 'Пользователь', NULL, 'N;'),
-('developer', 2, 'Разработчик', NULL, 'N;');
-
--- --------------------------------------------------------
-
---
--- Table structure for table `admin_auth_item_child`
---
-
-CREATE TABLE IF NOT EXISTS `admin_auth_item_child` (
-  `parent` varchar(64) NOT NULL,
-  `child` varchar(64) NOT NULL,
-  PRIMARY KEY (`parent`,`child`),
-  KEY `child` (`child`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
---
--- Dumping data for table `admin_auth_item_child`
---
-
-INSERT INTO `admin_auth_item_child` (`parent`, `child`) VALUES
-('developer', 'admin');
-
--- --------------------------------------------------------
-
---
--- Table structure for table `admin_user`
---
-
-CREATE TABLE IF NOT EXISTS `admin_user` (
-  `username` varchar(64) NOT NULL,
-  `password` varchar(40) NOT NULL,
-  `salt` varchar(10) NOT NULL,
-  `name` varchar(64) NOT NULL,
-  PRIMARY KEY (`username`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
---
--- Dumping data for table `admin_user`
---
-
-INSERT INTO `admin_user` (`username`, `password`, `salt`, `name`) VALUES
-('admin', 'cf373489fa2425711ba9526f204251bf1b30da3d', 'uqLt5vcZ2V', 'Администратор'),
-('developer', '20239caa272a13eb425afb4b5f4d6faaab198765', 'mbnjdHReOf', 'Разработчик');
-
--- --------------------------------------------------------
-
---
--- Table structure for table `gallery`
---
-
-CREATE TABLE IF NOT EXISTS `gallery` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `versions_data` text NOT NULL,
-  `name` tinyint(1) NOT NULL DEFAULT '1',
-  `description` tinyint(1) NOT NULL DEFAULT '1',
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-
---
--- Dumping data for table `gallery`
---
-
-INSERT INTO `gallery` (`id`, `versions_data`, `name`, `description`) VALUES
-(1, 'N;', 0, 0),
-(2, 'a:2:{s:5:"small";a:1:{s:6:"resize";a:2:{i:0;i:200;i:1;N;}}s:6:"medium";a:1:{s:6:"resize";a:2:{i:0;i:800;i:1;N;}}}', 1, 1);
-
--- --------------------------------------------------------
-
---
--- Table structure for table `gallery_photo`
---
-
-CREATE TABLE IF NOT EXISTS `gallery_photo` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `gallery_id` int(11) NOT NULL,
-  `rank` int(11) NOT NULL DEFAULT '0',
-  `name` varchar(512) NOT NULL,
-  `description` text NOT NULL,
-  `file_name` varchar(128) NOT NULL,
-  PRIMARY KEY (`id`),
-  KEY `fk_gallery_photo_gallery1` (`gallery_id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=488 ;
-
--- --------------------------------------------------------
-
---
--- Table structure for table `page`
---
-
-CREATE TABLE IF NOT EXISTS `page` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `link` varchar(64) DEFAULT NULL,
-  `name` varchar(256) DEFAULT NULL,
-  `content` longtext,
-  `title` varchar(512) DEFAULT NULL,
-  `description` text,
-  `keywords` text,
-  `projects_list` varchar(128) DEFAULT NULL,
-  PRIMARY KEY (`id`),
-  UNIQUE KEY `link_UNIQUE` (`link`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ;
-
---
--- Dumping data for table `page`
---
-
-INSERT INTO `page` (`id`, `link`, `name`, `content`, `title`, `description`, `keywords`, `projects_list`) VALUES
-(1, 'test1', 'Тестовая страница', '<p>Test content</p>', '', '', '', '1,2');
-
--- --------------------------------------------------------
-
---
--- Table structure for table `static_data`
---
-
-CREATE TABLE IF NOT EXISTS `static_data` (
-  `id` int(11) NOT NULL AUTO_INCREMENT,
-  `data` longtext,
-  PRIMARY KEY (`id`)
-) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=101 ;
-
---
--- Dumping data for table `static_data`
---
-
-INSERT INTO `static_data` (`id`, `data`) VALUES
-(1, 'a:3:{s:5:"item1";s:8:"Line One";s:5:"item2";s:1:"1";s:5:"item3";s:16:"<p>Rich Text</p>";}'),
-(100, 'a:2:{s:5:"phone";s:11:"999-999-333";s:10:"adminEmail";s:17:"email@example.com";}');
-
--- --------------------------------------------------------
-
---
--- Table structure for table `static_page`
---
-
-CREATE TABLE IF NOT EXISTS `static_page` (
-  `section` varchar(64) NOT NULL,
-  `key` varchar(64) NOT NULL,
-  `name` varchar(256) DEFAULT NULL,
-  `data` longtext,
-  `title` varchar(512) DEFAULT NULL,
-  `description` text,
-  `keywords` text,
-  PRIMARY KEY (`section`,`key`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
---
--- Constraints for dumped tables
---
-
---
--- Constraints for table `admin_auth_assignment`
---
-ALTER TABLE `admin_auth_assignment`
-  ADD CONSTRAINT `admin_auth_assignment_ibfk_1` FOREIGN KEY (`itemname`) REFERENCES `admin_auth_item` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;
-
---
--- Constraints for table `admin_auth_item_child`
---
-ALTER TABLE `admin_auth_item_child`
-  ADD CONSTRAINT `admin_auth_item_child_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `admin_auth_item` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
-  ADD CONSTRAINT `admin_auth_item_child_ibfk_2` FOREIGN KEY (`child`) REFERENCES `admin_auth_item` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;
-
---
--- Constraints for table `gallery_photo`
---
-ALTER TABLE `gallery_photo`
-  ADD CONSTRAINT `fk_gallery_photo_gallery1` FOREIGN KEY (`gallery_id`) REFERENCES `gallery` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
-
-/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
-/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
-/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

File app/protected/migrations/m130123_200914_base.php

+<?php
+
+class m130123_200914_base extends CDbMigration
+{
+    public function up()
+    {
+        //return true;
+        $this->execute(<<<SQL
+
+CREATE TABLE IF NOT EXISTS `{{admin_auth_assignment}}` (
+  `itemname` varchar(64) NOT NULL,
+  `userid` varchar(64) NOT NULL,
+  `bizrule` text,
+  `data` text,
+  PRIMARY KEY (`itemname`,`userid`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE IF NOT EXISTS `{{admin_auth_item}}` (
+  `name` varchar(64) NOT NULL,
+  `type` int(11) NOT NULL,
+  `description` text,
+  `bizrule` text,
+  `data` text,
+  PRIMARY KEY (`name`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+CREATE TABLE IF NOT EXISTS `{{admin_auth_item_child}}` (
+  `parent` varchar(64) NOT NULL,
+  `child` varchar(64) NOT NULL,
+  PRIMARY KEY (`parent`,`child`),
+  KEY `child` (`child`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+
+CREATE TABLE IF NOT EXISTS `{{admin_user}}` (
+  `username` varchar(64) NOT NULL,
+  `password` varchar(40) NOT NULL,
+  `salt` varchar(10) NOT NULL,
+  `name` varchar(64) NOT NULL,
+  PRIMARY KEY (`username`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+INSERT INTO `{{admin_auth_item}}` (`name`, `type`, `description`, `bizrule`, `data`) VALUES
+('admin', 2, 'Администратор', NULL, 'N;'),
+('authenticated', 2, 'Пользователь', NULL, 'N;'),
+('developer', 2, 'Разработчик', NULL, 'N;');
+
+INSERT INTO `{{admin_auth_item_child}}` (`parent`, `child`) VALUES
+('developer', 'admin');
+
+INSERT INTO `{{admin_user}}` (`username`, `password`, `salt`, `name`) VALUES
+('admin', 'cf373489fa2425711ba9526f204251bf1b30da3d', 'uqLt5vcZ2V', 'Администратор'),
+('developer', '20239caa272a13eb425afb4b5f4d6faaab198765', 'mbnjdHReOf', 'Разработчик');
+
+INSERT INTO `{{admin_auth_assignment}}` (`itemname`, `userid`, `bizrule`, `data`) VALUES
+('admin', 'admin', NULL, 'N;'),
+('developer', 'developer', NULL, 'N;');
+
+ALTER TABLE `{{admin_auth_assignment}}`
+  ADD CONSTRAINT `{{admin_auth_assignment}}_ibfk_1` FOREIGN KEY (`itemname`) REFERENCES `{{admin_auth_item}}` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE `{{admin_auth_item_child}}`
+  ADD CONSTRAINT `{{admin_auth_item_child}}_ibfk_1` FOREIGN KEY (`parent`) REFERENCES `{{admin_auth_item}}` (`name`) ON DELETE CASCADE ON UPDATE CASCADE,
+  ADD CONSTRAINT `{{admin_auth_item_child}}_ibfk_2` FOREIGN KEY (`child`) REFERENCES `{{admin_auth_item}}` (`name`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+CREATE TABLE IF NOT EXISTS `{{static_page}}` (
+  `section` varchar(64) NOT NULL,
+  `key` varchar(64) NOT NULL,
+  `name` varchar(256) DEFAULT NULL,
+  `data` longtext,
+  `title` varchar(512) DEFAULT NULL,
+  `description` text,
+  `keywords` text,
+  PRIMARY KEY (`section`,`key`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+SQL
+        );
+    }
+
+    public function down()
+    {
+        $this->execute(<<<SQL
+DROP TABLE IF EXISTS `{{admin_auth_assignment}}`;
+DROP TABLE IF EXISTS `{{admin_auth_item_child}}`;
+DROP TABLE IF EXISTS `{{admin_auth_item}}`;
+DROP TABLE IF EXISTS `{{admin_auth_item}}`;
+DROP TABLE IF EXISTS `{{admin_user}}`;
+DROP TABLE IF EXISTS `{{static_page}}`;
+SQL
+        );
+        return true;
+    }
+
+    /*
+    // Use safeUp/safeDown to do migration with transaction
+    public function safeUp()
+    {
+    }
+
+    public function safeDown()
+    {
+    }
+    */
+}

File app/protected/migrations/m130123_200915_gallery.php

+<?php
+
+class m130123_200915_gallery extends CDbMigration
+{
+    public function up()
+    {
+        //return true;
+        $this->execute(<<<SQL
+CREATE TABLE IF NOT EXISTS `{{gallery}}` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `versions_data` text NOT NULL,
+  `name` tinyint(1) NOT NULL DEFAULT '1',
+  `description` tinyint(1) NOT NULL DEFAULT '1',
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+CREATE TABLE IF NOT EXISTS `{{gallery_photo}}` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `gallery_id` int(11) NOT NULL,
+  `rank` int(11) NOT NULL DEFAULT '0',
+  `name` varchar(512) NOT NULL,
+  `description` text NOT NULL,
+  `file_name` varchar(128) NOT NULL,
+  PRIMARY KEY (`id`),
+  KEY `fk_gallery_photo_gallery1_idx` (`gallery_id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+
+ALTER TABLE `{{gallery_photo}}`
+  ADD CONSTRAINT `fk_{{gallery_photo}}_{{gallery}}1` FOREIGN KEY (`gallery_id`) REFERENCES `{{gallery}}` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
+SQL
+        );
+    }
+
+    public function down()
+    {
+        $this->execute(<<<SQL
+DROP TABLE IF EXISTS `{{gallery_photo}}`;
+DROP TABLE IF EXISTS `{{gallery}}`;
+SQL
+        );
+        return true;
+    }
+
+    /*
+    // Use safeUp/safeDown to do migration with transaction
+    public function safeUp()
+    {
+    }
+
+    public function safeDown()
+    {
+    }
+    */
+}

File app/protected/models/Page.php

-<?php
-
-/**
- * This is the model class for table "page".
- *
- * The followings are the available columns in table 'page':
- * @property integer $id
- * @property string $link
- * @property string $name
- * @property string $content
- * @property string $title
- * @property string $description
- * @property string $keywords
- * @property string $projects_list
- */
-class Page extends CActiveRecord
-{
-    /**
-     * Returns the static model of the specified AR class.
-     * @param string $className active record class name.
-     * @return Page the static model class
-     */
-    public static function model($className = __CLASS__)
-    {
-        return parent::model($className);
-    }
-
-    /**
-     * @return string the associated database table name
-     */
-    public function tableName()
-    {
-        return 'page';
-    }
-
-    /**
-     * @return array validation rules for model attributes.
-     */
-    public function rules()
-    {
-        // NOTE: you should only define rules for those attributes that
-        // will receive user inputs.
-        return array(
-            array('link', 'length', 'max' => 64),
-            array('name', 'length', 'max' => 256),
-            array('title', 'length', 'max' => 512),
-            array('projects_list', 'length', 'max' => 128),
-            array('content, description, keywords, projectIds', 'safe'),
-            // The following rule is used by search().
-            // Please remove those attributes that should not be searched.
-            array('id, link, name, content, title, description, keywords, projects_list', 'safe', 'on' => 'search'),
-        );
-    }
-
-    /**
-     * @return array relational rules.
-     */
-    public function relations()
-    {
-        // NOTE: you may need to adjust the relation name and the related
-        // class name for the relations automatically generated below.
-        return array(
-        );
-    }
-
-    /**
-     * @return array customized attribute labels (name=>label)
-     */
-    public function attributeLabels()
-    {
-        return array(
-            'id' => 'ID',
-            'link' => 'Псевдоним в адресной строке',
-            'name' => 'Название страницы',
-            'content' => 'Содержимое',
-            'title' => 'Заголовок',
-            'description' => 'Описание',
-            'keywords' => 'Ключевые слова',
-            'projects_list' => 'Связаные проекты',
-            'projectIds' => 'Связаные проекты',
-        );
-    }
-
-    /**
-     * Retrieves a list of models based on the current search/filter conditions.
-     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
-     */
-    public function search()
-    {
-        // Warning: Please modify the following code to remove attributes that
-        // should not be searched.
-
-        $criteria = new CDbCriteria;
-
-        $criteria->compare('id', $this->id);
-        $criteria->compare('link', $this->link, true);
-        $criteria->compare('name', $this->name, true);
-        $criteria->compare('content', $this->content, true);
-        $criteria->compare('title', $this->title, true);
-        $criteria->compare('description', $this->description, true);
-        $criteria->compare('keywords', $this->keywords, true);
-        $criteria->compare('projects_list', $this->projects_list, true);
-
-        return new CActiveDataProvider($this, array(
-            'criteria' => $criteria,
-        ));
-    }
-
-    public function getProjectIds()
-    {
-        return explode(',', $this->projects_list);
-    }
-
-    public function setProjectIds($value)
-    {
-        $this->projects_list = implode(',', $value);
-    }
-}

File app/protected/models/StaticData.php

-<?php
-
-/**
- * This is the model class for table "static_data".
- *
- * The followings are the available columns in table 'static_data':
- * @property integer $id
- * @property string $data
- */
-class StaticData extends CActiveRecord
-{
-    /**
-     * Returns the static model of the specified AR class.
-     * @param string $className active record class name.
-     * @return StaticData the static model class
-     */
-    public static function model($className = __CLASS__)
-    {
-        return parent::model($className);
-    }
-
-    /**
-     * @return string the associated database table name
-     */
-    public function tableName()
-    {
-        return 'static_data';
-    }
-
-    /**
-     * @return array validation rules for model attributes.
-     */
-    public function rules()
-    {
-        // NOTE: you should only define rules for those attributes that
-        // will receive user inputs.
-        return array(
-            array('data', 'safe'),
-            // The following rule is used by search().
-            // Please remove those attributes that should not be searched.
-            array('id, data', 'safe', 'on' => 'search'),
-        );
-    }
-
-    /**
-     * @return array relational rules.
-     */
-    public function relations()
-    {
-        // NOTE: you may need to adjust the relation name and the related
-        // class name for the relations automatically generated below.
-        return array(
-        );
-    }
-
-    /**
-     * @return array customized attribute labels (name=>label)
-     */
-    public function attributeLabels()
-    {
-        return array(
-            'id' => 'ID',
-            'data' => 'Data',
-        );
-    }
-
-    /**
-     * Retrieves a list of models based on the current search/filter conditions.
-     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
-     */
-    public function search()
-    {
-        // Warning: Please modify the following code to remove attributes that
-        // should not be searched.
-
-        $criteria = new CDbCriteria;
-
-        $criteria->compare('id', $this->id);
-        $criteria->compare('data', $this->data, true);
-
-        return new CActiveDataProvider($this, array(
-            'criteria' => $criteria,
-        ));
-    }
-
-    private $_data = null;
-
-    public function getDataAttributes()
-    {
-        if (!isset($this->_data)) {
-            $this->_data = unserialize($this->data);
-        }
-        return $this->_data;
-    }
-
-    public function setDataAttributes($data)
-    {
-        $this->_data = $data;
-        $this->data = serialize($data);
-    }
-}

File app/protected/models/StaticPage.php

  * @property string $title
  * @property string $description
  * @property string $keywords
- * @property string $last_change
- * @property double $priority
- * @property string $change_freq
+// * @property string $last_change
+// * @property double $priority
+// * @property string $change_freq
  */
 class StaticPage extends CActiveRecord
 {
      */
     public function tableName()
     {
-        return 'static_page';
+        return '{{static_page}}';
     }
 
     /**
     {
         // NOTE: you may need to adjust the relation name and the related
         // class name for the relations automatically generated below.
-        return array(
-        );
+        return array();
     }
 
     /**

File app/protected/modules/manager/controllers/DefaultController.php

 class DefaultController extends AdminController
 {
 
-	public function actionIndex()
-	{
-		$this->render('index');
-	}
+    public function actionIndex()
+    {
+        $this->render('index');
+    }
 }

File app/protected/modules/manager/views/default/index.php

                 The action belongs to the controller "<?php echo get_class($this); ?>"
                 in the "<?php echo $this->module->id; ?>" module.
             </p>
+
             <p>
                 You may customize this page by editing <tt><?php echo __FILE__; ?></tt>
             </p>

File app/protected/views/layouts/main.php

     <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css"/>
 
     <title><?php echo CHtml::encode($this->pageTitle); ?></title>
+
+    <?php
+
+    if (!empty($this->keywords))
+        echo '<meta name="keywords" content="', CHtml::encode($this->keywords), '"/>', "\n";
+
+    if (!empty($this->description))
+        echo '<meta name="description" content="', CHtml::encode($this->description), '"/>', "\n";
+    ?>
 </head>
 
 <body>
 <!-- page -->
 
 </body>
-</html>
+</html>