/Taxonomy/Model/Type.php
PHP | 120 lines | 69 code | 9 blank | 42 comment | 2 complexity | 82080f63005393e16d72434045f39bdb MD5 | raw file
- <?php
- App::uses('AppModel', 'Model');
- /**
- * Type
- *
- * @category Taxonomy.Model
- * @package Croogo.Taxonomy.Model
- * @version 1.0
- * @author Fahad Ibnay Heylaal <contact@fahad19.com>
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- * @link http://www.croogo.org
- */
- class Type extends TaxonomyAppModel {
- /**
- * Model name
- *
- * @var string
- * @access public
- */
- public $name = 'Type';
- /**
- * Behaviors used by the Model
- *
- * @var array
- * @access public
- */
- public $actsAs = array(
- 'Croogo.Cached' => array(
- 'groups' => array(
- 'taxonomy',
- ),
- ),
- 'Croogo.Params',
- 'Croogo.Trackable',
- );
- /**
- * Validation
- *
- * @var array
- * @access public
- */
- public $validate = array(
- 'title' => array(
- 'rule' => array('minLength', 1),
- 'message' => 'Title cannot be empty.',
- ),
- 'alias' => array(
- 'isUnique' => array(
- 'rule' => 'isUnique',
- 'message' => 'This alias has already been taken.',
- ),
- 'minLength' => array(
- 'rule' => array('minLength', 1),
- 'message' => 'Alias cannot be empty.',
- ),
- ),
- );
- /**
- * Model associations: hasAndBelongsToMany
- *
- * @var array
- * @access public
- */
- public $hasAndBelongsToMany = array(
- 'Vocabulary' => array(
- 'className' => 'Taxonomy.Vocabulary',
- 'joinTable' => 'types_vocabularies',
- 'foreignKey' => 'type_id',
- 'associationForeignKey' => 'vocabulary_id',
- 'unique' => true,
- 'conditions' => '',
- 'fields' => '',
- 'order' => 'Vocabulary.weight ASC',
- 'limit' => '',
- 'offset' => '',
- 'finderQuery' => '',
- 'deleteQuery' => '',
- 'insertQuery' => '',
- ),
- );
- /**
- * Display fields for this model
- *
- * @var array
- */
- protected $_displayFields = array(
- 'id',
- 'title',
- 'alias',
- 'description',
- 'plugin',
- );
- /**
- * Get a list of relevant types for given plugin
- */
- public function pluginTypes($plugin = null) {
- if ($plugin === null) {
- $conditions = array();
- } elseif ($plugin) {
- $conditions = array('plugin' => $plugin);
- } else {
- $conditions = array(
- 'OR' => array(
- 'plugin LIKE' => '',
- 'plugin' => null,
- ),
- );
- }
- return $this->find('list', compact('conditions'));
- }
- }