I am trying to retrieve the project names for all the active projects. I was following the documentation and code given over hereHarvest API. But it throws an error Call to undefined method HarvestAPI::getActiveProjects .Here is the code which I have written
<?php
require_once(dirname(__FILE__) . '/HarvestAPI.php');
/* Register Auto Loader */
spl_autoload_register(array('HarvestAPI', 'autoload'));
$api = new HarvestAPI();
$api->setUser( $user );
$api->setPassword( $password );
$api->setAccount($account );
$api->setRetryMode( HarvestAPI::RETRY );
$api->setSSL(true);
$result = $api->getActiveProjects();
foreach( $result->data as $project ) {
echo $project->name;
}
?>
P.S. I have administrator access for the account. So, I should be able to view all project titles
Look into HarvestAPI.php you will see that there is no method called getActiveProjects
Use this one
public function getProjects( $updated_since = null )
{
$url = "projects" . $this->appendUpdatedSinceParam( $updated_since );
return $this->performGET( $url, true );
}
Related
I'm writing a small routing system for a project. It's not perfect and it's a custom solution that will map the url to their templates if requested from the user. I want to generate a dynamic page based on an unique id for each event inserted inside the database from the user. So if the user request the event 1234 it will get a page with the event detail at the url https://mysitedomain.com/event/1234. I need to understand how to achieve this with my code, I'm using a front controller and red bean as ORM to access the database.
Here is the code of my router. Any suggestion will be appreciated. for now I'm only able to serve the templates.
<?php
namespace Router;
define('TEMPLATE_PATH', dirname(__DIR__, 2).'/assets/templates/');
class Route {
private static $assets = ['bootstrap' => 'assets/css/bootstrap.min.css',
'jquery' => 'assets/js/jquery.min.js',
'bootstrapjs' => 'assets/js/bootstrap.min.js',
];
public static function init()
{
if( isset($_SERVER['REQUEST_URI']) ){
$requested_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH);
if( $requested_uri === '/' ){
echo self::serveTemplate('index', self::$assets);
}
elseif( $requested_uri != '/' ){
$requested_uri = explode('/', $_SERVER['REQUEST_URI']);
if( $requested_uri[1] === 'event' ){
echo self::serveTemplate('event', self::$assets, ['event_id' => 001] );
}
else{
echo self::serveTemplate($view, self::$assets);
}
}
}
}
private static function serveTemplate(string $template, array $data, array $event_id = null)
{
if( !is_null($event_id) ){
$data[] = $event_id;
ob_start();
extract($data);
require_once TEMPLATE_PATH."$template.php";
return ob_get_clean();
}
else{
ob_start();
extract($data);
require_once TEMPLATE_PATH."$template.php";
return ob_get_clean();
}
}
}
?>
Writing a router from scratch is a little complex, you have to play a lots with regular expression to accommodate various scenario of requested url and your router should handle HTTP methods like POST, GET, DELETE, PUT and PATCH.
You may want to use existing libraries like Fast Route, easy to use and it's simplicity could give you idea how it is created.
I have a page dashboard.php, which creates a merchant dashboard that shows deals submitted by the merchant. I'm simply trying to separate types of deals by checking to see if a deal is a suggested deal:
...
while ($deals->have_posts()) : $deals->the_post();
$suggested_deal = SA_Post_Type::get_instance( $post->ID );
$boolsuggesteddeal = $suggested_deal->is_suggested_deal();
...
However, the is_suggested_deal() line is causing the page to not display anything past that line.
The SA_POST_TYPE class is outlined below:
class SA_Post_Type extends Group_Buying_Deal {
...
public static function get_instance( $id = 0 ) {
if ( !$id ) {
return NULL;
}
if ( !isset( self::$instances[$id] ) || !self::$instances[$id] instanceof self ) {
self::$instances[$id] = new self( $id );
}
if ( self::$instances[$id]->post->post_type != parent::POST_TYPE ) {
return NULL;
}
return self::$instances[$id];
}
...
public function is_suggested_deal() {
$term = array_pop( wp_get_object_terms( $this->get_id(), self::TAX ) );
return $term->slug == self::TERM_SLUG;
}
...
Since the class and function are both public, why am I unable to call the function? Any help would be greatly appreciated.
EDIT: I can't figure out how to get error reporting on without showing all site users the errors, I'm on a live site. I tried creating an instance of SA_Post_Type(), but that alone cause the page to fail to load anything after that line.
You have not created an instance of the class, do so like this...
$SA_Post_Type = new SA_Post_Type();
Then you are able to access the function...
$boolsuggesteddeal = $SA_Post_Type->is_suggested_deal();
Since is_suggested_deal is not a static function, you have to create a new instance of the SA_Post_Type class firstly.
$sa_post_type = new SA_Post_Type();
$boolsuggesteddeal = $sa_post_type->is_suggested_deal();
Hope this helps.
I was looking for a solution as to how to save data from joomla frontend. I came across the following code for controller and model which works perfectly. But I was looking for a standard practice like its done in the back end using jform, jtable etc ... In the following code (inside model), the saving technique do not look so appealing. And I am totally without any idea how the server side validations is implemented.
It might be confusing, so i would like to reiterate that in the backend we don't even have to write the add or save or update function, it is automatically handled by the core classes with both client and server side validation. So i was looking for something like that.
Controller
<?php
// No direct access.
defined('_JEXEC') or die;
// Include dependancy of the main controllerform class
jimport('joomla.application.component.controllerform');
class JobsControllerRegistration extends JControllerForm
{
public function getModel($name = 'Registration', $prefix = 'JobsModel', $config = array('ignore_request' => true))
{
return parent::getModel($name, $prefix, array('ignore_request' => false));
}
public function submit()
{
// Check for request forgeries.
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Initialise variables.
$app = JFactory::getApplication();
$model = $this->getModel('Registration');
// Get the data from the form POST
$data = JRequest::getVar('jform', array(), 'post', 'array');
$form = $model->getForm();
if (!$form) {
JError::raiseError(500, $model->getError());
return false;
}
// Now update the loaded data to the database via a function in the model
$upditem = $model->updItem($data);
// check if ok and display appropriate message. This can also have a redirect if desired.
if ($upditem) {
echo "<h2>Joining with us is successfully saved.</h2>";
} else {
echo "<h2>Joining with us faild.</h2>";
}
return true;
}
}
Model
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// Include dependancy of the main model form
jimport('joomla.application.component.modelform');
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
// Include dependancy of the dispatcher
jimport('joomla.event.dispatcher');
/**
* HelloWorld Model
*/
class JobsModelRegistration extends JModelForm
{
/**
* #var object item
*/
protected $item;
/**
* Get the data for a new qualification
*/
public function getForm($data = array(), $loadData = true)
{
$app = JFactory::getApplication('site');
// Get the form.
$form = $this->loadForm('com_jobs.registration', 'registration', array('control' => 'jform', 'load_data' => true),true);
if (empty($form)) {
return false;
}
return $form;
}
//Nwely added method for saving data
public function updItem($data)
{
// set the variables from the passed data
$fname = $data['fname'];
$lname = $data['lname'];
$age = $data['age'];
$city = $data['city'];
$telephone = $data['telephone'];
$email = $data['email'];
$comments = $data['comments'];
// set the data into a query to update the record
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->clear();
$db =& JFactory::getDBO();
$query = "INSERT INTO #__joinwithus ( `id`, `firstname`, `lastname`, `age`, `city`, `telephone`, `email`, `comment`)
VALUES (NULL,'" . $fname . "','" . $lname . "','" . $age . "','" . $city . "','" . $email . "','" . $telephone . "','" . $comments . "')";
$db->setQuery((string)$query);
if (!$db->query()) {
JError::raiseError(500, $db->getErrorMsg());
return false;
} else {
return true;
}
}
}
Can somebody kindly point me to a good tutorial or share me a component which deals with form in the frontend with joomla 2.5.
use the following code in your model
$data = $app->input->getArray($_POST);
$query = $db->getQuery(true);
You should be able to use jcontrollerform's methods directly, instead of writing your own submit()-method (and updItem()) like you do. I describe something similar here. This means you display your form the usual way using jform, and use action="index.php?option=com_jobs&task=save&view=registration&id=whateverid"
This way jcontrollerform->save() is used, which in turn calls your model's save(). (Hmmm, this probably means your model should extend JModelAdmin instead of JModelForm, to include the relevant methods. ) This will run all the necessary validation checks etc.
You might need to register paths for the model, table and form that you want to be using, like I do in the link.
You need to include the id in the url parameters if you edit existing data, because the jform[id] - parameter will be ignored.
Sorry I dont have any good tutorial or whatever for you, hope this helps.
Im trying to use VisualCaptcha with my Laravel apps. I have tried to adapt this exemple with my code. But I dont know how to adapt this following callback to my controller :
$app->get( '/audio(/:type)', function( $type = 'mp3' ) use( $app ) {
$captcha = new \visualCaptcha\Captcha( $app->session );
if ( ! $captcha->streamAudio( $app->response, $type ) ) {
$app->pass();
}
} );
Here is my controller :
class CaptchaController extends BaseController {
/**
* Start Captcha
*/
public function start($params)
{
$session = new SessionCaptcha();
$captcha = new Captcha($session);
return $captcha->generate();
}
public function audio()
{
$session = new SessionCaptcha();
$captcha = new Captcha($session);
//$response = Response::make();
$response->header('Access-Control-Allow-Origin', '*');
//return var_dump($response);
return $captcha->streamAudio($response, 'mp3');
}
}
The start function works but not the audio function... I dont know how to add the first parameter to "$captcha->streamAudio($firstParam, $extension)".
Just in case other people land here first, this has been answered at https://github.com/emotionLoop/visualCaptcha-PHP/issues/16#issuecomment-53863330
The author mentioned not returning $captcha->generate(); but also some undisclosed modifications.
i am creating a joomla2.5 module.
I want to retrieve the data pass through parameter from the module, but am getting the about title error. Below is my code:
helper.php
class modFeedGrabber
{
function feedurl(){
$url = $params->get('feedUrl');
return $url;
}
function maxCount(){
$maxcount = $params->get('maxCount');
return $maxcount;
}
function showDesc(){
return $params->get('showDesc');
}
function showPubDate(){
return $params->get('showPubDate');
}
function targetLink(){
return $params->get('titleLinkTarget');
}
function descChar(){
return $params->get('descCharacterLimit');
}
function fx(){
return $params->get('fx');
}
function delay(){
return $params->get('delay');
}
function timeout(){
return $params->get('timeout');
}
function module_sfx(){
return $params->get('moduleclass_sfx');
}
}
mod_feedGrabber.php
defined( '_JEXEC' ) or die( 'Restricted access' );
$sitebase = JPATH_BASE;
$doc =& JFactory::getDocument();
// Include the syndicate functions only once
require_once( dirname(__FILE__).DS.'/helper.php' );
$feed = new modFeedGrabber();
$url = $feed->feedurl($url);
$maxcount = $feed->maxcount($maxcount);
require( JModuleHelper::getLayoutPath( 'mod_feedGrabber' ) );
My new quetion is how can i get data pass from the module?
To illustrate my comments above:
$url = $feed->feedurl($url);
^^^^---- $url is not defined at this point
doesn't matter if feedurl() returns a $url value. At the time you CALL feedurl(), the $url you're trying to pass into the method is undefined. SO within feedurl(), you're doing
$url = $params->get(...);
^^^^^^^---the $url you passed in to the method, which is null/undefined
Then, of course, there's other problems:
$url = $params->get(feedUrl);
^^^^^^^--- undefined constant