Mys 1.3.4 Paging in admin panel für images

Forum
Last Post
Threads / Messages

anno1986

Member
Member
Joined
Jan 21, 2014
Messages
3
Points
0
Mysidian Dollar
0
The following patch provides paging for the image menu in admin panel.
Useful for slow connections and/or many pictures stored in filemap database table

diff -ruw v1.3.4/admincp/image.php src/admincp/image.php
Code:
--- v1.3.4/admincp/image.php	2013-08-24 23:29:48.000000000 +0200
+++ src/admincp/image.php	2014-01-26 18:18:36.000000000 +0100
@@ -103,11 +103,20 @@
 
 	public function manage(){
 	    $mysidia = Registry::get("mysidia");
-		$stmt = $mysidia->db->select("filesmap", array("id", "wwwpath"));
+	    // anno1986 added paging for images
+	    $total = $mysidia->db->select("filesmap", array("id"))->rowCount();
+	    $pagination = new Pagination($total, 9, "admincp/image/delete");
+        $pagination->setPage($mysidia->input->get("page"));
+        // anno1986 added paging for images
+		$stmt = $mysidia->db->select("filesmap", array("id", "wwwpath"), "1 LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");
 		$filesMap = new LinkedHashMap;
 		while($file = $stmt->fetchObject()){
-		    $filesMap->put(new Integer($file->id), new Image($file->wwwpath));
+		    $img = new Image($file->wwwpath);
+            //$img->resample(100,null);
+		    $filesMap->put(new Integer($file->id), $img);
 		}
+        // anno1986 added paging for images
+        $this->setField("pagination", $pagination);
 		$this->setField("filesMap", $filesMap);
 	}


diff -ruw v1.3.4/admincp/view/imageview.php src/admincp/view/imageview.php
Code:
--- v1.3.4/admincp/view/imageview.php	2013-04-26 21:04:22.000000000 +0200
+++ src/admincp/view/imageview.php	2014-01-26 18:15:00.000000000 +0100
@@ -36,7 +36,12 @@
 		$document->setTitle($this->lang->manage_title);
 		$document->addLangvar($this->lang->manage);
 		
+        $pagination = $this->getField("pagination");
+		
 		$imageForm = new Form("manageform", "delete", "post");		
+        // anno1986 added paging to image view
+        $imageForm->add(new Comment($pagination->showPage()));
+        
 		$filesMap = $this->getField("filesMap");
 		$iterator = $filesMap->iterator();
         while ($iterator->hasNext()){
@@ -46,10 +51,17 @@
 			$fileImage->setLineBreak(TRUE);
 			
 		    $action = new RadioButton("Delete this Image", "iid", $fileID->getValue());
-			$action->setLineBreak(TRUE);
+			//$action->setLineBreak(TRUE);
+			$imageForm->add(new Comment("<div style='display:inline-block;width:270px;margin-top:20px;'>",FALSE));
 			$imageForm->add($fileImage);
 			$imageForm->add($action);
+            
+            $imageForm->add(new Comment("</div>", FALSE));
+            
 		}
+        // anno1986 added paging to image view
+        $imageForm->add(new Comment($pagination->showPage()));
+        
         $imageForm->add(new Button("Submit", "submit", "submit"));
 		$document->add($imageForm);
 	}
 
This doesn't really explain how to add the fix. It might be ok for coders but some of us are beginners or even non coders.
 
after trying and testing I manage to make the code work, because copy and paste just gives a blank page, and so i will post the code thats working for me for those that don't have idea what to do... like me XD



in admincp/image.php find:
PHP:
	public function manage(){
	    $mysidia = Registry::get("mysidia");
		$stmt = $mysidia->db->select("filesmap", array("id", "wwwpath"));
		$filesMap = new LinkedHashMap;
		while($file = $stmt->fetchObject()){
		    $filesMap->put(new Integer($file->id), new Image($file->wwwpath));
		}
		$this->setField("filesMap", $filesMap);
	}
and replace with:
PHP:
  	public function manage(){
 	    $mysidia = Registry::get("mysidia");
		$stmt = $mysidia->db->select("filesmap", array("id", "wwwpath"));
	    $total = $mysidia->db->select("filesmap", array("id"))->rowCount();
	    $pagination = new Pagination($total, 20, "admincp/image/delete");
        $pagination->setPage($mysidia->input->get("page"));	
        $stmt = $mysidia->db->select("filesmap", array("id", "wwwpath"), "1 LIMIT {$pagination->getLimit()},{$pagination->getRowsperPage()}");		
 		$filesMap = new LinkedHashMap;
 				while($file = $stmt->fetchObject()){
		    $filesMap->put(new Integer($file->id), new Image($file->wwwpath));

		}
        $this->setField("pagination", $pagination);
 		$this->setField("filesMap", $filesMap);
 	}

in admincp/view/imageview.php find:
PHP:
	public function manage(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;	
		$document->setTitle($this->lang->manage_title);
		$document->addLangvar($this->lang->manage);
		
		$imageForm = new Form("manageform", "delete", "post");		
		$filesMap = $this->getField("filesMap");
		$iterator = $filesMap->iterator();
        while ($iterator->hasNext()){
		    $file = $iterator->next();
			$fileID = $file->getKey();
			$fileImage = $file->getValue();			
			$fileImage->setLineBreak(TRUE);
			
		    $action = new RadioButton("Delete this Image", "iid", $fileID->getValue());
			$action->setLineBreak(TRUE);
			$imageForm->add($fileImage);
			$imageForm->add($action);
		}
        $imageForm->add(new Button("Submit", "submit", "submit"));
		$document->add($imageForm);
	}

and replace with this:
PHP:
	public function manage(){
	    $mysidia = Registry::get("mysidia");
		$document = $this->document;	
		$document->setTitle($this->lang->manage_title);
		$document->addLangvar($this->lang->manage);
		$pagination = $this->getField("pagination");

		$imageForm = new Form("manageform", "delete", "post");
		$imageForm->add(new Comment($pagination->showPage()));
		$filesMap = $this->getField("filesMap");
		$iterator = $filesMap->iterator();
        while ($iterator->hasNext()){
		    $file = $iterator->next();
			$fileID = $file->getKey();
			$fileImage = $file->getValue();			
			$fileImage->setLineBreak(TRUE);
			
		    $action = new RadioButton("Delete this Image", "iid", $fileID->getValue());
			$action->setLineBreak(TRUE);
						$imageForm->add(new Comment("<div style='display:inline-block;width:100px;margin-top:20px;'>",FALSE));
 			$imageForm->add($fileImage);
 			$imageForm->add($action);
            $imageForm->add(new Comment("</div>", FALSE));
            
 		}
        $imageForm->add(new Comment($pagination->showPage()));
        
         $imageForm->add(new Button("Submit", "submit", "submit"));
 		$document->add($imageForm);
 	}

those are the codes that are working for me, hope it works for everyone else =)
and thanks anno1986 for posting the code ^^ because if i tried to do it myself i probably wont be able to do it.

also replace the "20" with the number of images you want to see in each page and replace "100" with the max width of your adoptbles.
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,277
Messages
33,118
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Top