I think I've managed to do it by using poundservice and poundvalidator, thanks for pointing me in the right direction! It seems to work, but I am only one person and still not great at this so if anyone sees this and wants to test it out for bugs feel free
In service/applicationservice/poundservice.php scroll to the bottom and where it says private function validatePound(), replace it with this:
PHP:
private function validatePound(OwnedAdoptable $adopt){
$validations = new ArrayObject(["adopt", "owner", "number", "recurrence", "money", "favpet"]);
$validator = new PoundValidator($adopt, $this->getCost($adopt, "pound"), $this->settings, $validations);
$validator->validate();
}
That adds a check for favpet, which we need to set up.
In service/validator/poundvalidator.php, scroll to the bottom and put this (but make sure it's before the last curly bracket!):
PHP:
protected function checkFavpet(){
$mysidia = Registry::get("mysidia");
$favpetID = $mysidia->db->select("users_profile", array("uid", "favpet"), "uid = '{$mysidia->user->getID()}'")->fetchObject();
if($favpetID->favpet == $this->adopt->getAdoptID()){
throw new PoundException("favpet");
}
Then open lang/main/lang_pound.php and put this somewhere:
PHP:
$lang['favpet'] = "This adopt is your favpet! You cannot pound them!";
And that seems to work. When you go to pound an adopt it will throw the above error and if you go to manage the favpet you still have them.
Now, this happens if you go to the pound page and click the confirm button. But what if you want the page to look different and stop you seeing the option to pound them in the first place?
Open view/main/poundview.php, go to public function pound(), and add this line in:
PHP:
$favpetID = $mysidia->db->select("users_profile", array("uid", "favpet"), "uid = '{$mysidia->user->getID()}'")->fetchObject();
I put it underneath:
PHP:
$adopt = $this->getField("adopt");
$confirm = $this->getField("confirm");
Just so it stays at the top lol. Then find:
PHP:
if($confirm){
$cost = $this->getField("cost");
$document->setTitle($this->lang->pound_complete);
$document->addLangvar($this->lang->pound_success);
$document->addLangvar(" at a cost of {$cost->getValue()} {$mysidia->settings->cost}");
$document->addLangvar($this->lang->afterwards);
return;
}
And underneath that put this:
PHP:
if($favpetID->favpet == $adopt->getAdoptID()){
$document->setTitle("Oops!");
$document->add(new Comment("You cannot pound your favpet!"));
return;
}
My full poundview.php in case you want to just copy it (this would only work if you haven't edited it yourself!):
PHP:
<?php
namespace View\Main;
use Resource\Collection\LinkedList;
use Resource\Core\Model;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\GUI\Component\Button;
use Resource\GUI\Component\Image;
use Resource\GUI\Component\Link;
use Resource\GUI\Container\Form;
use Resource\GUI\Container\TCell;
use Resource\GUI\Document\Comment;
use Resource\GUI\Document\Division;
use Resource\GUI\Element\Align;
use Service\Builder\TableBuilder;
use Service\Helper\AdoptTableHelper;
class PoundView extends View{
public function index(){
$document = $this->document;
$document->setTitle($this->lang->title);
$document->addLangvar($this->lang->default);
$readoptForm = new Form("readoptform", "pound/adopt", "post");
$readoptHeader = new Comment("Pounded Adoptables for adoption");
$readoptHeader->setHeading(3);
$readoptForm->add($readoptHeader);
$helper = new AdoptTableHelper;
$readoptTable = new TableBuilder("readopttable");
$readoptTable->setAlign(new Align("center", "middle"));
$readoptTable->buildHeaders("Select", "Image", "Basic Info", "Additional Info");
$readoptTable->setHelper($helper);
$poundMap = $this->getField("poundMap");
$iterator = $poundMap->iterator();
while($iterator->hasNext()){
$entry = $iterator->next();
$adopt = $entry->getKey();
$cost = $entry->getValue();
$cells = new LinkedList;
$cells->add(new TCell($helper->getPoundButton($adopt->getAdoptID())));
$cells->add(new TCell($adopt->getImage(Model::GUI)));
$cells->add(new TCell($helper->getBasicInfo($adopt->getName(), $cost->getValue())));
$cells->add(new TCell($helper->getAdditionalInfo($adopt)));
$readoptTable->buildRow($cells);
}
$notice = new Comment("Select an adoptable from above to become its new owner.");
$notice->setHeading(3);
$readoptForm->add($readoptTable);
$readoptForm->add($notice);
$readoptForm->add(new Button("Adopt Me", "submit", "submit"));
$document->add($readoptForm);
}
public function pound(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$adopt = $this->getField("adopt");
$confirm = $this->getField("confirm");
$favpetID = $mysidia->db->select("users_profile", array("uid", "favpet"), "uid = '{$mysidia->user->getID()}'")->fetchObject();
if($confirm){
$cost = $this->getField("cost");
$document->setTitle($this->lang->pound_complete);
$document->addLangvar($this->lang->pound_success);
$document->addLangvar(" at a cost of {$cost->getValue()} {$mysidia->settings->cost}");
$document->addLangvar($this->lang->afterwards);
return;
}
if($favpetID->favpet == $adopt->getAdoptID()){
$document->setTitle("Oops!");
$document->add(new Comment("You cannot pound your favpet!"));
return;
}
else{
$document->setTitle($this->lang->pound_title);
$document->add($adopt->getImage(Model::GUI));
$document->add(new Comment("<br>{$this->lang->pound}<br><br>{$this->lang->pound_warning}<br>"));
$options = new Division("pound");
$options->setAlign(new Align("center"));
$options->add(new Image("templates/icons/delete.gif", "Pound"));
$options->add(new Link("pound/pound/{$adopt->getAdoptID()}/confirm", "Pound {$adopt->getName()} - I don't want it anymore!", TRUE));
$options->add(new Image("templates/icons/yes.gif", "Do not pound"));
$options->add(new Link("myadopts/manage/{$adopt->getAdoptID()}", "DO NOT Pound {$adopt->getName()}"));
$document->add($options);
}
}
public function adopt(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if($mysidia->input->post("submit")){
$document->setTitle($this->lang->global_action_complete);
$document->addLangvar($this->lang->readopt_success);
$cost = $this->getField("cost");
if($cost) $document->addLangvar(" at a cost of {$cost->getValue()} {$mysidia->settings->cost}");
}
}
}
That makes it so users see an error when
attempting to pound their favourite pet. And if users have figured it out and sneakily go to add /confirm to the URL to pound their pet, they see the other error that we set up before! So they cannot pound their favpet and they also see a separate page attempting to pound them.
If anyone sees this and there's a different way of doing it let me know! I'm still learning and tinkering with the new structure so I'm up for changing things and seeing how to better do what I need to