Exemplo n.º 1
0
	public function NewTestUser(){
	     $params = array(
			'user_id' => '10',
			'username' => 'gbluth',
			'last_name' => 'Bluth',
			'first_name' => 'George',
			'middle_initial' => 'O',
			'role' => 'F'
		);
   		$this->user->insert($params);
	}
Exemplo n.º 2
0
 /**
  * Create Term and Taxonomy Relationships.
  *
  * Relates an object (post, link etc) to a term and taxonomy type. Creates the
  * term and taxonomy relationship if it doesn't already exist. Creates a term if
  * it doesn't exist (using the slug).
  *
  * A relationship means that the term is grouped in or belongs to the taxonomy.
  * A term has no meaning until it is given context by defining which taxonomy it
  * exists under.
  *
  * @package NXTClass
  * @subpackage Taxonomy
  * @since 2.3.0
  *
  * @param int $object_id The object to relate to.
  * @param array|int|string $term The slug or id of the term, will replace all existing
  * related terms in this taxonomy.
  * @param array|string $taxonomy The context in which to relate the term to the object.
  * @param bool $append If false will delete difference of terms.
  * @return array|nxt_Error Affected Term IDs
  */
 function set_object_terms($object_id, $terms, $taxonomy, $append = false)
 {
     $object_id = (int) $object_id;
     if (!$this->is_taxonomy($taxonomy)) {
         return new nxt_Error('invalid_taxonomy', __('Invalid Taxonomy'));
     }
     if (!is_array($terms)) {
         $terms = array($terms);
     }
     if (!$append) {
         $old_tt_ids = $this->get_object_terms($object_id, $taxonomy, array('fields' => 'tt_ids', 'orderby' => 'none'));
     }
     $tt_ids = array();
     $term_ids = array();
     foreach ((array) $terms as $term) {
         if (!strlen(trim($term))) {
             continue;
         }
         if (!($id = $this->is_term($term, $taxonomy))) {
             $id = $this->insert_term($term, $taxonomy);
         }
         if (is_nxt_error($id)) {
             return $id;
         }
         $term_ids[] = $id['term_id'];
         $id = $id['term_taxonomy_id'];
         $tt_ids[] = $id;
         if ($this->db->get_var($this->db->prepare("SELECT term_taxonomy_id FROM {$this->db->term_relationships} WHERE object_id = %d AND term_taxonomy_id = %d", $object_id, $id))) {
             continue;
         }
         $this->db->insert($this->db->term_relationships, array('object_id' => $object_id, 'term_taxonomy_id' => $id));
     }
     $this->update_term_count($tt_ids, $taxonomy);
     if (!$append) {
         $delete_terms = array_diff($old_tt_ids, $tt_ids);
         if ($delete_terms) {
             $in_delete_terms = "'" . implode("', '", $delete_terms) . "'";
             $this->db->query($this->db->prepare("DELETE FROM {$this->db->term_relationships} WHERE object_id = %d AND term_taxonomy_id IN ({$in_delete_terms})", $object_id));
             $this->update_term_count($delete_terms, $taxonomy);
         }
     }
     $t = $this->get_taxonomy($taxonomy);
     if (!$append && isset($t->sort) && $t->sort) {
         $values = array();
         $term_order = 0;
         $final_tt_ids = $this->get_object_terms($object_id, $taxonomy, 'fields=tt_ids');
         foreach ($tt_ids as $tt_id) {
             if (in_array($tt_id, $final_tt_ids)) {
                 $values[] = $this->db->prepare("(%d, %d, %d)", $object_id, $tt_id, ++$term_order);
             }
         }
         if ($values) {
             $this->db->query("INSERT INTO {$this->db->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)");
         }
     }
     do_action('set_object_terms', $object_id, $terms, $tt_ids, $taxonomy, $append);
     return $tt_ids;
 }
