Permalink
Browse files

begin work on module highlight

  • Loading branch information...
0 parents commit 7709c47b6cfba7e1250bdd537a2c22bdab7313f2 @Floby Floby committed Jun 25, 2012
@@ -0,0 +1,12 @@
+.DS_Store
+*.db
+*.sqlite
+.project
+.buildpath
+/.settings
+
+.*.un~
+.*.swp
+.idea/*
+*.*~
+*.done
@@ -0,0 +1,10 @@
+<?php
+class Highlight_Bootstrap extends Centurion_Application_Module_Bootstrap
+{
+ public function _initHelper()
+ {
+ Zend_Controller_Action_HelperBroker::addHelper(
+ new Highlight_Controller_Action_Helper_AddButtonOnGrid()
+ );
+ }
+}
No changes.
@@ -0,0 +1,15 @@
+[production]
+admin.controllers[] = "admin-highlight"
+admin.controllers[] = "admin-feed"
+resources.navigation.adapter = "Centurion_Model_DbTable_Navigation"
+resources.layout.admin.layout = "admin"
+
+[development : production]
+
+[staging : production]
+
+[testing : production]
+
+[pre_prod : production]
+
+[local : production]
@@ -0,0 +1,30 @@
+<?php
+class Highlight_AdminFeedController extends Centurion_Controller_Action
+{
+ public function createFeedAction()
+ {
+ if ($this->_request->isPost()) {
+ $this->view->form = new Highlight_Form_Model_Feed();
+
+ $values = $this->_request->getPost();
+
+ if (isset($values['name'])&&$this->view->form->isValid($values)) {
+ $this->view->form->save();
+ $this->getHelper('redirector')->setGotoUrl($this->view->url(array('action' => 'index')));
+ }
+
+ if (isset($values['current_filter']) && isset($values['current_sortCol']) && isset($values['current_sortCol']) && isset($values['current_sortOrder']) && isset($values['model'])) {
+ $this->view->form->setFilter($values['current_filter']);
+ $this->view->form->setSort($values['current_sortCol'], $values['current_sortOrder']);
+ $this->view->form->setModelname($values['model']);
+ }
+
+ $this->view->form->cleanForm();
+ }
+ }
+
+ public function indexAction()
+ {
+
+ }
+}
@@ -0,0 +1,6 @@
+<?php
+
+class Highlight_AdminHighlightController extends Highlight_Model_Controller_AdminHighlightController
+{
+
+}
@@ -0,0 +1,17 @@
+<?php
+class Highlight_Controller_Action_Helper_AddButtonOnGrid extends Zend_Controller_Action_Helper_Abstract
+{
+ public function postDispatch()
+ {
+ //We don't use it from now. But maybe later.
+ return;
+
+ if ($this->getActionController() instanceof Centurion_Rest_Controller_CRUD && $this->getRequest()->getActionName() === 'index') {
+ $this->getResponse()->appendBody(
+ $this->getActionController()->view->partial('crud/grid.phtml', 'highlight', array('model' => $this->getRequest()->getParam('model')))
+ );
+ }
+
+
+ }
+}
@@ -0,0 +1,10 @@
+<?php
+class Highlight_Controller_Action_Helper_GetHighlightContainer extends Zend_Controller_Action_Helper_Abstract
+{
+
+ public function direct($containerName)
+ {
+ //TODO: change all call to action helper => view helper and remove this helper.
+ return $this->getActionController()->view->getHighlightContainer($containerName);
+ }
+}
@@ -0,0 +1,91 @@
+-- phpMyAdmin SQL Dump
+-- version 3.3.2
+-- http://www.phpmyadmin.net
+--
+-- Serveur: localhost
+-- Généré le : Mer 16 Juin 2010 à 16:47
+-- Version du serveur: 5.1.41
+-- Version de PHP: 5.3.1
+
+SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
+SET foreign_key_checks = 0;
+
+--
+-- Base de données: `sam`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Structure de la table `highlight_container`
+--
+drop table IF EXISTS highlight_container;
+CREATE TABLE IF NOT EXISTS `highlight_container` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `name` varchar(255) NOT NULL,
+ `feed_id` int(11) unsigned DEFAULT NULL,
+ `content_type_id` int(11) unsigned NOT NULL,
+ PRIMARY KEY (`id`),
+ KEY `hightlight_flux` (`feed_id`),
+ KEY `content_type_id` (`content_type_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+-- --------------------------------------------------------
+
+--
+-- Structure de la table `highlight_feed`
+--
+drop table IF EXISTS highlight_feed;
+CREATE TABLE IF NOT EXISTS `highlight_feed` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `hightlight_container_id` int(11) unsigned DEFAULT NULL,
+ `proxy_content_type_id` int(11) unsigned DEFAULT NULL,
+ `name` varchar(255) NOT NULL,
+ `where` varchar(255) DEFAULT NULL,
+ `order` varchar(255) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `hightlight_container_id` (`hightlight_container_id`,`proxy_content_type_id`),
+ KEY `proxy_content_type_id` (`proxy_content_type_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
+
+-- --------------------------------------------------------
+
+--
+-- Structure de la table `highlight_row`
+--
+drop table IF EXISTS highlight_row;
+CREATE TABLE IF NOT EXISTS `highlight_row` (
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
+ `proxy_content_type_id` int(11) unsigned DEFAULT NULL,
+ `proxy_pk` varchar(255) NOT NULL,
+ `container_id` int(11) unsigned NOT NULL,
+ `position` int(11) unsigned DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `hightlight_container` (`container_id`),
+ KEY `proxy_model` (`proxy_content_type_id`)
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
+
+--
+-- Contraintes pour les tables exportées
+--
+
+--
+-- Contraintes pour la table `highlight_container`
+--
+ALTER TABLE `highlight_container`
+ ADD CONSTRAINT `highlight_container_ibfk_1` FOREIGN KEY (`feed_id`) REFERENCES `highlight_feed` (`id`),
+ ADD CONSTRAINT `highlight_contenttype_ibfk_1` FOREIGN KEY (`content_type_id`) REFERENCES `centurion_content_type` (`id`);
+
+--
+-- Contraintes pour la table `highlight_feed`
+--
+ALTER TABLE `highlight_feed`
+ ADD CONSTRAINT `highlight_feed_ibfk_1` FOREIGN KEY (`hightlight_container_id`) REFERENCES `highlight_container` (`id`),
+ ADD CONSTRAINT `highlight_feed_ibfk_2` FOREIGN KEY (`proxy_content_type_id`) REFERENCES `centurion_content_type` (`id`);
+
+--
+-- Contraintes pour la table `highlight_row`
+--
+ALTER TABLE `highlight_row`
+ ADD CONSTRAINT `highlight_row_ibfk_2` FOREIGN KEY (`container_id`) REFERENCES `highlight_container` (`id`),
+ ADD CONSTRAINT `highlight_row_ibfk_3` FOREIGN KEY (`proxy_content_type_id`) REFERENCES `centurion_content_type` (`id`);
@@ -0,0 +1,51 @@
+<?php
+
+class Highlight_Form_Model_Feed extends Centurion_Form_Model_Abstract
+{
+ public function __construct($options = array(), Centurion_Db_Table_Abstract $instance = null)
+ {
+ $this->_model = Centurion_Db::getSingleton('highlight/feed');
+
+ $this->_exclude = array('id', 'proxy_content_type_id', 'order', 'where', 'hightlight_container_id');
+
+ $this->_elementLabels = array(
+ 'name' => 'Name'
+ );
+
+ parent::__construct($options, $instance);
+ }
+
+ public function setFilter($filter)
+ {
+ $this->getElement('where')->setValue($filter);
+ }
+
+ public function setSort($sortCol, $sortOrder)
+ {
+ if ($sortCol !== '1')
+ $this->getElement('order')->setValue($sortCol . ' ' . $sortOrder);
+ }
+
+ public function setModelname($model)
+ {
+ list($contentTypeRow, $created) = Centurion_Db::getSingleton('centurion/contentType')->getOrCreate(array('name' => $model));
+ $this->getElement('proxy_content_type_id')->setValue($contentTypeRow->id);
+ }
+
+ public function init()
+ {
+ parent::init();
+
+ $this->addElement('hidden', 'where', array());
+ $this->addElement('hidden', 'order', array());
+ $this->addElement('hidden', 'proxy_content_type_id', array());
+
+ $this->getElement('name')->addValidator('Db_NoRecordExists', false, array('table' => 'highlight_feed', 'field' => 'name'));
+ }
+
+ public function save($adapter = null)
+ {
+ $this->_exclude = array('hightlight_container_id');
+ parent::save($adapter);
+ }
+}
@@ -0,0 +1,108 @@
+<?php
+abstract class Highlight_Model_Controller_AdminHighlightController extends Centurion_Controller_Action
+{
+ protected $_container = null;
+
+ public function preDispatch()
+ {
+ $view = $this->initView();
+ $view->addBasePath($this->getFrontController()->getModuleDirectory('highlight') . DIRECTORY_SEPARATOR . 'views');
+ return parent::preDispatch();
+ }
+
+ public function actions($row)
+ {
+ return '<a href="'.$this->view->url(array('id' => $row->id, 'module' => 'highlight', 'controller' => 'admin-highlight'), 'rest', true).'">'.$this->view->translate('Manage highlight').'</a>';
+ }
+
+ public function init()
+ {
+
+ }
+
+ protected function _returnTo()
+ {
+ if (null !== $this->_getParam('returnto', null))
+ $this->_response->setRedirect(urldecode($this->_getParam('returnto')));
+ else
+ $this->_response->setRedirect($this->view->url(array('action' => 'get')));
+ }
+
+ public function indexAction()
+ {
+ $this->view->containers = Centurion_Db::getSingleton('highlight/container')->fetchAll();
+ }
+
+ protected function _getContainer($redirect404 = true)
+ {
+ if (!isset($this->_container)) {
+ if (($container = $this->_getParam('container', null)) && ($container instanceof Highlight_Model_DbTable_Row_Container)) {
+ $this->_container = $container;
+ } else if ($id = $this->_getParam('id', null)) {
+ $this->_container = $this->_helper->getObjectOr404('highlight/container', array('id' => $this->_getParam('id')));
+ } else {
+ throw new Zend_Controller_Action_Exception(sprintf('No container given'), 404);
+ }
+ }
+ return $this->_container;
+ }
+
+ public function autocompleteAction()
+ {
+ $container = $this->_getContainer();
+
+ $highlight = $container->getHighlightModel();
+ $resultArray = $highlight->autocomplete($this->_getParam('term'), $container);
+
+ $response = $this->getResponse();
+
+ $this->_helper->Json($resultArray);
+
+// $response->appendBody(Zend_Json::encode($resultArray));
+ }
+
+ public function getAction()
+ {
+ $this->view->container = $this->_getContainer();
+ }
+
+ public function addAction()
+ {
+ $className = $this->_getParam('model', null);
+ $pk = $this->_getParam('pk', null);
+
+ $container = $container = $this->_getContainer();
+
+ if (trim($className) !== '' && trim($pk) !== '') {
+ $row = Centurion_Db::getSingletonByClassName($className)->find($pk)->current();
+ $container->addRow($row, $this->_getParam('position', null));
+ }
+
+ $this->_returnTo();
+ }
+
+ public function deleteAction()
+ {
+ $rowId = $this->_getParam('row_id', null);
+ $row = Centurion_Db::getSingleton('highlight/row')->findOneById($rowId);
+ $row->delete();
+
+ $this->_returnTo();
+ }
+
+ public function saveOrderAction()
+ {
+ $this->view->container = $container = $this->_getContainer();
+
+ $rowTable = Centurion_Db::getSingleton('highlight/row');
+ $i = 0;
+
+ foreach ($this->_getParam('rowId') as $position => $id) {
+ $row = $rowTable->findOneById($id);
+ $row->position = $position;
+ $row->save();
+ }
+
+ $this->_returnTo();
+ }
+}
@@ -0,0 +1,30 @@
+<?php
+class Highlight_Model_DbTable_Container extends Centurion_Db_Table_Abstract
+{
+ protected $_name = 'highlight_container';
+ protected $_rowClass = 'Highlight_Model_DbTable_Row_Container';
+
+ public function addRow($container, $row, $position)
+ {
+ if ($container instanceof Centurion_Db_Table_Row_Abstract) {
+ $container = $container->id;
+ }
+
+ list($highlightRow, $created) = Centurion_Db::getSingleton('highlight/row')->getOrCreate(array('container_id' => $container, 'position' => $position));
+ $highlightRow->setProxy($row);
+ $highlightRow->save();
+ }
+
+ protected $_referenceMap = array(
+ 'feed' => array(
+ 'columns' => 'feed_id',
+ 'refColumns' => 'id',
+ 'refTableClass' => 'Highlight_Model_DbTable_Feed'
+ ),
+ 'content_type' => array(
+ 'columns' => 'content_type_id',
+ 'refColumns' => 'id',
+ 'refTableClass' => 'Core_Model_DbTable_ContentType'
+ ),
+ );
+}
Oops, something went wrong.

0 comments on commit 7709c47

Please sign in to comment.