コード例 #1
0
 public function doValidate($validator, $values)
 {
     if ($values['id']) {
         $plugin = PluginPeer::retrieveByPk($values['id']);
         if (!sfContext::getInstance()->getUser()->ownsPlugin($plugin)) {
             throw new sfValidatorError($validator, 'You don\'t own the plugin you\'re trying to edit');
         }
     }
     if (substr_count($values['repository'], '.git') > 0) {
         $values['repository'] = substr($values['repository'], 0, strrpos($values['repository'], '.'));
     }
     $tags = GitHubFetcher::fetchContent(sprintf('/repos/%s/%s/tags', $values['user'], $values['repository']));
     if (($tagsArr = @json_decode($tags)) !== null) {
         foreach ((array) $tagsArr as $tag) {
             $this->gitTags[] = $tag->name;
         }
         usort($this->gitTags, 'version_compare');
     } else {
         throw new sfValidatorError($validator, 'Bad GitHub response. Try again later.');
     }
     if (empty($this->gitTags)) {
         throw new sfValidatorError($validator, 'GitHub repository has no tags. At least one tag is required.');
     }
     return $values;
 }
コード例 #2
0
ファイル: index.php プロジェクト: dapepe/tymio
function registerPluginEvents($pluginEvents)
{
    foreach ($pluginEvents as $entity => $events) {
        foreach ($events as $event) {
            PluginPeer::registerEvent($entity, $event);
        }
    }
}
コード例 #3
0
 public function executeDownload(sfWebRequest $request)
 {
     $project = PluginPeer::retrieveBySlug($request->getParameter('project'));
     $this->forward404Unless($project);
     $tag = $project->getGitTagByName($request->getParameter('tag'));
     $this->forward404Unless($tag);
     $project->sumDownload();
     $tag->sumDownload();
     header('Location: ' . $tag->getDownloadLink());
     exit;
 }
コード例 #4
0
 public function executeRecent(sfWebRequest $request)
 {
     $feed = $this->getFeed($request->getParameter('format'));
     $c = new Criteria();
     $c->addDescendingOrderByColumn(PluginPeer::CREATED_AT);
     $c->setLimit(20);
     $plugins = PluginPeer::doSelect($c);
     foreach ((array) $plugins as $plugin) {
         $item = new sfFeedItem();
         $item->setTitle($plugin->getTitle());
         $item->setLink('@plugin?slug=' . $plugin->getSlug());
         $item->setAuthorName($plugin->getAuthor()->getFullName());
         $item->setPubdate($plugin->getCreatedAt('U'));
         $item->setUniqueId($plugin->getSlug());
         $item->setContent($plugin->getDescription());
         $feed->addItem($item);
     }
     $this->feed = $feed;
 }
