コード例 #1
0
 public static function setRolesFor($user_id, $roles)
 {
     Record::deleteWhere('UserRole', 'user_id = :user_id', array(':user_id' => (int) $user_id));
     foreach ($roles as $role => $role_id) {
         Record::insert('UserRole', array('user_id' => (int) $user_id, 'role_id' => (int) $role_id));
     }
 }
コード例 #2
0
ファイル: TaggerTag.php プロジェクト: silentworks/tagger
 public static function deletePageTagRelationship($page_id, $tag_id)
 {
     // get the id of the tag
     $tag = Record::findOneFrom('Tag', 'id=?', array($tag_id));
     Record::deleteWhere('PageTag', 'page_id=? AND tag_id=?', array($page_id, $tag->id));
     $tag->count--;
     $tag->save();
     return true;
 }
コード例 #3
0
ファイル: tag.php プロジェクト: ZerGabriel/cms-1
 /**
  * 
  * @param integer|Model_Page_Front $page_id
  * @param array $tags
  */
 public static function save_by_page($page_id, $tags)
 {
     if (is_string($tags)) {
         $tags = explode(Model_Tag::SEPARATOR, $tags);
     }
     $tags = array_unique(array_map('trim', $tags));
     $current_tags = Model_Page_Tag::find_by_page($page_id);
     if ($page_id instanceof Model_Page_Front) {
         $page_id = $page_id->id();
     }
     // no tag before! no tag now! ... nothing to do!
     if (empty($tags) and empty($current_tags)) {
         return NULL;
     }
     // delete all tags
     if (empty($tags)) {
         // update count (-1) of those tags
         foreach ($current_tags as $tag) {
             DB::update(Model_Tag::tableName())->set(array('count' => DB::expr('count - 1')))->where('name', '=', $tag)->execute();
         }
         Record::deleteWhere(self::tableName(), array('where' => array(array('page_id', '=', (int) $page_id))));
         Cache::instance()->delete_tag('page_tags');
     } else {
         $old_tags = array_diff($current_tags, $tags);
         $new_tags = array_diff($tags, $current_tags);
         // insert all tags in the tag table and then populate the page_tag table
         foreach ($new_tags as $index => $tag_name) {
             if (empty($tag_name)) {
                 continue;
             }
             $tag = Record::findOneFrom('Model_Tag', array('where' => array(array('name', '=', $tag_name))));
             // try to get it from tag list, if not we add it to the list
             if (!$tag instanceof Model_Tag) {
                 $tag = new Model_Tag(array('name' => trim($tag_name)));
             }
             $tag->count++;
             $tag->save();
             // create the relation between the page and the tag
             $page_tag = new Model_Page_Tag(array('page_id' => (int) $page_id, 'tag_id' => $tag->id));
             $page_tag->save();
         }
         // remove all old tag
         foreach ($old_tags as $index => $tag_name) {
             // get the id of the tag
             $tag = Record::findOneFrom('Model_Tag', array('where' => array(array('name', '=', $tag_name))));
             Record::deleteWhere(self::tableName(), array('where' => array(array('page_id', '=', (int) $page_id), array('tag_id', '=', $tag->id))));
             $tag->count--;
             $tag->save();
         }
         Cache::instance()->delete_tag('page_tags');
     }
 }
コード例 #4
0
ファイル: Page.php プロジェクト: chaobj001/tt
 public function saveTags($tags)
 {
     if (is_string($tags)) {
         $tags = explode(',', $tags);
     }
     $tags = array_map('trim', $tags);
     $current_tags = $this->getTags();
     // no tag before! no tag now! ... nothing to do!
     if (count($tags) == 0 && count($current_tags) == 0) {
         return;
     }
     // delete all tags
     if (count($tags) == 0) {
         $tablename = self::tableNameFromClassName('Tag');
         // update count (-1) of those tags
         foreach ($current_tags as $tag) {
             self::$__CONN__->exec("UPDATE {$tablename} SET count = count - 1 WHERE name = '{$tag}'");
         }
         return Record::deleteWhere('PageTag', 'page_id=?', array($this->id));
     } else {
         $old_tags = array_diff($current_tags, $tags);
         $new_tags = array_diff($tags, $current_tags);
         // insert all tags in the tag table and then populate the page_tag table
         foreach ($new_tags as $index => $tag_name) {
             if (!empty($tag_name)) {
                 // try to get it from tag list, if not we add it to the list
                 if (!($tag = Record::findOneFrom('Tag', 'name=?', array($tag_name)))) {
                     $tag = new Tag(array('name' => trim($tag_name)));
                 }
                 $tag->count++;
                 $tag->save();
                 // create the relation between the page and the tag
                 $tag = new PageTag(array('page_id' => $this->id, 'tag_id' => $tag->id));
                 $tag->save();
             }
         }
         // remove all old tag
         foreach ($old_tags as $index => $tag_name) {
             // get the id of the tag
             $tag = Record::findOneFrom('Tag', 'name=?', array($tag_name));
             Record::deleteWhere('PageTag', 'page_id=? AND tag_id=?', array($this->id, $tag->id));
             $tag->count--;
             $tag->save();
         }
     }
 }
