insert() публичный Метод

public insert ( array $Fields ) : boolean
$Fields array
Результат boolean
Пример #1
0
 /**
  * Add screenshots to an addon.
  *
  * @param string $AddonID Addon in question.
  * @throws Exception No permission manage addon's pictures.
  * @throws Gdn_UserException Addon not found.
  */
 public function addPicture($AddonID = '')
 {
     $Session = Gdn::session();
     if (!$Session->isValid()) {
         $this->Form->addError('You must be authenticated in order to use this form.');
     }
     $Addon = $this->AddonModel->getID($AddonID);
     if (!$Addon) {
         throw notFoundException('Addon');
     }
     if ($Session->UserID != $Addon['InsertUserID']) {
         $this->permission('Addons.Addon.Manage');
     }
     $this->addModule('AddonHelpModule', 'Panel');
     $AddonPictureModel = new Gdn_Model('AddonPicture');
     $this->Form->setModel($AddonPictureModel);
     $this->Form->addHidden('AddonID', $AddonID);
     if ($this->Form->authenticatedPostBack() === true) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->validateUpload('Picture');
             // Generate the target image name
             $TargetImage = $UploadImage->generateTargetName(PATH_UPLOADS, '');
             $ImageBaseName = 'addons/screens/' . pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image in large size
             $ImgParsed = $UploadImage->saveImageAs($TmpImage, changeBaseName($ImageBaseName, 'ao%s'), 700, 1000);
             // Save the uploaded image in thumbnail size
             $ThumbSize = 150;
             $ThumbParsed = $UploadImage->saveImageAs($TmpImage, changeBasename($ImageBaseName, 'at%s'), $ThumbSize, $ThumbSize);
             $ImageBaseName = sprintf($ImgParsed['SaveFormat'], $ImageBaseName);
         } catch (Exception $ex) {
             $this->Form->addError($ex->getMessage());
         }
         // If there were no errors, insert the picture
         if ($this->Form->errorCount() == 0) {
             $AddonPictureModel = new Gdn_Model('AddonPicture');
             $AddonPictureModel->insert(array('AddonID' => $AddonID, 'File' => $ImageBaseName));
         }
         // If there were no problems, redirect back to the addon
         if ($this->Form->errorCount() == 0) {
             $this->RedirectUrl = url('/addon/' . AddonModel::slug($Addon));
         }
     }
     $this->render();
 }
Пример #2
0
 /**
  * Automatically add the current core version if not specified in the fields.
  * 
  * @param array $fields The data you want to insert into the model.
  * @return bool
  */
 public function insert($fields)
 {
     if (!array_key_exists('CoreVersionID', $fields)) {
         $fields['CoreVersionID'] = $this->getCoreVersion()->AddonVersionID;
     }
     return parent::insert($fields);
 }