コード例 #5
0
 public function doValidate($validator, $values)
 {
     if ($values['id']) {
         $plugin = PluginPeer::retrieveByPk($values['id']);
         if (!sfContext::getInstance()->getUser()->ownsPlugin($plugin)) {
             throw new sfValidatorError($validator, 'You don\'t own the plugin you\'re trying to edit');
         }
     }
     $tags = $this->fetch(sprintf('http://github.com/api/v2/json/repos/show/%s/%s/tags', $values['user'], $values['repository']));
     if ($tagsArr = @json_decode($tags)) {
         $this->gitTags = array_keys((array) $tagsArr->tags);
         usort($this->gitTags, 'version_compare');
     } else {
         throw new sfValidatorError($validator, 'Bad GitHub response. Try again later.');
     }
     if (empty($this->gitTags)) {
         throw new sfValidatorError($validator, 'GitHub repository has no tags. At least one tag is required.');
     }
     return $values;
 }
 protected function doClean($values)
 {
     if (is_null($values)) {
         $values = array();
     }
     if (!is_array($values)) {
         throw new InvalidArgumentException('You must pass an array parameter to the clean() method');
     }
     $errors = array();
     $deps = isset($values[$this->getOption('dependencies_field')]) ? $values[$this->getOption('dependencies_field')] : array();
     if (!empty($deps)) {
         foreach ($deps as $i => $dep) {
             if (!isset($dep['package']) || !$dep['package']) {
                 $errors[] = new sfValidatorError($this, 'no_package');
             } else {
                 if (!ForgeToolkit::isUrl($dep['package'])) {
                     if (!isset($dep['version']) || !$dep['version']) {
                         $errors[] = new sfValidatorError($this, 'missing_tag', array('value' => $results[3]));
                     }
                     $plugin = PluginPeer::retrieveBySlug($results[3]);
                     if ($plugin) {
                         if ($tag = $plugin->getGitTagByName($dep['tag'])) {
                             $values[$i]['plugin_tag_id'] = $tag->getId();
                             $errors[] = new sfValidatorError($this, 'tag_not_found', array('plugin' => $results[3], 'value' => $dep['tag']));
                         }
                     } else {
                         $errors[] = new sfValidatorError($this, 'plugin_not_found', array('value' => $dep['package']));
                     }
                 } else {
                     $values[$i]['external'] = true;
                     $values[$i]['url'] = $dep['package'];
                     $values[$i]['title'] = ForgeToolkit::retrieveTitleFromURL($dep['package']);
                 }
             }
         }
     }
     if (!empty($errors)) {
         throw new sfValidatorErrorSchema($this, $errors);
     }
     return $values;
 }
コード例 #7
0
ファイル: domain.php プロジェクト: dapepe/tymio
<?php

// Register Plugin-Events
PluginPeer::registerEvent('domain', 'create');
PluginPeer::registerEvent('domain', 'modify');
PluginPeer::registerEvent('domain', 'remove');
PluginPeer::registerEvent('domain', 'restore');
/**
 * API functions to manage DOMAINS
 *
 * @author Peter-Christoph Haider (Project Leader) et al.
 * @package ZfxSupport
 * @version 1.1 (2012-01-17)
 * @copyright Copyright (c) 2012, Groupion GmbH & Co. KG
 */
