Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

overdue comments

  • Loading branch information...
commit 46fef567babeb3c2bef641a91072cd2ffdc7f7b7 1 parent ab8e08f
@Floby Floby authored
View
9 Bootstrap.php
@@ -13,6 +13,7 @@ public function _initHelpers()
/**
* reads the config file for named containers
* if some don't already exist in base, create them
+ * the config authorizes numeric or string keys for the named highlights config container
*/
public function _initContainers()
{
@@ -39,18 +40,26 @@ public function _initContainers()
}
+
+ /**
+ * reads all the named highlights from config and returned them in alphabetical order
+ * @return [string]
+ */
static public function listNamedHighlightsInConfig()
{
$namedHighlights = Centurion_Config_Manager::get('highlight.named_highlights');
$res = array();
foreach ($namedHighlights as $key => $name) {
+ // if the value is an array, then the name is the key
if(is_array($name)) {
$res[] = $key;
}
+ // else the name is the value
else {
$res[] = $name;
}
}
+ sort($res);
return $res;
}
}
View
16 configs/module.ini
@@ -3,10 +3,16 @@ admin.controllers[] = "admin-highlight"
admin.controllers[] = "admin-row"
resources.navigation.adapter = "Centurion_Model_DbTable_Navigation"
resources.layout.admin.layout = "admin"
+
+; add our view helpers to the config path
resources.view.helperPath.Highlight_View_Helper_ = APPLICATION_PATH "/modules/highlight/views/helpers"
+; config for the default field mapper
+; the class to instanciate
highlight.mappers.default.className = "Highlight_Model_FieldMapper_Default"
+; each key within the mapper's config describe the components of the final field it names
+; the fields array lists the fields of a row the mappers will look in to find the content of the final field
highlight.mappers.default.title.fields[] = "title"
highlight.mappers.default.title.fields[] = "name"
highlight.mappers.default.link.fields[] = "permalink"
@@ -20,9 +26,19 @@ highlight.mappers.default.description.fields[] = "description"
highlight.mappers.default.cover.fields[] = "cover"
highlight.mappers.default.cover.fields[] = "image"
highlight.mappers.default.cover.fields[] = "media"
+
+; pixelOnEmpty allows to populate the value with the empty pixel if nothing is set
highlight.mappers.default.cover.pixelOnEmpty = 1
+; config for the default crawler
+; the default crawler looks in one or more tables in the specified fields for any match
+;
+; the class to instanciate
highlight.crawlers.default.className = "Highlight_Model_Crawler_Default";
+
+; each key of the config defines a model it has to crawl
+; the table config define which table it has to crawl
+; the fields config array lists the fields in which to look for matches with the query terms
highlight.crawlers.default.models.profile.table = "user/profile";
highlight.crawlers.default.models.profile.fields[] = "nickname"
highlight.crawlers.default.models.profile.fields[] = "user__email"
View
5 forms/Model/Feed.php
@@ -1,5 +1,8 @@
<?php
+/**
+ * @deprecated
+ */
class Highlight_Form_Model_Feed extends Centurion_Form_Model_Abstract
{
public function __construct($options = array(), Centurion_Db_Table_Abstract $instance = null)
@@ -48,4 +51,4 @@ public function save($adapter = null)
$this->_exclude = array('hightlight_container_id');
parent::save($adapter);
}
-}
+}
View
25 forms/Model/Item.php
@@ -1,7 +1,13 @@
<?php
+/**
+ * A form to add a new item in the collection for a highlight
+ */
class Highlight_Form_Model_Item extends Centurion_Form_Model_Abstract
{
+ /**
+ * the container to which this item belongs
+ */
protected $_container = null;
public function __construct($options = array(), Centurion_Db_Table_Abstract $instance = null)
@@ -25,16 +31,19 @@ public function init()
$this->setAttrib('class', 'form-main form-highlight');
+ // make this element a hidden value
$proxy_pk = $this->getElement('proxy_pk');
$this->removeElement('proxy_pk');
$this->addElement('hidden', 'proxy_pk', array('required'=>true));
$this->getElement('proxy_pk')->setRequired(true);
+ // make this element a hidden value
$proxy_content_type_id = $this->getElement('proxy_content_type_id');
$this->removeElement('proxy_content_type_id');
$this->addElement('hidden', 'proxy_content_type_id', array('required'=>true));
$this->getElement('proxy_content_type_id')->setRequired(true);
+ // make this element a hidden value
$position = $this->getElement('position');
$this->removeElement('position');
$this->addElement('hidden', 'position', array(
@@ -43,6 +52,7 @@ public function init()
$this->getElement('position')->setRequired(true);
+ // add the field in which the autocomplete plugin will be affected
$this->addElement('text', 'autocomplete', array(
'class' => 'ui-autocomplete-input ui-autocomplete-loading',
'role' => 'textbox',
@@ -50,32 +60,47 @@ public function init()
'label' => $this->_translate('Content'),
'description' => $this->_translate('Search for content')
));
+ // we need a special render helper to render this element. cause Centurion
+ // doesn't use form decorators as it should
$this->getElement('autocomplete')->helper = 'highlightAutoCompleteTextForm';
+ // group fields
$elements = array_keys(array_merge($this->getElements(), $this->getSubForms()));
$this->addDisplayGroup($elements, 'allElements', array('class'=>'form-group'));
$this->getDisplayGroup('allElements')->setLegend($this->_translate('Add a highlight'));
}
+ /**
+ * Set the container for this item
+ */
public function setContainer($container)
{
$this->_container = $container;
return $this;
}
+ /**
+ * Get the container for this item
+ */
public function getContainer()
{
return $this->_container;
}
+ /**
+ * Completely override default Centurion_Form_Model_Abstract behaviour.
+ * because addRow is actually tested on the highlight model
+ */
public function save($adapter = null)
{
$container = $this->getContainer();
+ // forbid saving an item with no container
if(is_null($container)) {
throw new UnexpectedValueException('no container found for this form');
}
+ // find the proxy row and add it to the collection
$model = Centurion_Db::getSingletonByClassName($this->getElement('proxy_content_type_id')->getValue());
$row = $model->find($this->getElement('proxy_pk')->getValue())->current();
$item = $container->addRow($row, $this->getElement('position')->getValue());
View
1  forms/Model/Row.php
@@ -39,6 +39,7 @@ public function init()
$this->addReferenceSubForm($pic, 'cover');
+ // @todo add info fields about proxy for this highlight
//$mapper = Highlight_Model_FieldMapper_Factory::get('default');
//$map = $mapper->map($this->_proxy);
}
View
37 models/Controller/AdminHighlightController.php
@@ -1,12 +1,24 @@
<?php
+
+/**
+ * The generic controller for highlights
+ */
abstract class Highlight_Model_Controller_AdminHighlightController extends Centurion_Controller_Action
{
+ /**
+ * The current container we are managing
+ */
protected $_container = null;
+
+ /**
+ * The select object we use for a list of containers
+ */
protected $_select = null;
public function preDispatch()
{
$view = $this->initView();
+ // make sure our views always get found
$view->addBasePath($this->getFrontController()->getModuleDirectory('highlight') . DIRECTORY_SEPARATOR . 'views');
return parent::preDispatch();
}
@@ -19,10 +31,6 @@ 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()
- {
-
- }
/**
* implements callback url logic. it looks for a `returnto` parameter and sets any relevant redirection
@@ -36,6 +44,10 @@ protected function _returnTo()
$this->_response->setRedirect($this->view->url(array('action' => 'get')));
}
+ /**
+ * Lists all containers by their names
+ * if a proxy exists, only lists named containers attached to this proxy
+ */
public function indexAction()
{
$this->view->containers = $this->getContainers();
@@ -62,12 +74,14 @@ public function getSelect()
if($this->_select) return $this->_select;
$this->_select = Centurion_Db::getSingleton('highlight/container')->select(true);
+ // if there's a proxy, only list containers with this proxy
if($proxy = $this->_getProxy()) {
$this->_select->filter(array(
'proxy_pk' => $proxy->pk,
'proxy_content_type__name' => get_class($proxy->getTable())
));
}
+ // else, only list containers with no proxy from config
else {
$this->_select->filter(array(
'proxy_pk__isnull' => true
@@ -82,6 +96,9 @@ public function getSelect()
return $this->_select;
}
+ /**
+ * Proxy to the bootstrap static function
+ */
protected function _getNamedHighlights()
{
return Highlight_Bootstrap::listNamedHighlightsInConfig();
@@ -146,6 +163,10 @@ protected function _hasProxyParam()
return ($this->_getParam('proxy_pk', false) && $this->_getParam('proxy_content_type_id'));
}
+ /**
+ * Gets called from xhr by the autocomplete plugin.
+ * returns a json view of a list of models that matches the query
+ */
public function autocompleteAction()
{
$container = $this->_getContainer();
@@ -189,14 +210,19 @@ public function getCrawler()
}
}
+ // if everything else fails, get default crawler
if(empty($crawler)) {
$crawler = Highlight_Model_Crawler_Factory::get('default');
}
+ // some crawlers may need the container we are talking about
$crawler->setContainer($this->_getContainer());
return $crawler;
}
+ /**
+ * returns a form object for the autocomplete part
+ */
public function _getAutocompleteForm()
{
$form = new Highlight_Form_Model_Item();
@@ -226,6 +252,9 @@ public function getAction()
$this->render('admin-highlight/get', true, true);
}
+ /**
+ * gets a mapper for the highlights item we want to display.
+ */
protected function _getHighlightMapper()
{
// return default mapper for now
View
9 models/Crawler/Abstract.php
@@ -13,12 +13,18 @@
protected $_models = array();
+ /**
+ * Set the current container for this crawler
+ */
public function setContainer($container)
{
$this->_container = $container;
return $this;
}
+ /**
+ * Get the current container for this crawler
+ */
public function getContainer()
{
return $this->_container;
@@ -68,6 +74,9 @@ public function autocomplete($terms, $resultSet = null)
return $res;
}
+ /**
+ * returns an array with the necessary information about a row. to identify it
+ */
protected function _populateArrayFromRow(Centurion_Db_Table_Row_Abstract $row)
{
$res = array(
View
3  models/Crawler/Default.php
@@ -1,7 +1,8 @@
<?php
/**
- * a simple crawler that only looks in flatepages
+ * a simple crawler that only looks in the models defined in the config
+ * @todo define config structure
**/
class Highlight_Model_Crawler_Default extends Highlight_Model_Crawler_Abstract
{
View
5 models/Crawler/Factory.php
@@ -1,7 +1,10 @@
<?php
/**
- *
+ * A factory that makes crawlers from config
+ * it looks for the given crawler name in the config.
+ * then instanciate the proper class
+ * with the params as an array for only parameter
**/
class Highlight_Model_Crawler_Factory
{
View
18 models/DbTable/Container.php
@@ -1,4 +1,8 @@
<?php
+
+/**
+ * The model table for a highlight container
+ */
class Highlight_Model_DbTable_Container extends Centurion_Db_Table_Abstract
{
protected $_name = 'highlight_container';
@@ -77,8 +81,11 @@ public function createWithProxy(Centurion_Db_Table_Row_Abstract $instance)
}
/**
- * not used yet.
- * will be used if the spec ever says we need more than one container for a given proxy
+ * create a container with the given proxy and the given name
+ * this allows for multiple container for the same proxy. you can differentiate them by their names
+ * @param $name the name we want our container to have
+ * @param $instance the model to which we want to attach this container
+ * @throws InvalidArgumentException
* @return Centurion_Db_Table_Row_Abstract
*/
public function createWithNameAndProxy($name, Centurion_Db_Table_Row_Abstract $instance)
@@ -121,6 +128,13 @@ public function findOneByProxy(Centurion_Db_Table_Row_Abstract $row)
}
+ /**
+ * find a container with the given proxy and that has the given name
+ * this should return only one row.
+ * @param $nam the name of the container we want
+ * @param $row the proxy attached to the container we are looking for
+ * @return Centurion_Db_Table_Row_Abstract
+ */
public function findOneByNameAndProxy($name, Centurion_Db_Table_Row_Abstract $row)
{
if(!is_string($name)) {
View
4 models/DbTable/Row.php
@@ -1,4 +1,8 @@
<?php
+
+/**
+ * a row model for a highlight element
+ */
class Highlight_Model_DbTable_Row extends Centurion_Db_Table_Abstract
{
protected $_name = 'highlight_row';
View
15 models/DbTable/Row/Container.php
@@ -1,4 +1,7 @@
<?php
+/**
+ *
+ */
class Highlight_Model_DbTable_Row_Container extends Centurion_Db_Table_Row_Proxy
{
protected $_highlightModel = null;
@@ -53,11 +56,15 @@ public function titleGetter()
}
}
- public function getHighlights($mapper = null, $override = null, $limit = null)
+ /**
+ * Retrieve a list of highlights, ready to use
+ * @param $mapper the mapper to use, default if not specified
+ * @param $override an array of parameters to override those of the given mapper
+ * @param $limit the maximum number of highlights to return
+ * @return array of highlights
+ */
+ public function getHighlights($mapper = 'default', $override = null, $limit = null)
{
- if(!$mapper) {
- $mapper = 'default';
- }
if(is_string($mapper)) {
$mapper = Highlight_Model_FieldMapper_Factory::get($mapper, $override);
}
View
11 models/DbTable/Row/Row.php
@@ -1,8 +1,14 @@
<?php
+/**
+ * The row model for an highlight item
+ */
class Highlight_Model_DbTable_Row_Row extends Centurion_Db_Table_Row_Proxy
{
+ /**
+ * @deprecated
+ */
public function getBlockHtml(Highlight_Model_FieldMapper_Interface $mapper=null)
{
$meta = $this->getProxy()->getTable()->getMeta();
@@ -20,6 +26,11 @@ public function getBlockHtml(Highlight_Model_FieldMapper_Interface $mapper=null)
}
}
+ /**
+ * map the current highlight item with the given field mapper
+ * @param $mapper the field mapper to use. use default one if not specified
+ * @return array
+ */
public function map(Highlight_Model_FieldMapper_Interface $mapper = null)
{
if(!$mapper) {
View
4 models/DbTable/Rowset/Highlight.php
@@ -1,4 +1,8 @@
<?php
+
+/**
+ * @deprecated
+ */
class Highlight_Model_DbTable_Rowset_Highlight implements SeekableIterator, Countable, ArrayAccess
{
protected $_name = null;
View
7 models/FieldMapper/Default.php
@@ -2,6 +2,8 @@
/**
* Maps fields to something readable for highlights
+ * it basically takes any row and format it into a generic associative array
+ * of ('title', 'description', 'url', 'cover')
**/
class Highlight_Model_FieldMapper_Default implements Highlight_Model_FieldMapper_Interface
{
@@ -87,6 +89,11 @@ public function map(Centurion_Db_Table_Row_Abstract $row)
}
+ /**
+ * After the proxy is mapped, override the returned value with those provided
+ * @param $res the original mapped values
+ * @param $override the values to override
+ */
public function mapOverride($res, $override)
{
$over = array();
View
3  models/FieldMapper/Factory.php
@@ -1,7 +1,8 @@
<?php
/**
- *
+ * A factory that makes field mappers from config
+ * @todo config structure
**/
class Highlight_Model_FieldMapper_Factory
{
View
6 models/Highlight/Abstract.php
@@ -1,4 +1,8 @@
<?php
+
+/**
+ * @deprecated
+ */
abstract class Highlight_Model_Highlight_Abstract
{
const LIMIT_AUTOCOMPLETE = 10;
@@ -33,4 +37,4 @@ public function getTitle($row)
{
return $row->__toString();
}
-}
+}
View
4 tests/Model/ContainerTest.php
@@ -11,12 +11,16 @@ protected function setUp()
protected function tearDown()
{
+ // make sure the test table is empty when we're done
$table = self::getTable();
foreach ($table->fetchAll() as $row) {
$row->delete();
}
}
+ /**
+ * Return the table to use for these tests
+ */
public static function getTable()
{
return Centurion_Db::getSingleton('highlight/container');
View
3  tests/Model/Crawler/Crawler.php
@@ -5,6 +5,9 @@ class Highlight_Test_Model_Crawler_Crawler extends Highlight_Model_Crawler_Abstr
protected $_table;
+ /**
+ * Get a table we can crawl
+ */
public function getTable()
{
if(!is_null($this->_table)) return $this->_table;
View
3  tests/Model/DbTable/Crawlable.php
@@ -1,5 +1,8 @@
<?php
+/**
+ * Mock table that you can actually crawl
+ */
class Highlight_Test_Model_DbTable_Crawlable extends Asset_Model_DbTable_Abstract
{
protected $_name = 'highlight_crawlable';
View
6 traits/Controller/CRUD.php
@@ -30,6 +30,9 @@ public function init()
}
+ /**
+ * Callback function for the grid field to manage highlights for a particular row
+ */
public function displayManageLink($row)
{
list($contentType,) = Centurion_Db::getSingleton('core/content_type')->getOrCreate(array(
@@ -54,6 +57,9 @@ public function displayManageLink($row)
return sprintf('<a target="_blank" href="%s">%s</a>', $url, $label);
}
+ /**
+ * fetch extraParams for the highlight controller action that the CRUD controller can override
+ */
protected function _getExtraParams()
{
if(!method_exists($this->_controller, 'getAdditionalHighlightUrlParams')) {
View
3  traits/Model/Row/HasHighlights.php
@@ -1,7 +1,8 @@
<?php
/**
- *
+ * An interface that a row can implement to help
+ * it forces to have a getCrawler method
**/
class Highlight_Traits_Model_Row_HasHighlights extends Centurion_Traits_Model_DbTable_Row_Abstract
{
Please sign in to comment.
Something went wrong with that request. Please try again.