1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
<?php
/**
* TfBlockHandler class file.
*
* @copyright Simon Wilkinson 2013+ (https://tuskfish.biz)
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License (GPL) V2
* @author Simon Wilkinson <[email protected]>
* @version Release: 1.0
* @since 1.0
* @package content
*/
// Enable strict type declaration.
declare(strict_types=1);
if (!defined("TFISH_ROOT_PATH")) die("TFISH_ERROR_ROOT_PATH_NOT_DEFINED");
/**
* Manipulates block content objects (TfBlock).
*
* @copyright Simon Wilkinson 2013+ (https://tuskfish.biz)
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html GNU General Public License (GPL) V2
* @author Simon Wilkinson <[email protected]>
* @version Release: 1.0
* @since 1.0
* @package content
* @uses TfContentTypes Whitelist of sanctioned TfishContentObject subclasses.
* @var TfValidator $validator Instance of the Tuskfish data validator class.
* @var TfDatabase $db Instance of the Tuskfish database class.
* @var TfCriteriaFactory $criteriaFactory Instance of the Tuskfish criteria factory class.
* @var TfFileHandler $fileHandler Instance of the Tuskfish file handler class.
* @var TfTaglinkHandler $taglinkHandler Instance of the Tuskfish taglink handler class.
*/
class TfBlockHandler extends TfContentHandler
{
/**
* Constructor.
*
* @param TfValidator $validator An instance of the Tuskfish data validator class.
* @param TfDatabase $db An instance of the database class.
* @param TfCriteriaFactory $criteriaFactory an instance of the Tuskfish criteria factory class.
* @param TfFileHandler $fileHandler An instance of the Tuskfish file handler class.
* @param TfTaglinkHandler $taglinkHandler An instance of the Tuskfish taglink handler class.
*/
public function __construct(TfValidator $validator, TfDatabase $db,
TfCriteriaFactory $criteriaFactory, TfFileHandler $fileHandler,
TfTaglinkHandler $taglinkHandler)
{
parent::__construct($validator, $db, $criteriaFactory, $fileHandler, $taglinkHandler);
}
/**
* Count TfBlock objects, optionally matching conditions specified in a TfCriteria object.
*
* @param TfCriteria $criteria Query composer object used to build conditional database query.
* @return int $count Count of TfBlock objects matching conditions.
*/
public function getCount(TfCriteria $criteria = null)
{
if (isset($criteria) && !is_a($criteria, 'TfCriteria')) {
trigger_error(TFISH_ERROR_NOT_CRITERIA_OBJECT, E_USER_ERROR);
}
if (!isset($criteria)) {
$criteria = $this->criteriaFactory->getCriteria();
}
// Unset any pre-existing object type criteria.
$typeKey = $this->getTypeIndex($criteria->item);
if (isset($typeKey)) {
$criteria->unsetType($typeKey);
}
// Set new type criteria specific to this object.
$criteria->add($this->criteriaFactory->getItem('type', 'TfBlock'));
$count = parent::getcount($criteria);
return $count;
}
/**
* Get TfBlock objects, optionally matching conditions specified with a TfCriteria object.
*
* Note that the article type is automatically set, so when calling
* TfBlockHandler::getObjects($criteria) it is unnecessary to set the object type.
* However, if you want to use TfContentHandler::getObjects($criteria) then you do need to
* specify the object type, otherwise you will get all types of content returned. it is
* acceptable to use either handler, although probably good practice to use the object-
* specific one when you know you want a specific kind of object.
*
* @param TfCriteria $criteria Query composer object used to build conditional database query.
* @return array $objects content objects.
*/
public function getObjects(TfCriteria $criteria = null)
{
if (isset($criteria) && !is_a($criteria, 'TfCriteria')) {
trigger_error(TFISH_ERROR_NOT_CRITERIA_OBJECT, E_USER_ERROR);
}
if (!isset($criteria)) {
$criteria = $this->criteriaFactory->getCriteria();
}
// Unset any pre-existing object type criteria.
$typeKey = $this->getTypeIndex($criteria->item);
if (isset($typeKey)) {
$criteria->unsetType($typeKey);
}
// Set new type criteria specific to this object.
$criteria->add($this->criteriaFactory->getItem('type', 'TfBlock'));
$objects = parent::getObjects($criteria);
return $objects;
}
}