class DomainAPI extends API
{
    /**
     * @var array An associative array mapping actions to their definitions.
     *     Action format:    { <name> => [ <method>, <function>, <parameters> ] }
     *       Methods:        POST, GET, REQUEST
     *     Parameter format: [ <name>, <type>, <default> = '', <required> = true ]
     *       Types:          int, float, bool, array, object, string
     */
    public $actions = array('list' => array('ANY', 'list', array(array('search', 'string', null, false), array('showdeleted', 'bool', false, false), array('orderby', 'string', false, false), array('ordermode', 'string', false, false))), 'details' => array('ANY', 'details', array(array('id', 'int', null))), 'add' => array('POST', 'add', array(array('data', 'array', null))), 'update' => array('POST', 'update', array(array('id', 'int', null), array('data', 'array', null))), 'restore' => array('POST', 'restore', array(array('id', 'int', null))), 'remove' => array('POST', 'remove', array(array('id', 'int', null))));
    public $auth_exceptions = array();
    /** @var array Basic filter settings */
    public $filter_basic = array('Name' => array('filter' => FILTER_VALIDATE_MIN_LENGTH, 'len' => 2, 'field' => 'entity.domain.singular'));
    /** @var array Filter settings for domain properties */
    public $filter_properties = array();
    /**
コード例 #8
0
 /**
  * Delete a plugin
  *
  * @author Guillermo Rauch
  **/
 public function executeDelete(sfWebRequest $request)
 {
     $this->plugin = PluginPeer::retrieveBySlug($request->getParameter('slug'));
     $this->plugin->delete();
     $this->redirect('@homepage');
 }
コード例 #9
0
ファイル: user.php プロジェクト: dapepe/tymio
<?php

// Register Plugin-Events
PluginPeer::registerEvent('user', 'create');
PluginPeer::registerEvent('user', 'modify');
PluginPeer::registerEvent('user', 'remove');
PluginPeer::registerEvent('user', 'restore');
/**
 * API functions to manage USERS
 *
 * @author Peter-Christoph Haider (Project Leader) et al.
 * @package ZfxSupport
 * @version 1.1 (2012-01-17)
 * @copyright Copyright (c) 2012, Groupion GmbH & Co. KG
 */
class UserAPI extends API
{
    /**
     * @var array An associative array mapping actions to their definitions.
     *     Action format:    { <name> => [ <method>, <function>, <parameters> ] }
     *       Methods:        POST, GET, REQUEST
     *     Parameter format: [ <name>, <type>, <default> = '', <required> = true ]
     *       Types:          int, float, bool, array, object, string
     */
    public $actions = array('auth' => array('ANY', 'auth', array(array('username', 'string', false), array('password', 'string', false), array('session', 'bool', false, false), array('cookie', 'bool', false, false))), 'session' => array('ANY', 'session', array()), 'list' => array('ANY', 'list', array(array('search', 'string', null, false), array('domain', 'int', null, false), array('showdeleted', 'bool', false, false), array('orderby', 'string', null, false), array('ordermode', 'string', null, false))), 'details' => array('ANY', 'details', array(array('id', 'string', null, false), array('allowpeers', 'bool', false, false))), 'add' => array('ANY', 'add', array(array('data', 'array', null))), 'update' => array('ANY', 'update', array(array('id', 'int', null), array('data', 'array', null))), 'set_pwd' => array('ANY', 'set_pwd', array(array('id', 'int', null, false), array('new_password', 'string', null))), 'restore' => array('ANY', 'restore', array(array('id', 'int', null))), 'remove' => array('ANY', 'remove', array(array('id', 'int', null))));
    public $auth_exceptions = array('auth');
    /** @var array Basic filter settings */
    public $filter_basic = array('Name' => array('filter' => FILTER_VALIDATE_USERNAME_CHARS, 'field' => 'field.username'), 'DomainId' => array('filter' => FILTER_VALIDATE_INT, 'field' => 'entity.domain.singular', 'message' => 'error.not_set'), 'Firstname' => array('filter' => FILTER_VALIDATE_MIN_LENGTH, 'len' => 2, 'field' => 'field.firstname'), 'Lastname' => array('filter' => FILTER_VALIDATE_MIN_LENGTH, 'len' => 2, 'field' => 'field.lastname'), 'Password' => array('filter' => FILTER_VALIDATE_PASSWORD), 'Email' => array('filter' => FILTER_VALIDATE_EMAIL));
    /** @var array Filter settings for user properties */
    public $filter_properties = array('HoursPerWeek' => array('filter' => FILTER_VALIDATE_INT, 'field' => 'entity.hours_per_week'));
    /**
コード例 #10
0
ファイル: transaction.php プロジェクト: dapepe/tymio
 /**
  * Creates transactions from clockings.
  *
  * Plugin event "transaction.add" data:
  * - "user": { ... }      // The user object
  * - "clockings": [ ... ]
  * - "booking_types": { identifier: {...}, ... }
  * - "bookings": {}        // Receives the bookings to be created
  * - "transactions": {}    // Receives the transactions to be created
  *
  * @param array $clockingIds
  * @param bool $commit Optional. If FALSE, only data about the transaction
  *     will be returned without saving them to the database. That data can
  *     be used to manually create a transaction.
  *     Default is TRUE.
  * @return array An array with IDs of clocking that have been booked.
  * @throws Exception
  */
 public function do_add(array $clockingIds, $commit = true)
 {
     if (empty($clockingIds)) {
         throw new Exception('No clockings specified.');
     }
     $usedClockingIds = array();
     // Return value for $commit == FALSE:
     // An associative array mapping user IDs to associative arrays with the
     // items "bookings" and "transactions":
     // {
     //     [user-id-1]: {
     //         "bookings"    : {
     //             [ref-1]   : { ... }
     //         },
     //         "transactions": [
     //         ]
     //     }
     // }
     $resultData = array();
     $con = Propel::getConnection();
     if (!$con->beginTransaction()) {
         throw new Exception('Could not start transaction.');
     }
     try {
         $authUser = $this->requireUser();
         $authUserId = $authUser->getId();
         $isAdmin = $authUser->isAdmin();
         if (!$isAdmin) {
             throw new Exception('Non-administrative user "' . $authUser->getFQN($con) . '" cannot create transactions.');
         }
         $clockings = ClockingAPI::createClockingQuery($authUser, $con)->joinWith('Domain.Account')->joinWith('ClockingType')->filterById($clockingIds, Criteria::IN)->addAscendingOrderByColumn(ClockingPeer::START)->addAscendingOrderByColumn(ClockingPeer::END)->addAscendingOrderByColumn(ClockingTypePeer::IDENTIFIER)->addAscendingOrderByColumn(ClockingPeer::ID)->find($con);
         // Check for missing clockings
         $missingIds = array_diff_key(array_fill_keys($clockingIds, true), $clockings->getArrayCopy('Id'));
         if (!empty($missingIds)) {
             throw new Exception('Could not find clockings with the IDs ' . implode(', ', $missingIds) . '.');
         }
         // Lock clocking records by writing to them
         $this->freezeClockings(true, $clockings, $con);
         // Group clockings by user
         $clockingDataByUserId = array();
         foreach ($clockings as $clocking) {
             $clockingDataByUserId[$clocking->getUserId()][] = EntityArray::from($clocking) + array('Type' => EntityArray::from($clocking->getClockingType()));
         }
         $typeDataByAccount = array();
         foreach ($clockingDataByUserId as $userId => $userClockingData) {
             $user = UserQuery::create()->findPk($userId, $con);
             $userData = array_diff_key($user->toArray(), array('PasswordHash' => true));
             $account = $user->getAccount($con);
             $accountId = $account->getId();
             if (isset($typeDataByAccount[$accountId])) {
                 list($typesById, $typeData) = $typeDataByAccount[$accountId];
             } else {
                 $types = BookingTypeQuery::create()->findByAccountId($account->getId(), $con);
                 $typesById = $types->getArrayCopy('Id');
                 $typeData = $types->toArray('Identifier');
                 $typeDataByAccount[$accountId] = array($typesById, $typeData);
             }
             $data = PluginPeer::fireEvent($authUser, 'transaction', 'add', array('user' => $userData, 'clockings' => $userClockingData, 'booking_types' => $typeData, 'bookings' => array(), 'transactions' => array()), $con);
             if (!isset($data['bookings'])) {
                 $data['bookings'] = array();
             }
             if (empty($data['transactions'])) {
                 // Ignore if there are no bookings either, otherwise fail
                 if (!empty($data['bookings']) and is_array($data['bookings'])) {
                     throw new Exception('Plugins created ' . count($data['bookings']) . ' booking(s) not linked to any transactions.');
                 }
             } elseif (!is_array($data['bookings']) or !is_array($data['transactions'])) {
                 throw new Exception('Plugins must return array data in variables "bookings" and "transactions".');
             } else {
                 // Create bookings and transactions
                 list($userClockingIds, $transactions) = $this->createBookingsTransactions($authUser, $user, $data['bookings'], $typesById, $data['transactions'], $con);
                 $usedClockingIds += $userClockingIds;
                 $resultData[$userId] = array('bookings' => array(), 'transactions' => EntityArray::from($transactions, $con));
             }
         }
         $this->freezeClockings(false, $clockings, $con);
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
     if (!$commit) {
         $con->rollBack();
         return $resultData;
     }
     if (!$con->commit()) {
         throw new Exception('Could not commit transaction.');
     }
     return array_keys($usedClockingIds);
 }
コード例 #11
0
ファイル: cronjob.php プロジェクト: dapepe/tymio
<?php

require_once dirname(__FILE__) . '/../lib/tymio/common.php';
// Run timed plugins if either their last execution time is further in the past
// than their specified execution interval or where the time of day minus the
// start time offset is a divisor of the interval.
$now = time();
$timeOfDay = $now - strtotime('0:00', $now);
$query = new PluginQuery();
$plugins = $query->filterByActive(0, Criteria::NOT_EQUAL)->filterByEntity(PluginPeer::ENTITY_SYSTEM)->filterByEvent(PluginPeer::EVENT_TIMED)->add($query->getNewCriterion(PluginPeer::LAST_EXECUTION_TIME, '(' . $now . ' - ' . PluginPeer::LAST_EXECUTION_TIME . ' > ' . PluginPeer::INTERVAL . ')', Criteria::CUSTOM)->addOr($query->getNewCriterion(PluginPeer::START, '((86400 + ' . $timeOfDay . ' - ' . PluginPeer::START . ') % 86400 % ' . PluginPeer::INTERVAL . ' BETWEEN 0 AND 59)', Criteria::CUSTOM)->addAnd($query->getNewCriterion(PluginPeer::LAST_EXECUTION_TIME, '(' . $now . ' - ' . PluginPeer::LAST_EXECUTION_TIME . ' > 60)', Criteria::CUSTOM))))->addAscendingOrderByColumn(PluginPeer::LAST_EXECUTION_TIME)->addAscendingOrderByColumn(PluginPeer::PRIORITY)->find();
$parameters = PluginPeer::buildParameters(PluginPeer::ENTITY_SYSTEM, PluginPeer::EVENT_TIMED);
foreach ($plugins as $plugin) {
    try {
        error_log('Plugin #' . $plugin->getId() . ' ' . $plugin->getIdentifier() . ', last exec time ' . ($now - $plugin->getLastExecutionTime()) . ', time of day ' . $timeOfDay . ', interval ' . $plugin->getInterval() . ' => ' . (86400 + $timeOfDay - $plugin->getStart()) % 86400 % $plugin->getInterval());
        $sandbox = $plugin->execute(null, $parameters);
        $plugin->setLastExecutionTime($now)->save();
        $exception = $sandbox->getException();
        if ($exception !== null) {
            throw $exception;
        }
    } catch (Exception $e) {
        echo 'Plugin #' . $plugin->getId() . ' ' . $plugin->getIdentifier() . ': ' . $e->getMessage() . "\n";
    }
}
コード例 #12
0
 /**
  * Selects a collection of ProductPlugin objects pre-filled with all related objects except Product.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return array           Array of ProductPlugin objects.
  * @throws PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAllExceptProduct(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     // $criteria->getDbName() will return the same object if not set to another value
     // so == check is okay and faster
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(ProductPluginPeer::DATABASE_NAME);
     }
     ProductPluginPeer::addSelectColumns($criteria);
     $startcol2 = ProductPluginPeer::NUM_HYDRATE_COLUMNS;
     PluginPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + PluginPeer::NUM_HYDRATE_COLUMNS;
     $criteria->addJoin(ProductPluginPeer::PLUGIN_ID, PluginPeer::ID, $join_behavior);
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = ProductPluginPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = ProductPluginPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://www.propelorm.org/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = ProductPluginPeer::getOMClass();
             $obj1 = new $cls();
             $obj1->hydrate($row);
             ProductPluginPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined Plugin rows
         $key2 = PluginPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = PluginPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = PluginPeer::getOMClass();
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 PluginPeer::addInstanceToPool($obj2, $key2);
             }
             // if $obj2 already loaded
             // Add the $obj1 (ProductPlugin) to the collection in $obj2 (Plugin)
             $obj2->addProductPlugin($obj1);
         }
         // if joined row is not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
コード例 #13
0
ファイル: clocking.php プロジェクト: dapepe/tymio
 /**
  * Removes a clocking entry
  *
  * @param int $id The clocking ID
  */
 public function do_remove($id)
 {
     $con = Propel::getConnection();
     if (!$con->beginTransaction()) {
         throw new Exception('Could not start transaction.');
     }
     try {
         $authUser = $this->requireUser($con);
         $clocking = $this->getClockingById($id, $con);
         if ($clocking->getBooked()) {
             throw new Exception('Cannot remove clocking entry #' . $id . ' because it already has bookings. Please remove the transactions instead.');
         }
         if (!$clocking->isOpen() and !$authUser->isAdmin()) {
             $account = $authUser->getAccount($con);
             if ($account === null) {
                 throw new Exception('Could not get account of user #' . $authUser->getId() . ' "' . $authUser->getFQN($con) . '".');
             }
             $type = $clocking->getClockingType($con);
             if ($type === null) {
                 throw new Exception('Could not get clocking type with ID #' . $clocking->getTypeId() . '.');
             }
             $this->validateTimeLimits($account, $authUser, $clocking, $con);
         }
         $clockingUser = $clocking->getUserRelatedByUserId($con);
         if ($clockingUser === null) {
             throw new Exception('Could not determine clocking\'s assigned user #' . $clocking->getUserId() . '.');
         }
         PluginPeer::fireEvent($clockingUser, 'clocking', 'remove', EntityArray::from($clocking, $con), $con);
         $clocking->setDeleted(1)->save($con);
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
     if (!$con->commit()) {
         throw new Exception('Could not commit transaction.');
     }
     return true;
 }
コード例 #14
0
ファイル: BasePlugin.php プロジェクト: Halfnhav4/datawrapper
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's BasePeer::TYPE_PHPNAME
  *
  * @param array  $arr     An array to populate the object from.
  * @param string $keyType The type of keys the array uses.
  * @return void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PluginPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setInstalledAt($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setEnabled($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setIsPrivate($arr[$keys[3]]);
     }
 }
コード例 #15
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return    Plugin A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `ID`, `INSTALLED_AT`, `ENABLED` FROM `plugin` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_STR);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new Plugin();
         $obj->hydrate($row);
         PluginPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
コード例 #16
0
ファイル: plugin.php プロジェクト: dapepe/tymio
 /**
  * List all events for an entity
  *
  * @param string $entityName Filter by event
  * @param string $search Search string
  */
 public function do_list_events($entityName = false, $search = false)
 {
     return PluginPeer::listEvents($entityName);
 }
コード例 #17
0
ファイル: BaseAccountPeer.php プロジェクト: dapepe/tymio
 /**
  * This is a method for emulating ON DELETE CASCADE for DBs that don't support this
  * feature (like MySQL or SQLite).
  *
  * This method is not very speedy because it must perform a query first to get
  * the implicated records and then perform the deletes by calling those Peer classes.
  *
  * This method should be used within a transaction if possible.
  *
  * @param      Criteria $criteria
  * @param      PropelPDO $con
  * @return int The number of affected rows (if supported by underlying database driver).
  */
 protected static function doOnDeleteCascade(Criteria $criteria, PropelPDO $con)
 {
     // initialize var to track total num of affected rows
     $affectedRows = 0;
     // first find the objects that are implicated by the $criteria
     $objects = AccountPeer::doSelect($criteria, $con);
     foreach ($objects as $obj) {
         // delete related BookingType objects
         $criteria = new Criteria(BookingTypePeer::DATABASE_NAME);
         $criteria->add(BookingTypePeer::ACCOUNT_ID, $obj->getId());
         $affectedRows += BookingTypePeer::doDelete($criteria, $con);
         // delete related ClockingType objects
         $criteria = new Criteria(ClockingTypePeer::DATABASE_NAME);
         $criteria->add(ClockingTypePeer::ACCOUNT_ID, $obj->getId());
         $affectedRows += ClockingTypePeer::doDelete($criteria, $con);
         // delete related Domain objects
         $criteria = new Criteria(DomainPeer::DATABASE_NAME);
         $criteria->add(DomainPeer::ACCOUNT_ID, $obj->getId());
         $affectedRows += DomainPeer::doDelete($criteria, $con);
         // delete related Holiday objects
         $criteria = new Criteria(HolidayPeer::DATABASE_NAME);
         $criteria->add(HolidayPeer::ACCOUNT_ID, $obj->getId());
         $affectedRows += HolidayPeer::doDelete($criteria, $con);
         // delete related Plugin objects
         $criteria = new Criteria(PluginPeer::DATABASE_NAME);
         $criteria->add(PluginPeer::ACCOUNT_ID, $obj->getId());
         $affectedRows += PluginPeer::doDelete($criteria, $con);
         // delete related Property objects
         $criteria = new Criteria(PropertyPeer::DATABASE_NAME);
         $criteria->add(PropertyPeer::ACCOUNT_ID, $obj->getId());
         $affectedRows += PropertyPeer::doDelete($criteria, $con);
         // delete related User objects
         $criteria = new Criteria(UserPeer::DATABASE_NAME);
         $criteria->add(UserPeer::ACCOUNT_ID, $obj->getId());
         $affectedRows += UserPeer::doDelete($criteria, $con);
     }
     return $affectedRows;
 }
コード例 #18
0
ファイル: holiday.php プロジェクト: dapepe/tymio
<?php

// Register Plugin-Events
PluginPeer::registerEvent('holiday', 'create');
PluginPeer::registerEvent('holiday', 'modify');
PluginPeer::registerEvent('holiday', 'remove');
/**
 * API functions to manage HOLIDAYS
 *
 * @author Peter-Christoph Haider (Project Leader) et al.
 * @package ZfxSupport
 * @version 1.1 (2012-01-17)
 * @copyright Copyright (c) 2012, Groupion GmbH & Co. KG
 */
class HolidayAPI extends API
{
    public $actions = array('list' => array('ANY', 'list', array(array('search', 'string', null, false), array('start', 'int', null, false), array('end', 'int', null, false), array('domain', 'int', null, false), array('orderby', 'string', null, false), array('ordermode', 'string', null, false))), 'details' => array('ANY', 'details', array(array('id', 'int', null))), 'add' => array('ANY', 'add', array(array('data', 'array', null))), 'update' => array('ANY', 'update', array(array('id', 'int', null), array('data', 'array', null))), 'erase' => array('ANY', 'erase', array(array('id', 'int', null))));
    public $auth_exceptions = array('auth');
    /** @var array Basic filter settings */
    public $filter_basic = array('Name' => array('filter' => FILTER_VALIDATE_MIN_LENGTH, 'len' => 2, 'field' => 'field.name'), 'Date' => array('filter' => FILTER_VALIDATE_INT, 'message' => 'not_a_date', 'field' => 'field.start'));
    /**
     * User or token authentication
     *
     * @see API::auth()
     * @return bool
     */
    public function auth()
    {
        if ($this->authUser()) {
            return true;
        }
コード例 #19
0
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(PluginPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(PluginPeer::DATABASE_NAME);
         $criteria->add(PluginPeer::ID, $pks, Criteria::IN);
         $objs = PluginPeer::doSelect($criteria, $con);
     }
     return $objs;
 }
コード例 #20
0
 public function doValidate($validator, $values)
 {
     foreach ((array) $values['files'] as $file) {
         try {
             $parser = new ForgeJSParser(file_get_contents($file));
         } catch (ForgeJSParserException $e) {
             throw new sfValidatorError($validator, $e->getMessage() . sprintf(' (%s)', basename($file)));
         }
         $data = $parser->getData();
         // check for *presence* of required fields
         $requiredFields = array('provides', 'authors');
         foreach ($requiredFields as $required) {
             if (!isset($data[$required])) {
                 throw new sfValidatorError($validator, sprintf('`%s` field missing or empty in %s', $required, basename($file)));
             }
         }
         // check for well formed dependencies
         if (isset($data['requires'])) {
             if (!is_array($data['requires'])) {
                 $data['requires'] = array($data['requires']);
             }
             foreach ($data['requires'] as $a => $b) {
                 if (is_string($b) && preg_match('/([^:]+):([^\\/]*)\\/(.+)/', $b, $match)) {
                     $pluginName = $match[0];
                     $version = $match[1];
                     $b = $match[2];
                 } else {
                     if (strstr($a, '/') || strstr($a, ':')) {
                         $pieces = explode(strstr($a, '/') ? '/' : ':', $a);
                         $pluginName = $pieces[0];
                         $version = $pieces[1];
                     } else {
                         if (is_numeric($a)) {
                             $pluginName = '_self_';
                             $version = '_current_';
                         } else {
                             throw new sfValidatorError($validator, sprintf('Dependency "%s" is invalid. The format should be <b>plugin-uid</b>/<b>release</b>: [<b>provided-component</b>, ...]', $a . ': ' . $b));
                         }
                     }
                 }
                 $plugin = PluginPeer::retrieveBySlug($pluginName);
                 if (!is_array($b)) {
                     $b = array($b);
                 }
                 foreach ($b as $dep) {
                     if ($plugin) {
                         $c = new Criteria();
                         $c->add(PluginTagPeer::PLUGIN_ID, $plugin->getId());
                         $plugintag = PluginTagPeer::retrieveByName($dep, $c);
                         if ($plugintag) {
                             $plugin_tag_id = $plugintag->getId();
                         } else {
                             $plugin_tag_id = null;
                         }
                     } else {
                         $plugin_tag_id = null;
                     }
                     $this->dependencies[] = array('scope' => $pluginName, 'version' => $version, 'component' => $dep, 'plugin_tag_id' => $plugin_tag_id);
                 }
             }
         }
     }
 }
コード例 #21
0
ファイル: BasePlugin.php プロジェクト: dapepe/tymio
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's BasePeer::TYPE_PHPNAME
  *
  * @param array  $arr     An array to populate the object from.
  * @param string $keyType The type of keys the array uses.
  * @return void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = PluginPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setAccountId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setEntity($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setEvent($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setPriority($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setIdentifier($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setName($arr[$keys[6]]);
     }
     if (array_key_exists($keys[7], $arr)) {
         $this->setCode($arr[$keys[7]]);
     }
     if (array_key_exists($keys[8], $arr)) {
         $this->setActive($arr[$keys[8]]);
     }
     if (array_key_exists($keys[9], $arr)) {
         $this->setInterval($arr[$keys[9]]);
     }
     if (array_key_exists($keys[10], $arr)) {
         $this->setStart($arr[$keys[10]]);
     }
     if (array_key_exists($keys[11], $arr)) {
         $this->setLastExecutionTime($arr[$keys[11]]);
     }
 }
コード例 #22
0
ファイル: BasePluginQuery.php プロジェクト: dapepe/tymio
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return                 Plugin A model object, or null if the key is not found
  * @throws PropelException
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `id`, `account_id`, `entity`, `event`, `priority`, `identifier`, `name`, `code`, `active`, `interval`, `start`, `last_execution_time` FROM `plugin` WHERE `id` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new Plugin();
         $obj->hydrate($row);
         PluginPeer::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }
コード例 #23
0
 public function executeView(sfWebRequest $request)
 {
     $this->author = AuthorPeer::retrieveByUsername($request->getParameter('username'));
     $this->forward404Unless($this->author);
     if ($this->author->getPluginsCount()) {
         $c = new Criteria();
         $c->addDescendingOrderByColumn(PluginPeer::DOWNLOADS_COUNT);
         $c->add(PluginPeer::AUTHOR_ID, $this->author->getId());
         $this->plugins = PluginPeer::doSelect($c);
     }
 }
コード例 #24
0
ファイル: PluginPeer.php プロジェクト: dapepe/tymio
 /**
  * Sets the user that was authenticated by the system.
  *
  * @param User $user
  * @return void
  * @uses $authUser
  */
 public static function setAuthenticatedUser(User $user = null)
 {
     self::$authUser = $user;
 }