public function loadModel($id) { $model = Reward::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * Load all user rewards and set them to group index. * Every user can have only one reward for a group. * * <code> * $options = array( * 'user_id' => 1, * 'group_id' => 2 * ); * * $userRewards = new Gamification\User\Rewards(JFactory::getDbo()); * $userRewards->load($options); * </code> * * @param array $options */ public function load(array $options = array()) { $userId = $this->getOptionId($options, 'user_id'); $groupId = $this->getOptionId($options, 'group_id'); // Create a new query object. $query = $this->db->getQuery(true); $query->select('a.reward_id, a.user_id, a.group_id')->select('b.title, b.points, b.image, b.published, b.points_id, b.group_id')->from($this->db->quoteName('#__gfy_userrewards', 'a'))->innerJoin($this->db->quoteName('#__gfy_rewards', 'b') . ' ON a.reward_id = b.id')->where('a.user_id = ' . (int) $userId); if ($groupId > 0) { $query->where('a.group_id = ' . (int) $groupId); } $this->db->setQuery($query); $results = (array) $this->db->loadAssocList(); if (count($results) > 0) { $this->userId = $userId; foreach ($results as $result) { $reward = new Reward(\JFactory::getDbo()); $reward->bind($result); $this->items[$result['group_id']][$reward->getRewardId()] = $reward; } } }
public function actionCreate() { $this->pageTitle = 'Jobstar - Create Reward'; error_reporting(E_ALL & ~E_NOTICE); $model = new Reward(); $rewardImagesModel = new RewardImages(); $Tags = new Tags(); if (isset($_POST['Reward']) && !empty($_POST['Reward'])) { $model->attributes = $_POST['Reward']; $model->category_id = $_POST['Reward']['category_id']; //echo "<pre>"; //print_r($model->attributes); if ($model->save()) { //echo "----"; $useridFolder = $model->id; if (isset($_POST['tags'])) { $getTags = $_POST['tags']; $mystring = $getTags; $findme = ','; $pos = strpos($mystring, $findme); if ($pos === false) { //echo "The string '$findme' was not found in the string '$mystring'"; //if that tag name already exist, skip that tag $chkTagExist = Tags::model()->find('name = :name', array(':name' => $getTags)); if (empty($chkTagExist)) { // echo "Tag not exist"; $insertMultiDoc = Yii::app()->db->createCommand()->insert('tags', array('reward_id' => $model->id, 'name' => $getTags)); } else { //echo "dont save the record"; } } else { //echo "The string '$findme' was found in the string '$mystring'"; //echo " and exists at position $pos"; //explode with comma $getTagArray = explode(',', $getTags); //insert into tags table with reward model id. foreach ($getTagArray as $tagVal) { //if that tag name already exist, skip that tag $chkTagExist = Tags::model()->find('name = :name', array(':name' => $tagVal)); if (empty($chkTagExist)) { // echo "Tag not exist"; $insertMultiDoc = Yii::app()->db->createCommand()->insert('tags', array('reward_id' => $model->id, 'name' => $tagVal)); } else { //echo "dont save the record"; } } } } //end tags $images = CUploadedFile::getInstancesByName('images'); // proceed if the images have been set if (isset($images) && count($images) > 0) { //upload multiple images, first create folder with reward id and store all related images in that folder. // create folder if ($_SERVER['DOCUMENT_ROOT'] == '/var/www/html') { $setDir = $_SERVER['DOCUMENT_ROOT'] . "/images/reward/" . $useridFolder; } else { $setDir = $_SERVER['DOCUMENT_ROOT'] . "/jobstar/images/reward/" . $useridFolder; } if (is_dir($setDir) == false) { mkdir("{$setDir}", 0777, true); chmod("{$setDir}", 0777); } //end //echo $setDir; //die; // go through each uploaded image $i = 0; foreach ($images as $image => $pic) { if ($i == '0') { //first image will be default $setDefaultStatus = '1'; } else { $setDefaultStatus = '0'; } //echo $pic->name.'<br />'; $finalName = $setDir . "/" . $pic->name; //echo "<br>"; if ($pic->saveAs($finalName)) { // add it to the main model now //$img_add = new Picture(); //$img_add->filename = $pic->name; //it might be $img_add->name for you, filename is just what I chose to call it in my model //$img_add->topic_id = $model->id; // this links your picture model to the main model (like your user, or profile model) $insertMultiDoc = Yii::app()->db->createCommand()->insert('rewardimages', array('reward_id' => $model->id, 'image' => $pic->name, 'defaultImage' => $setDefaultStatus)); //$img_add->save(); // DONE } else { // handle the errors here, if you want } $i++; } //end foreach } // if image is uploaded by admin } //die('end'); $this->redirect(array('admin', 'id' => $model->id)); } //end post method $this->render('create', array('model' => $model)); }
<!-- http://www.fyneworks.com/jquery/multiple-file-upload/ http://www.bsourcecode.com/2013/03/yii-cmultifileupload/ --> <!-- <input type="file" class="multi" name="images" accept="gif|jpg"/> --> <?php //echo $form->hiddenField($model, 'image'); ?> <!-- show all images in the existing table --> <?php if ($model->isNewRecord != '1' || !empty($model->filepath)) { if ($model->id != '') { echo $allImages = Reward::model()->showAllImagesWithDelIcon($model->id); } } $this->widget('CMultiFileUpload', array('name' => 'images', 'max' => 6, 'accept' => 'jpeg|jpg|gif', 'duplicate' => 'Duplicate file!', 'denied' => 'Invalid file type')); echo $form->error($model, 'image'); ?> <div style="color:red;"> <?php echo Yii::app()->user->getFlash('imageErrMsg'); ?> </div>
// the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see <http://www.gnu.org/licenses/>. // BTC Donations: 163Pv9cUDJTNUbadV4HMRQSSj3ipwLURRc //Set page starter variables// include dirname(__FILE__) . "/../includes/requiredFunctions.php"; //Include Reward class include $includedir . 'reward.php'; $reward = new Reward(); //Check that script is run locally ScriptIsRunLocally(); lock("shares"); //Include Block class include $includedir . "block.php"; $block = new Block(); //Get current block number $currentBlockNumber = $bitcoinController->getblocknumber(); $lastBlockNumber = $currentBlockNumber - 1; //Get latest block in database $latestDbBlock = $block->getLatestDbBlockNumber(); //Do block work if new block if ($latestDbBlock < $lastBlockNumber) { //Insert last block number into networkBlocks include $includedir . "stats.php";
<?php /* @var $this DocController */ /* @var $model Doc */ $this->breadcrumbs = array('Reward' => array('index'), $model->title); $this->menu = array(array('label' => 'List Reward', 'url' => array('index')), array('label' => 'Delete Reward', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => 'Manage Reward', 'url' => array('admin'))); ?> <h1>View Reward #<?php echo $model->id; ?> </h1> <div class="rewardview"> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('title', 'description', 'createTime', array('label' => 'Category Type', 'type' => 'raw', 'value' => Reward::searchCat($model->category_id)), array('label' => 'Tags', 'type' => 'raw', 'value' => Reward::searchTag($model->id)), array('label' => 'Attachment', 'type' => 'raw', 'value' => Reward::showAllImages($model->id))))); ?> </div>
public function actionCreate() { $this->pageTitle = 'Jobstar - Create Reward'; error_reporting(E_ALL & ~E_NOTICE); $model = new Reward(); $rewardImagesModel = new RewardImages(); $Tags = new Tags(); if (isset($_POST['Reward']) && !empty($_POST['Reward'])) { //check product name duplicacy $chkTitle = $_POST['Reward']['title']; $chkPrice = $_POST['Reward']['price']; $chkCategory = $_POST['Reward']['category_id']; $chkRewardExist = Reward::model()->find('title = :title', array(':title' => $chkTitle)); if (!empty($chkRewardExist)) { Yii::app()->user->setFlash('errDupTitle', 'Reward name exist in database, please enter another.'); $this->redirect(array('create', 'titleSet' => $chkTitle, 'priceSet' => $chkPrice, 'categorySet' => $chkCategory)); } //end checking //check image is uploaded or not $chkImageUploaded = CUploadedFile::getInstancesByName('images'); if (isset($chkImageUploaded) && count($chkImageUploaded) > 0) { //do nothing.... this is done only for validation } else { //please select image Yii::app()->user->setFlash('imageErrMsg', 'Please upload image.'); $model->attributes = $_POST['Reward']; //$this->redirect(array('create')); $this->redirect(array('create', 'titleSet' => $chkTitle, 'priceSet' => $chkPrice, 'categorySet' => $chkCategory)); } // end validation $model->attributes = $_POST['Reward']; $model->category_id = $_POST['Reward']['category_id']; $model->status = '1'; $model->description = $_POST['Reward']['description']; //echo "<pre>"; //print_r($model->attributes); if ($model->save()) { //echo "----"; $useridFolder = $model->id; if (isset($_POST['tag']) && $_POST['tag'] != '') { $getTags = $_POST['tag']; $mystring = $getTags; $findme = ','; $pos = strpos($mystring, $findme); if ($pos === false) { //echo "The string '$findme' was not found in the string '$mystring'"; //if that tag name already exist, skip that tag $chkTagExist = Tags::model()->find('name = :name', array(':name' => $getTags)); if (empty($chkTagExist)) { // echo "Tag not exist"; $insertMultiDoc = Yii::app()->db->createCommand()->insert('tags', array('reward_id' => $model->id, 'name' => $getTags)); } else { //echo "dont save the record"; } } else { //echo "The string '$findme' was found in the string '$mystring'"; //echo " and exists at position $pos"; //explode with comma $getTagArray = explode(',', $getTags); //insert into tags table with reward model id. foreach ($getTagArray as $tagVal) { //if that tag name already exist, skip that tag $chkTagExist = Tags::model()->find('name = :name', array(':name' => $tagVal)); if (empty($chkTagExist)) { // echo "Tag not exist"; $insertMultiDoc = Yii::app()->db->createCommand()->insert('tags', array('reward_id' => $model->id, 'name' => $tagVal)); } else { //echo "dont save the record"; } } } } //end tags $images = CUploadedFile::getInstancesByName('images'); //echo "<pre>"; //print_r($images); // proceed if the images have been set if (isset($images) && count($images) > 0) { //upload multiple images, first create folder with reward id and store all related images in that folder. // create folder if ($_SERVER['DOCUMENT_ROOT'] == '/var/www/html') { $setDir = $_SERVER['DOCUMENT_ROOT'] . "/images/reward/" . $useridFolder; } else { $setDir = $_SERVER['DOCUMENT_ROOT'] . "/jobstar/images/reward/" . $useridFolder; } if (is_dir($setDir) == false) { mkdir("{$setDir}", 0777, true); chmod("{$setDir}", 0777); } else { chmod("{$setDir}", 0777); } // go through each uploaded image $i = 0; foreach ($images as $thefile) { if ($i == '0') { //first image will be default $setDefaultStatus = '1'; } else { $setDefaultStatus = '0'; } //echo $pic->name.'<br />' error, size; //$finalName = $setDir."/".$pic->name; //echo "<br>"; $imagetime = time(); $image = $thefile; //$type = $pic->type; $type = $thefile->extensionName; $destination = $_SERVER['DOCUMENT_ROOT'] . "/jobstar/images/reward/" . $useridFolder; $finalName = $setDir . "/" . $imagetime . "_" . $i; $thumbnailImage = $setDir . "/" . $imagetime . "_" . $i; if ($image->saveAs($finalName . '.' . $type)) { $dbFileName = $imagetime . "_" . $i . '.' . $type; $chkThumb = $this->createimage(270, 200, $thumbnailImage, 'm', $type); if ($chkThumb == 0) { // add it to the main model now $insertMultiDoc = Yii::app()->db->createCommand()->insert('rewardimages', array('reward_id' => $model->id, 'image' => $dbFileName, 'defaultImage' => $setDefaultStatus)); $chkThumb = $this->createimage(270, 200, $thumbnailImage, 'm', $type); } else { $this->redirect(array('create')); } } else { // handle the errors here, if you want } $i++; } //end foreach } else { //please select image Yii::app()->user->setFlash('imageErrMsg', 'Please upload image.'); } } //die('end'); $this->redirect(array('admin', 'id' => $model->id)); } //end post method $this->render('create', array('model' => $model)); }