| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
// Disllow direct access. |
| 7 |
defined('ABSPATH') or die('Access denied'); |
| 8 |
|
| 9 |
/** |
| 10 |
* |
| 11 |
*/ |
| 12 |
class CJTBlockTemplatesModel extends CJTHookableClass { |
| 13 |
|
| 14 |
|
| 15 |
/** |
| 16 |
* put your comment there... |
| 17 |
* |
| 18 |
* @param mixed $blockId |
| 19 |
*/ |
| 20 |
public static function getLinkedTemplatesCount($blockId) { |
| 21 |
|
| 22 |
global $wpdb; |
| 23 |
|
| 24 |
$query = " SELECT count(*) |
| 25 |
FROM {$wpdb->prefix}cjtoolbox_block_templates |
| 26 |
WHERE blockId = %d;"; |
| 27 |
|
| 28 |
$query = $wpdb->prepare($query, $blockId); |
| 29 |
|
| 30 |
$count = $wpdb->get_var($query); |
| 31 |
|
| 32 |
return $count; |
| 33 |
} |
| 34 |
|
| 35 |
/** |
| 36 |
* Check weather a template is linked to specific block. |
| 37 |
* |
| 38 |
* Check database block_templates table for record with the given ids. |
| 39 |
* |
| 40 |
* @param Integer Block Id. |
| 41 |
* @param Integer Template Id. |
| 42 |
* @return boolean TRUE if linked, FALSE if not. |
| 43 |
*/ |
| 44 |
public function isLinked($blockId, $templateId) { |
| 45 |
// Try to load block template table with the requested Ids. |
| 46 |
$tableBlockTemplate = CJTxTable::getInstance('block-template'); |
| 47 |
$tableBlockTemplate->set('blockId', $blockId) |
| 48 |
->set('templateId', $templateId) |
| 49 |
->load(array('blockId', 'templateId')); |
| 50 |
// Return TRUE if the blockId and the TemplateId returned from the load process! |
| 51 |
return ($tableBlockTemplate->get('blockId') && $tableBlockTemplate->get('templateId')); |
| 52 |
} |
| 53 |
|
| 54 |
} // End class. |
| 55 |
|
| 56 |
// Hookable! |
| 57 |
CJTBlockTemplatesModel::define('CJTBlockTemplatesModel'); |