Exemplo n.º 3
0
 /**
  * Method to save records (insert or update)
  * @see application/controllers/ICrudController#save()
  */
 public function save(array $data, array $unlockedData)
 {
     try {
         if (isset($this->_post->Insert)) {
             $this->_model->insert($data);
         } else {
             $fieldKey = $this->_model->getFieldKey();
             $this->_model->update($data, "{$fieldKey} = {$unlockedData[$fieldKey]}");
         }
     } catch (Exception $e) {
         Fgsl_Session_Namespace::set('exception', $e);
         $this->_redirect('error/message');
     }
     return true;
 }
Exemplo n.º 4
0
 /**
  * Add the specified page to the specified tree
  * Remember to also call StructuredData::addWatch if you call this function
  *
  * @param unknown_type $dbw
  * @param unknown_type $treeId
  * @param unknown_type $title
  * @param unknown_type $revid
  * @param unknown_type $talkRevid
  * @param unknown_type $dataVersion
  * @param unknown_type $uid
  * @param unknown_type $flags
  * @return unknown
  */
 public static function addPage($dbw, &$user, $treeId, $title, $revid, $talkRevid, $dataVersion = 0, $uid = '', $flags = 0)
 {
     $result = true;
     // should this be the primary person?
     // TODO get rid of this test - the primary person can be set when the user opens the tree for the first time
     if ($title->getNamespace() == NS_PERSON) {
         $res = $dbw->select('familytree_page', 'fp_title', array('fp_tree_id' => $treeId, 'fp_namespace' => NS_PERSON), 'FamilyTreeUtil::addPage', array('LIMIT' => 1));
         if ($res === false || !$dbw->numRows($res)) {
             // make this person the primary page if it's the first person
             $dbw->update('familytree', array('ft_primary_namespace' => $title->getNamespace(), 'ft_primary_title' => $title->getDBkey()), array('ft_tree_id' => $treeId));
             FamilyTreeUtil::deleteFamilyTreesCache($user->getName());
             $errno = $dbw->lastErrno();
             if ($errno > 0) {
                 $result = false;
             }
         }
         $dbw->freeResult($res);
     }
     // insert familytree_page
     $record = array('fp_tree_id' => $treeId, 'fp_user_id' => $user->getID(), 'fp_namespace' => $title->getNamespace(), 'fp_title' => $title->getDBkey(), 'fp_oldid' => $revid, 'fp_latest' => $revid, 'fp_talk_oldid' => $talkRevid, 'fp_talk_latest' => $talkRevid, 'fp_data_version' => $dataVersion, 'fp_uid' => $uid, 'fp_flags' => $flags);
     $dbw->insert('familytree_page', $record, 'FamilyTreeUtil::addPage', array('ignore'));
     $errno = $dbw->lastErrno();
     if ($errno != 0 && $errno != 1062) {
         // 1062 = duplicate key
         $result = false;
     }
     return $result;
 }
 /**
  * Grant
  *
  * @param string $type
  * @param string $arg
  * @return void
  */
 protected function grant($type, $arg)
 {
     list($aclResourceId, $resourceIds) = $this->splitParams($type, $arg);
     if (isset($this->resourceTypeObjectRelation)) {
         $results = $this->resourceTypeObjectRelation->getTargetIdFromSourceId($this->resourceTypeObjectRelation->getSecondKey(), $this->resourceTypeObjectRelation->getFirstKey(), $aclResourceId);
         foreach ($resourceIds as $resourceId) {
             if ($resourceId != "*" && !in_array($resourceId, $results)) {
                 $this->resourceTypeObjectRelation->insert($aclResourceId, $resourceId);
             } elseif ($resourceId == "*") {
                 if ($type != "host" && $type != "hostgroup" && $type != "servicegroup") {
                     throw new CentreonClapiException(self::UNSUPPORTED_WILDCARD);
                 }
                 $field = "all_" . $type . "s";
                 $this->object->update($aclResourceId, array($field => '1', 'changed' => '1'));
             }
         }
     }
 }