/** * Creates a contenttype to add to the collection. * * @param array mixed $iteminfo - The known properties of the new item * @return vB_Item - The created item */ protected function createItem($iteminfo, $load_flags = false) { $item = parent::createItem($iteminfo, $load_flags); if ($this->filter_enabled and !$item->isEnabled()) { return false; } return $item; }
/** * Applies the result of the load query. * Child classes should extend or override to determine what was loaded based * on $required_query and $required_info. * * This method should only ever be used directly after performing the queries so * that $this->required_info accurately reflects the query result. * * @param resource $result - The db result resource * @param int $load_query - The query that the result is from */ protected function applyLoad($result, $load_query) { if (self::QUERY_WIDGETS == $load_query) { $widgets = $locations = array(); while ($widget = vB::$db->fetch_array($result)) { $itemid = $widget['itemid']; if (!isset($widgets[$itemid])) { $widgets[$itemid] = $locations[$itemid] = array(); } $widgets[$itemid][] = $widget['widgetid']; $locations[$itemid][$widget['column']][$widget['index']] = $widget['widgetid']; } foreach ($widgets AS $itemid => $widgetlist) { $this->collection[$itemid]->setWidgets($widgetlist); $this->collection[$itemid]->setLocations($locations[$itemid]); } // mark widget info as loaded $this->loaded_info |= vBCms_Item_Layout::INFO_WIDGETS; return true; } return parent::applyLoad($result, $load_query); }
/** * Applies the result of the load query. * * @param resource $result - The db result resource * @param int $load_query - The query that the result is from */ protected function applyLoad($result, $load_query) { if (self::QUERY_PARENTS == $load_query) { $parents = array(); if (vB::$db->num_rows($result)) { while ($parent = vB::$db->fetch_array($result)) { if (!isset($parents[$parent['itemid']])) { $parents[$parent['itemid']] = array(); } $parents[$parent['itemid']][$parent['nodeid']] = $parent; } } foreach ($parents AS $itemid => $parentlist) { $this->collection[$itemid]->setParents($parentlist); } // mark parents as loaded $this->loaded_info |= vBCms_Item_Content::INFO_PARENTS; return true; } else if (self::QUERY_CONFIG == $load_query) { // sort configs into individual widgets $configs = array(); while ($cvar = vB::$db->fetch_array($result)) { if (!isset($configs[$cvar['itemid']])) { $configs[$cvar['itemid']] = array(); } $configs[$cvar['itemid']][$cvar['name']] = $cvar['value']; } // set the configs on the items foreach ($configs AS $itemid => $config) { $this->collection[$itemid]->setConfig($config, true); } // mark config as loaded $this->loaded_info |= vBCms_Item_Content::INFO_CONFIG; return true; } return parent::applyLoad($result, $load_query); }
/** * Finds the page index based on a given dateline * * @access public * * @return unknown */ function seek_item($dateline) { if (!parent::seek_item($dateline)) { return false; } // Collection is stale $this->reset(); $sql = "SELECT COUNT(*) AS total\n\t\t\tFROM " . TABLE_PREFIX . "album AS album"; if ($this->only_autoapproved) { $sql .= "INNER JOIN " . TABLE_PREFIX . "albumupdate AS albumupdate"; } $sql .= " WHERE 1=1 "; if ($this->parent_id) { $sql .= " AND userid = {$this->parent_id} "; } $sql .= $this->state_sql() . "\n\t\t\t\tAND lastpicturedate " . ($this->descending ? ">" : "<") . " = {$dateline}\n\t\t"; $getpagenum = $this->registry->db->query_first($sql); // if page is full, adding 1 pushes to top of next page return $this->page = max(1, ceil(($getpagenum['total'] + 1) / $this->quantity)); }
/** * Builds or updates the collection from a db result. * If child classes need to apply loaded info to items that are not part of the * item model properties then they will have to extend or override this method. * * @param resource $result - The result resource of the query * @param int $load+query - The query that the result is from * @return bool - Success */ protected function applyLoad($result, $load_query) { if (!parent::applyLoad($result, $load_query)) { return false; } // Map the collection items back to the original itemid's to preserve the order. $collection = $this->itemid; foreach ($items AS &$content) { foreach($content AS $contenttypeid => $contentid) { if (isset($this->collection[$contenttypeid][$contentid])) { $content = $this->collection[$contenttypeid][$contentid]; } } } $this->collection = $collection; return true; }
/** * Applies the result of the load query. * * @param resource $result - The db result resource * @param int $load_query - The query that the result is from */ protected function applyLoad($result, $load_query) { if (self::QUERY_CONFIG == $load_query) { // sort configs into individual widgets $widget_configs = array(); while ($cvar = vB::$db->fetch_array($result)) { if (!isset($widget_configs[$cvar['itemid']])) { $widget_configs[$cvar['itemid']] = array('instance' => array(), 'node' => array()); } $widget_configs[$cvar['itemid']][($cvar['instance'] ? 'instance' : 'node')][$cvar['name']] = ($cvar['serialized'] ? unserialize($cvar['value']) : $cvar['value']); } // merge and apply configs to widgets foreach ($widget_configs AS $itemid => &$config) { $config = array_merge($config['instance'], $config['node']); if (isset($this->collection[$itemid])) { $this->collection[$itemid]->setConfig($config, true); } } // mark config as loaded $this->loaded_info |= vBCms_Item_Widget::INFO_CONFIG; return true; } return parent::applyLoad($result, $load_query); }