コード例 #1
0
ファイル: template.php プロジェクト: ceko/concrete5-1
$form = Loader::helper('form');
$gaiID = intval($_REQUEST['gaiID']);
$gatTypeID = intval($_REQUEST['gatTypeID']);
$type = GatheringItemTemplateType::getByID($gatTypeID);
$nh = Loader::helper('validation/numbers');
$item = GatheringItem::getByID($gaiID);
if (is_object($item) && is_object($type)) {
    $gathering = $item->getGatheringObject();
    $agp = new Permissions($gathering);
    if ($agp->canEditGatheringItems() && Loader::helper('validation/token')->validate('edit_gathering_item_template', $_REQUEST['token'])) {
        $reloadItemTile = false;
        if ($type->getGatheringItemTemplateTypeHandle() == 'tile') {
            $reloadItemTile = true;
        }
        if ($_POST['task'] == 'update_item_template') {
            $template = GatheringItemTemplate::getByID($_POST['gatID']);
            $item->setGatheringItemTemplate($type, $template);
            if ($reloadItemTile) {
                $item->render($type);
            }
            exit;
        }
        $assignments = GatheringItemFeatureAssignment::getList($item);
        $features = array();
        foreach ($assignments as $as) {
            $f = $as->getFeatureObject();
            if (is_object($f)) {
                $features[] = $f;
            }
        }
        $templates = GatheringItemTemplate::getListByType($type);
コード例 #2
0
ファイル: Item.php プロジェクト: ceko/concrete5-1
 public function setAutomaticGatheringItemTemplate()
 {
     $arr = Core::make('helper/arrays');
     $db = Database::connection();
     $myFeatureHandles = $this->getGatheringItemFeatureHandles();
     // we loop through and do it for all installed gathering item template types
     $types = GatheringItemTemplateType::getList();
     foreach ($types as $type) {
         $matched = array();
         $r = $db->Execute('select gatID from GatheringItemTemplates where gatTypeID = ?', array($type->getGatheringItemTemplateTypeID()));
         while ($row = $r->FetchRow()) {
             $templateFeatureHandles = $db->GetCol('select feHandle from Features f inner join GatheringItemTemplateFeatures af on f.feID = af.feID where gatID = ?', array($row['gatID']));
             if ($arr->subset($templateFeatureHandles, $myFeatureHandles)) {
                 $matched[] = GatheringItemTemplate::getByID($row['gatID']);
             }
         }
         usort($matched, array($this, 'sortByFeatureScore'));
         if (is_object($matched[0]) && $matched[0]->gatheringItemTemplateIsAlwaysDefault()) {
             $template = $matched[0];
         } else {
             // we do some fun randomization math.
             usort($matched, array($this, 'weightByFeatureScore'));
             $template = $matched[0];
         }
         if (is_object($template)) {
             $this->setGatheringItemTemplate($type, $template);
             if ($template->gatheringItemTemplateControlsSlotDimensions()) {
                 $this->setGatheringItemSlotWidth($template->getGatheringItemTemplateSlotWidth($this));
                 $this->setGatheringItemSlotHeight($template->getGatheringItemTemplateSlotHeight($this));
             }
         }
     }
 }