public function setup()
 {
     $this->collection = new PodioCollection();
     $external_ids = array('a', 'b', 'c');
     for ($i = 1; $i < 4; $i++) {
         $item = new PodioItem();
         $item->property('id', 'integer');
         $item->property('external_id', 'string');
         $item->init();
         $item->id = $i;
         $item->external_id = $external_ids[$i - 1];
         $this->collection[] = $item;
     }
 }
function getAllItems($id)
{
    $items = PodioItem::filter($id);
    //$result = json_decode($items);
    //var_dump($result);
    //echo $result->app;
}
 public function getExternalId_values($allExteral_ids)
 {
     $i = 0;
     $items = PodioItem::filter($this->app_id, array('limit' => 60));
     foreach ($items['items'] as $item) {
         // Now you can extract values from the individual item. E.g.:
         for ($j = 0; $j < count($allExteral_ids); $j++) {
             $field = $item->field($allExteral_ids[$j]);
             $allValue[$j] = $field->humanized_value();
         }
         $allItems[$i] = $allValue;
         $i++;
     }
     return $allItems;
 }
/**
 * Backups $app to a subfolder in $path
 * 
 * @param type $app app to backup
 * @param type $path in this folder a subfolder for the app will be created
 */
function backup_app($app, $path, $downloadFiles)
{
    $path_app = $path . '/' . fixDirName($app->config['name']);
    global $verbose;
    if ($verbose) {
        echo "App: " . $app->config['name'] . "\n";
        echo "debug: MEMORY: " . memory_get_usage(true) . " | " . memory_get_usage(false) . "\n";
    }
    mkdir($path_app);
    $appFile = "";
    $appFiles = array();
    $files_in_app_html = "<html><head><title>Files in app: " . $app->config['name'] . "</title></head><body>" . "<table border=1><tr><th>name</th><th>link</th><th>context</th></tr>";
    try {
        #$appFiles = PodioFile::get_for_app($app->app_id, array('attached_to' => 'item'));
        $appFiles = PodioFetchAll::iterateApiCall('PodioFile::get_for_app', $app->app_id, array(), FILE_GET_FOR_APP_LIMIT);
        #var_dump($appFiles);
        PodioFetchAll::flattenObjectsArray($appFiles, PodioFetchAll::podioElements(array('file_id' => null, 'name' => null, 'link' => null, 'hosted_by' => null, 'context' => array('id' => NULL, 'type' => null, 'title' => null))));
        if ($verbose) {
            echo "fetched information for " . sizeof($appFiles) . " files in app.\n";
        }
    } catch (PodioError $e) {
        show_error($e);
    }
    try {
        $allitems = PodioFetchAll::iterateApiCall('PodioItem::filter', $app->app_id, array(), ITEM_FILTER_LIMIT, 'items');
        echo "app contains " . sizeof($allitems) . " items.\n";
        for ($i = 0; $i < sizeof($allitems); $i += ITEM_XLSX_LIMIT) {
            $itemFile = PodioItem::xlsx($app->app_id, array("limit" => ITEM_XLSX_LIMIT, "offset" => $i));
            RateLimitChecker::preventTimeOut();
            file_put_contents($path_app . '/' . $app->config['name'] . '_' . $i . '.xlsx', $itemFile);
            unset($itemFile);
        }
        $before = time();
        gc_collect_cycles();
        echo "gc took : " . (time() - $before) . " seconds.\n";
        foreach ($allitems as $item) {
            if ($verbose) {
                echo " - " . $item->title . "\n";
            }
            $folder_item = fixDirName($item->item_id . '_' . $item->title);
            $path_item = $path_app . '/' . $folder_item;
            mkdir($path_item);
            unset($itemFile);
            $itemFile = HumanFormat::toHumanReadableString($item);
            if ($downloadFiles) {
                foreach ($appFiles as $file) {
                    if ($file->context['type'] == 'item' && $file->context['id'] == $item->item_id) {
                        $link = downloadFileIfHostedAtPodio($path_item, $file);
                        # $link is relative to $path_item (if downloaded):
                        if (!preg_match("/^http/i", $link)) {
                            $link = RelativePaths::getRelativePath($path_app, $path_item . '/' . $link);
                        }
                        $itemFile .= "File: {$link}\n";
                        $files_in_app_html .= "<tr><td>" . $file->name . "</td><td><a href=\"" . $link . "\">" . $link . "</a></td><td>" . $file->context['title'] . "</td></tr>";
                    }
                }
            }
            //TODO refactor to use less api calls: (not possible??!)
            if ($item->comment_count > 0) {
                #echo "comments.. (".$item->comment_count.")\n";
                $comments = PodioComment::get_for('item', $item->item_id);
                RateLimitChecker::preventTimeOut();
                $commentsFile = "\n\nComments\n--------\n\n";
                foreach ($comments as $comment) {
                    $commentsFile .= 'by ' . $comment->created_by->name . ' on ' . $comment->created_on->format('Y-m-d at H:i:s') . "\n----------------------------------------\n" . $comment->value . "\n\n\n";
                    if ($downloadFiles && isset($comment->files) && sizeof($comment->files) > 0) {
                        foreach ($comment->files as $file) {
                            $link = downloadFileIfHostedAtPodio($path_item, $file);
                            # $link is relative to $path_item (if downloaded):
                            if (!preg_match("/^http/i", $link)) {
                                $link = RelativePaths::getRelativePath($path_app, $path_item . '/' . $link);
                            }
                            $commentsFile .= "File: {$link}\n";
                            $files_in_app_html .= "<tr><td>" . $file->name . "</td><td><a href=\"" . $link . "\">" . $link . "</a></td><td>" . $file->context['title'] . "</td></tr>";
                        }
                    }
                }
            } else {
                $commentsFile = "\n\n[no comments]\n";
                #echo "no comments.. (".$item->comment_count.")\n";
            }
            file_put_contents($path_item . '/' . fixDirName($item->item_id . '-' . $item->title) . '.txt', $itemFile . $commentsFile);
            $appFile .= $itemFile . "\n\n";
        }
        //store non item/comment files:
        if ($verbose) {
            echo "storing non item/comment files..\n";
        }
        $app_files_folder = 'other_files';
        $path_app_files = $path_app . '/' . $app_files_folder;
        mkdir($path_app_files);
        $files_in_app_html .= "<tr><td><b>App Files</b></td><td><a href={$app_files_folder}>" . $app_files_folder . "</a></td><td></td></tr>";
        foreach ($appFiles as $file) {
            if ($file->context['type'] != 'item' && $file->context['type'] != 'comment') {
                echo "debug: downloading non item/comment file: {$file->name}\n";
                $link = downloadFileIfHostedAtPodio($path_app_files, $file);
                # $link is relative to $path_item (if downloaded):
                if (!preg_match("/^http/i", $link)) {
                    $link = RelativePaths::getRelativePath($path_app, $path_item . '/' . $link);
                }
                $files_in_app_html .= "<tr><td>" . $file->name . "</td><td><a href=\"" . $link . "\">" . $link . "</a></td><td>" . $file->context['title'] . "</td></tr>";
            }
        }
    } catch (PodioError $e) {
        show_error($e);
        $appFile .= "\n\nPodio Error:\n" . $e;
    }
    file_put_contents($path_app . '/all_items_summary.txt', $appFile);
    $files_in_app_html .= "</table></body></html>";
    file_put_contents($path_app . "/files_in_app.html", $files_in_app_html);
    unset($appFile);
    unset($files_in_app_html);
}
Example #5
0
require 'vendor/autoload.php';
require_once 'app_setting.inc.php';
use ZendService\LiveDocx\MailMerge;
error_log("validate triggerd");
// Setup client
Podio::setup($client_id, $client_secret);
// Turn on debugging
Podio::$debug = true;
// Authenticate the app
Podio::authenticate('app', array('app_id' => $app_id, 'app_token' => $app_token));
switch ($_POST['type']) {
    case 'hook.verify':
        // Validate the webhook
        PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code']));
    case 'item.create':
        $item = PodioItem::get($_POST['item_id']);
        $temp_array = array();
        foreach ($item->files as $fs) {
            $temp_array[] = $fs;
            if ($fs->mimetype == 'application/msword') {
                //Get file name withour ext
                $no_ext = substr($fs->name, 0, strpos($fs->name, '.'));
                //Upload file to our server
                $fl = PodioFile::get($fs->file_id);
                $fc = $fl->get_raw();
                file_put_contents($upload_path . $fs->name, $fc);
                //Part with convert files from doc(x) to pdf
                $mailMerge = new MailMerge();
                $mailMerge->setUsername($user)->setPassword($password)->setService(MailMerge::SERVICE_FREE);
                $mailMerge->setLocalTemplate($upload_path . $fs->name);
                $mailMerge->assign('software', 'Magic Graphical Compression Suite v1.9');
// loads. The goal to avoid having to re-authenticate each time
// a page is refreshed. It is enabled by default.
// If you open lib/PodioSession.php you can see how simple the
// session manager is. It just has get, set and destroy methods.
// You can use the Podio::is_authenticated() method to check if
// there is a stored access token already present:
Podio::setup(CLIENT_ID, CLIENT_SECRET);
if (Podio::is_authenticated()) {
    // There is already authentication present. We can make API
    // calls without authenticating again:
    $item = PodioItem::get(YOUR_ITEM_ID);
} else {
    // No authentication present. We have to authentication
    // before making API calls:
    Podio::authenticate('app', array('app_id' => YOUR_APP_ID, 'app_token' => YOUR_APP_TOKEN));
    $item = PodioItem::get(YOUR_ITEM_ID);
}
// The downside of the built-in session manager is that it just
// stores the access tokens in the $_SESSION. This means that you
// will have to re-authenticate a user each time their close their browser
// Often you will want to persist the access tokens for a longer period.
// To do so you can implement your own session manager. All you need
// is to create a class that implements the same get, set and destroy methods.
// Then you can store the access tokens in your database or whereever.
// When doing the client setup all you need to pass in the name of your session manager
// class as an option and it will be used instead of the built-in one.
// For example if your session manager class is called 'MySessionManager'
Podio::setup(CLIENT_ID, CLIENT_SECRET, array('session_manager' => 'MySessionManager'));
// If the built-in session manager is causing you trouble you can disable it.
// This can be useful during development to make sure no stale access tokens are stored.
Podio::setup(CLIENT_ID, CLIENT_SECRET, array());
Example #7
0
        echo "</a>";
    }
    echo "</div>";
    echo "</div>";
}
?>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-md-6">
					<h1>Podio</h1>
					<?php 
Podio::setup($config['podio']['client-id'], $config['podio']['client-secret']);
Podio::authenticate_with_app($config['podio']['ww-app-id'], $config['podio']['ww-app-secret']);
$ww = PodioItem::filter($config['podio']['ww-app-id']);
foreach ($ww as $week) {
    if ($week->title == 'Jake Neumann') {
        $week_start = $week->fields['1']->values['start'];
        if (time() - 60 * 60 * 24 * 7 < strtotime($week_start->format('Y-m-d H:i:s'))) {
            // var_dump( $week->fields );
            foreach ((array) $week->fields as $week) {
                foreach ((array) $week as $day) {
                    if (is_object($day) && $day->type == 'app') {
                        echo '<h4>' . $day->label . '</h4>';
                        foreach ($day->values as $proj) {
                            echo '<a href="' . $proj->link . '" target="_blank">';
                            echo $proj->title;
                            echo '</a>';
                            echo '<br />';
                        }
Example #8
0
 public static function addAllProjectsToArray()
 {
     $category_status_id = 62473690;
     //filtering by client name here
     //1 , 2, 3, 6, 7, 8, 9, 10, 11, 14
     $planning_collection = PodioItem::filter(APP_ID, array('filters' => array($category_status_id => array(1, 2, 3, 7, 8, 9, 10, 11, 14)), 'limit' => 200, 'sort_by' => 'created_on'));
     foreach ($planning_collection as $item) {
         //Add one to global variable each time to $project_count
         global $active_project_count;
         //the the global keyword to reference global scope
         global $start_day_array;
         global $start_month_array;
         global $start_year_array;
         global $due_day_array;
         global $due_month_array;
         global $due_year_array;
         global $title_array;
         global $client_array;
         global $job_number_array;
         global $id_array;
         $active_project_count += 1;
         array_push($start_day_array, intval(date_format($item->created_on, 'd')));
         //Maybe try intval(variablehere);
         array_push($start_month_array, intval(date_format($item->created_on, 'm')) - 1);
         //Subtracting 1 from month for some reason its off ... strange
         array_push($start_year_array, intval(date_format($item->created_on, 'Y')));
         //Maybe try intval(variablehere);
         //Add the values to the DUE DAY array's
         $due_date = $item->fields["due-date"];
         //get the due date by external id as object
         //$due_date = $item->fields["start-date"]; //get the due date by external id as object
         $blah = 0;
         $due_date->start != null ? $blah = intval(date_format($due_date->start, 'd')) : ($blah = intval(date('d')));
         array_push($due_day_array, $due_date->start == null ? intval(date('d')) : intval(date_format($due_date->start, 'd')));
         //TODO ask about default due and start days if they are null
         array_push($due_month_array, $due_date->start == null ? intval(date('m')) : intval(date_format($due_date->start, 'm')));
         array_push($due_year_array, $due_date->start == null ? intval(date('Y')) : intval(date_format($due_date->start, 'Y')));
         //TITLE
         array_push($title_array, ucfirst(strtolower($item->title)));
         //JOB NUMBER
         $job = $item->fields["job"];
         array_push($job_number_array, (double) $job->values);
         //CLIENT NAME ARRAY
         $client_name = $item->fields["client"];
         array_push($client_array, $client_name);
         //ID ARRAY
         array_push($id_array, $item->id);
     }
 }
// The total amount of items in the app
print $item_collection['filtered'];
// Number of items matching the current filter
print_r($item_collection['items']);
// Array of PodioItem instances
// PodioItem::filter is very powerful. You can filter and sort on almost any field. See all the details on https://developers.podio.com/doc/filters
// If you have a money field with a field_id of '1234' and you want to get all items in the app where the value is between 100 and 200:
$item_collection = PodioItem::filter(YOUR_APP_ID, array('filters' => array(1234 => array('from' => 100, 'to' => 200))));
// The following field types use the 'from' / 'to' format for filtering: number, money, calculation, progress, duration, date
// With other fields -- category, app reference, contact, question -- you provide an array of ids to match. E.g. if you want to get a collection of items where the app reference field with the field_id 5678 only matches items referencing items with the item_ids 1, 2 and 3:
$item_collection = PodioItem::filter(YOUR_APP_ID, array('filters' => array(5678 => array(1, 2, 3))));
// You can set sorting options and limit and offset values also. E.g. getting the 100 first items, sorted by their last edit date:
$item_collection = PodioItem::filter(YOUR_APP_ID, array('sort_by' => 'last_edit_on', 'sort_desc' => true, 'limit' => 100, 'offset' => 0));
// It's also doable to create new items from scratch (useful if you are migrating data from another system).
// Create the base item. Notice how you have to create a PodioApp instance. This is so we know what app to store the item in.
$item = new PodioItem(array('app' => new PodioApp(YOUR_APP_ID), 'fields' => array(), 'external_id' => 'my-legacy-id-number'));
// We can add some fields to the item:
$item->fields = array(new PodioTextItemField('title'), new PodioImageItemField('image-field'));
// Or you can use add_field and remove_field methods to add/remove fields one at a time:
$item->add_field(new PodioNumberItemField('number-field'));
// Field object must have a field_id or an external_id
$item->remove_field('number-field');
// Remove by field_id or external_id
// Notice how the external_id of the fields is being passed as the first argument to the constructor? When you create new instances of any of the Podio objects you can send three things to the constructor:
// 1. An associative array of properties. Like we did above when creating the item.
// 2. A string representing the external_id you want to set. Like we did for the PodioItemFields just above
// 3. An id value. Like we did for the PodioApp we attached to the PodioItem above.
// Give the fields values:
$item->field('title')->set_value('My title');
$item->field('image-field')->set_value(array(1, 2, 3));
// It is slightly cumbersome to first create the PodioItemFields and afterwards set the value for each one. You can set the values directly when creating the instances if you wish, but since the format is different for each field type it's often easier to call 'set_value' and have the formatting handled automatically.
Example #10
0
$file = __DIR__ . "/webhook.log";
//  authenticate
Podio::authenticate_with_app($config['app_id'], $config['app_token']);
// Big switch statement to handle the different events
switch ($_POST['type']) {
    // Validate the webhook. This is a special case where we verify newly created webhooks.
    case 'hook.verify':
        PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code']));
        // An item was created
    // An item was created
    case 'item.create':
        $string = gmdate('Y-m-d H:i:s') . " item.create webhook received. ";
        $string .= "Post params: " . print_r($_POST, true) . "\n";
        $item_id = (int) $_POST['item_id'];
        // get item
        $item = PodioItem::get($item_id);
        $item_file = $item->files[0];
        $file = PodioFile::get($item_file->file_id);
        $mimetype = $file->mimetype;
        // validate mime and get reader
        $reader_name = $controller->getReaderByMime($mimetype);
        if ($reader_name) {
            file_put_contents(__DIR__ . '/temp/' . $item_file->name, $file->get_raw());
            $file_name_exploded = explode('.', $item_file->name);
            $file_name_no_ext = $file_name_exploded[0];
            $controller->init_pdf_renderer();
            \PhpOffice\PhpWord\Autoloader::register();
            // Creating the new document...
            $phpWord = new \PhpOffice\PhpWord\PhpWord();
            // Read contents
            $source = __DIR__ . '/temp/' . $item_file->name;