View file upload/src/addons/AddonsLab/Core/Xf2/Admin/EntityConfig.php

File size: 6.34Kb
<?php
/** 
This software is furnished under a license and may be used and copied
only  in  accordance  with  the  terms  of such  license and with the
inclusion of the above copyright notice.  This software  or any other
copies thereof may not be provided or otherwise made available to any
other person.  No title to and  ownership of the  software is  hereby
transferred.                                                         
                                                                     
You may not reverse  engineer, decompile, defeat  license  encryption
mechanisms, or  disassemble this software product or software product
license.  AddonsLab may terminate this license if you don't comply with
any of these terms and conditions.  In such event,  licensee  agrees 
to return licensor  or destroy  all copies of software  upon termination 
of the license.
*/


namespace AddonsLab\Core\Xf2\Admin;

use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Finder;

abstract class EntityConfig
{
    /**
     * @return string
     * The prefix for all product classes, e.g. AddonsLab\AddonName
     */
    abstract public function getAddonNamespace();

    /**
     * @return string
     * Short name of the entity to edit, e.g. TestItem etc.
     */
    abstract public function getEntityName();

    /**
     * @return string
     * Entity name in lower case, used to generate the names of templates, e.g. test_item
     */
    abstract public function get_entity_name();

    /**
     * @return string
     * Lower-case prefix for all templates (usually common for the product), e.g. addon_id
     */
    abstract public function getPrefix();

    /**
     * @return string
     * The name of primary key of the entity, e.g. test_item_id
     */
    abstract public function getPrimaryKeyName();

    /**
     * @return string
     * The prefix used for all routes, e.g. addon/test-item. No trailing slash is needed.
     */
    abstract public function getRoutePrefix();

    /**
     * @return string
     * Id of Admin Permission to protected the page
     */
    abstract public function getAdminPermissionId();

    /**
     * @return Form
     * The configuration of the form used in Edit page
     */
    abstract public function getEditForm();

    /**
     * @return bool If true, the entity should have "active" column and a toggler will be shown to activate/deactivate the item
     */
    abstract public function hasActiveToggle();

    /**
     * @return bool If true, Controls popup will be shown with links from @see getControlPopupLinks method
     */
    abstract public function hasControlPopup();

    /**
     * @return string
     * The word to use instead of "item" in phrases, e.g. "test item"
     */
    abstract public function getItemNameLowerCase();

    /**
     * @return string
     * E.g. "Test Item"
     */
    abstract public function getItemNameUpperCase();

    /**
     * @return string
     * The word to use instead of "items" in phrases, e.g. "test items"
     */
    abstract public function getItemPluralNameLowerCase();

    /**
     * @return string
     * E.g. "Test Items"
     */
    abstract public function getItemPluralNameUpperCase();

    /**
     * @return bool If true, a quick filter control will be shown above the list
     */
    public function hasQuickFilter()
    {
        return true;
    }

    /**
     * @return array
     * Array of entities to fetch with the main entity by default
     */
    public function getDefaultWith()
    {
        return array();
    }

    /**
     * @return array
     * The entities to fetch with the main entity when fetching list data
     */
    public function getListWith()
    {
        return array();
    }

    /**
     * @return bool
     * Add button will be shown on top of the page and Add item page will be available
     */
    public function hasAddPage()
    {
        return true;
    }

    /**
     * @return bool
     * Item in the list will be clickable and user will be taken to the edit form
     */
    public function hasViewPage()
    {
        return true;
    }

    /**
     * @return bool
     * Save button will be shown, otherwise, Go Back button
     */
    public function hasSavePage()
    {
        return true;
    }

    /**
     * @return bool
     * Delete button will be shown
     */
    public function hasDeletePage()
    {
        return true;
    }

    /**
     * @return array
     * Array with links to be shown in the popup. Each link should be an array with attributes as defined below
     */
    public function getControlPopupLinks()
    {
        return array(
            array(
                'route' => '/change/to/route',
                'args' => array(),
                'attr' => 'data-test="change"',
                'text' => 'Override @getControlPopupLinks method',
            ),
        );
    }

    /**
     * @return bool|FilterForm
     * The form to build page filter. Will be shown as a separate form above the main list
     */
    public function getFilterForm()
    {
        return false;
    }
    
    /**
     * @param string $entity
     * @return string
     * E.g. AddonsLab\AddonName:TestItem
     */
    public function getFullEntityName($entity = '')
    {
        if (!$entity)
        {
            $entity = $this->getEntityName();
        }

        if (strpos($entity, ':') !== false)
        {
            return $entity;
        }

        return $this->getAddonNamespace() . ':' . $entity;
    }

    /**
     * The name of entity used to build the list. By default the same entity as the one used in forms
     * @return string
     */
    public function getListEntityName()
    {
        return $this->getEntityName();
    }

    /**
     * @param $action
     * @return string
     * E.g. AddonsLab\AddonName:TestItem\Edit
     */
    public function getViewName($action)
    {
        return $this->getAddonNamespace() . ':' . $this->getEntityName() . '\\' . $action;
    }

    /**
     * @param $postfix
     * @return string
     * E.g. addon_id_test_item_edit
     */
    public function getTemplateName($postfix)
    {
        return $this->getPrefix() . '_' . $this->get_entity_name() . '_' . strtolower($postfix);
    }

    public function getPhraseName($postfix)
    {
        return $this->getPrefix() . '_' . $this->get_entity_name() . '_' . $postfix;
    }

    public function getPhrase($postfix)
    {
        return \XF::phrase($this->getPhraseName($postfix));
    }
}