コード例 #5
0
	function clear404s() {
	
		self::__checkPermission('redirector_delete');
		
		if ( ! Record::deleteWhere('Redirector404s','1') )
			Flash::set('error', __('There was a problem clearing the 404 errors!'));
			
		else
			Flash::set('success', __('404 Errors have been cleared!'));
		
		redirect(get_url('plugin/redirector/'));
	
	}
コード例 #6
0
ファイル: Page.php プロジェクト: albertobraschi/toad
 public function saveTags($tags)
 {
     if (is_string($tags)) {
         $tags = explode(',', $tags);
     }
     $tags = array_map('trim', $tags);
     $tags = array_filter($tags);
     $current_tags = array();
     foreach ($this->tags() as $tag) {
         $current_tags[] = $tag->name();
     }
     // no tag before! no tag now! ... nothing to do!
     if (count($tags) == 0 && count($current_tags) == 0) {
         return;
     }
     // delete all tags
     if (count($tags) == 0) {
         return Record::deleteWhere('PageTag', 'page_id=?', array($this->id));
     } else {
         $old_tags = array_diff($current_tags, $tags);
         $new_tags = array_diff($tags, $current_tags);
         // insert all tags in the tag table and then populate the page_tag table
         foreach ($new_tags as $index => $tag_name) {
             if (!empty($tag_name)) {
                 // try to get it from tag list, if not we add it to the list
                 if (!($tag = Tag::findByName($tag_name))) {
                     $tag = new Tag(array('name' => trim($tag_name)));
                 }
                 $tag->save();
                 // create the relation between the page and the tag
                 $tag = new PageTag(array('page_id' => $this->id, 'tag_id' => $tag->id));
                 $tag->save();
             }
         }
         // remove all old tag
         foreach ($old_tags as $index => $tag_name) {
             // get the id of the tag
             $tag = Tag::findByName($tag_name);
             Record::deleteWhere('PageTag', 'page_id=? AND tag_id=?', array($this->id, $tag->id));
             $tag->save();
         }
     }
 }
コード例 #7
0
	private function __storetags($tags,$download_id=null) {
	
		//	if download_id is provided clear out old tags
		if (!is_null($download_id)) Record::deleteWhere('DownloadTagConnection','download_id='.Record::escape((int)$download_id));
		
		//	check to make sure there are some tags
		if (empty($tags)) return true;
		
		//	take either an array or comma separated list of tags
		if (!is_array($tags)) $tags = explode(',',$tags);
		$tags = preg_replace('/[^a-z0-9 _,-]/','',$tags);
		
		//	find or create tag and connect to download
		foreach ($tags as $tagname) {
			$tagname = trim(strtolower($tagname));
			//	check for minimum tag length; must be at least three characters
			if (strlen($tagname) >= 3) {
				if (!$tag = DownloadTag::findByName($tagname)) {
					$tag = new DownloadTag(array('name'=>$tagname));
					$tag->save();
				}
				
				if (!is_null($download_id)) {
					$connection = new DownloadTagConnection(array(
						'download_id'=>(int)$download_id,
						'tag_id'=>$tag->id
					));
					$connection->save();
				}
			}
		}
		
		return true;
	}//*/
コード例 #8
0
 public function product_delete($id)
 {
     if ($product = Record::findByIdFrom('Product', $id)) {
         $product_title = $product->title;
         //delete page for product
         if ($page = Record::findByIdFrom('Page', $product->page_id)) {
             $page->delete();
         }
         //delete variants
         Record::deleteWhere('ecommerce_product_variant', 'product_id=?', array($id));
         //delete images
         Record::deleteWhere('ecommerce_product_image', 'product_id=?', array($id));
         //delete files
         Record::deleteWhere('ecommerce_product_file', 'product_id=?', array($id));
         //delete videos
         Record::deleteWhere('ecommerce_product_video', 'product_id=?', array($id));
         if ($product->delete()) {
             //add log entry
             $this->_insert_log('Product \'' . $product_title . '\' was deleted.');
             Flash::set('success', __('Product has been deleted!'));
         } else {
             Flash::set('error', __('Product has not been deleted!'));
         }
     } else {
         Flash::set('error', __('Product not found!'));
     }
     redirect(get_url('plugin/ecommerce/product'));
 }