Esempio n. 1
0
/**
 * Campsite set_topic function plugin
 *
 * Type:     function
 * Name:     set_topic
 * Purpose:
 *
 * @param array
 *     $p_params[name] The Name of the topic to be set
 *     $p_params[identifier] The Identifier of the topic to be set
 * @param object
 *     $p_smarty The Smarty object
 */
function smarty_function_set_topic($p_params, &$p_smarty)
{
    // gets the context variable
    $campsite = $p_smarty->getTemplateVars('gimme');
    if (isset($p_params['identifier'])) {
        $attrName = 'identifier';
        $attrValue = $p_params['identifier'];
        $topicId = intval($p_params['identifier']);
    } elseif (isset($p_params['name'])) {
        $attrName = 'name';
        $attrValue = $p_params['name'];
        $topic = Topic::GetByFullName($p_params['name']);
        if (!is_null($topic) && $topic->exists()) {
            $topicId = $topic->getTopicId();
        } else {
            $campsite->topic->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
            return false;
        }
    } else {
        $property = array_shift(array_keys($p_params));
        CampTemplate::singleton()->trigger_error("invalid parameter '{$property}' in set_topic");
        return false;
    }
    if ($campsite->topic->defined && $campsite->topic->identifier == $topicId) {
        return;
    }
    $topicObj = new MetaTopic($topicId);
    if ($topicObj->defined) {
        $campsite->topic = $topicObj;
    } else {
        $campsite->topic->trigger_invalid_value_error($attrName, $attrValue, $p_smarty);
    }
}
Esempio n. 2
0
 /**
  * A topic is like a category for a piece of data.
  *
  * @param int $p_id
  */
 public function Topic($p_idOrName = null)
 {
     parent::DatabaseObject($this->m_columnNames);
     if (preg_match('/^[\\d]+$/', $p_idOrName) > 0) {
         $this->m_data['id'] = $p_idOrName;
         $this->fetch();
     } elseif (is_string($p_idOrName) && !empty($p_idOrName)) {
         $topic = Topic::GetByFullName($p_idOrName);
         if (!is_null($topic)) {
             $this->duplicateObject($topic);
         }
     }
 }
Esempio n. 3
0
 public function IsValid($p_value)
 {
     $topic = Topic::GetByFullName($p_value);
     return !is_null($topic);
 }